Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "VertexProgram.hpp" |
| 16 | |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 17 | #include "SamplerCore.hpp" |
Nicolas Capens | 1d8c8db | 2018-11-05 16:30:42 -0500 | [diff] [blame] | 18 | #include "Device/Renderer.hpp" |
| 19 | #include "Device/Vertex.hpp" |
| 20 | #include "System/Half.hpp" |
Chris Forbes | ebe5f7f | 2019-01-16 10:38:34 -0800 | [diff] [blame] | 21 | #include "Vulkan/VkDebug.hpp" |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 22 | |
| 23 | namespace sw |
| 24 | { |
Ben Clayton | 76e9bc0 | 2019-02-26 15:02:18 +0000 | [diff] [blame] | 25 | VertexProgram::VertexProgram( |
| 26 | const VertexProcessor::State &state, |
| 27 | vk::PipelineLayout const *pipelineLayout, |
| 28 | SpirvShader const *spirvShader) |
| 29 | : VertexRoutine(state, pipelineLayout, spirvShader) |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 30 | { |
| 31 | ifDepth = 0; |
| 32 | loopRepDepth = 0; |
| 33 | currentLabel = -1; |
| 34 | whileTest = false; |
| 35 | |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 36 | enableStack[0] = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 37 | |
Chris Forbes | 26f1a86 | 2019-02-02 15:23:01 -0800 | [diff] [blame] | 38 | auto it = spirvShader->inputBuiltins.find(spv::BuiltInInstanceIndex); |
| 39 | if (it != spirvShader->inputBuiltins.end()) |
| 40 | { |
| 41 | // TODO: we could do better here; we know InstanceIndex is uniform across all lanes |
| 42 | assert(it->second.SizeInComponents == 1); |
Chris Forbes | e7b8020 | 2019-02-12 20:38:26 +0000 | [diff] [blame] | 43 | routine.getValue(it->second.Id)[it->second.FirstComponent] = |
Chris Forbes | 26f1a86 | 2019-02-02 15:23:01 -0800 | [diff] [blame] | 44 | As<Float4>(Int4((*Pointer<Int>(data + OFFSET(DrawData, instanceID))))); |
| 45 | } |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | VertexProgram::~VertexProgram() |
| 49 | { |
| 50 | } |
| 51 | |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 52 | void VertexProgram::program(UInt &index) |
| 53 | { |
Nicolas Capens | dc2966a | 2018-10-31 11:25:15 -0400 | [diff] [blame] | 54 | // shader->print("VertexShader-%0.8X.txt", state.shaderID); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 55 | |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 56 | enableIndex = 0; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 57 | |
Chris Forbes | d007720 | 2019-02-10 19:52:08 +0000 | [diff] [blame] | 58 | auto it = spirvShader->inputBuiltins.find(spv::BuiltInVertexIndex); |
| 59 | if (it != spirvShader->inputBuiltins.end()) |
| 60 | { |
| 61 | assert(it->second.SizeInComponents == 1); |
Chris Forbes | e7b8020 | 2019-02-12 20:38:26 +0000 | [diff] [blame] | 62 | routine.getValue(it->second.Id)[it->second.FirstComponent] = |
Chris Forbes | d007720 | 2019-02-10 19:52:08 +0000 | [diff] [blame] | 63 | As<Float4>(Int4(index) + Int4(0, 1, 2, 3)); |
| 64 | } |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 65 | |
Chris Forbes | d5aed49 | 2019-02-02 15:18:52 -0800 | [diff] [blame] | 66 | spirvShader->emit(&routine); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 67 | |
| 68 | if(currentLabel != -1) |
| 69 | { |
| 70 | Nucleus::setInsertBlock(returnBlock); |
| 71 | } |
Chris Forbes | c61271e | 2019-02-19 17:01:28 -0800 | [diff] [blame] | 72 | |
| 73 | spirvShader->emitEpilog(&routine); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 76 | RValue<Pointer<Byte>> VertexProgram::uniformAddress(int bufferIndex, unsigned int index) |
| 77 | { |
| 78 | if(bufferIndex == -1) |
| 79 | { |
| 80 | return data + OFFSET(DrawData, vs.c[index]); |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | return *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, vs.u[bufferIndex])) + index; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | RValue<Pointer<Byte>> VertexProgram::uniformAddress(int bufferIndex, unsigned int index, Int &offset) |
| 89 | { |
| 90 | return uniformAddress(bufferIndex, index) + offset * sizeof(float4); |
| 91 | } |
| 92 | |
Chris Forbes | 1845d5e | 2018-12-27 11:50:15 -0800 | [diff] [blame] | 93 | Int4 VertexProgram::enableMask() |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 94 | { |
Chris Forbes | 1845d5e | 2018-12-27 11:50:15 -0800 | [diff] [blame] | 95 | Int4 enable = true ? Int4(enableStack[enableIndex]) : Int4(0xFFFFFFFF); |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 96 | return enable; |
| 97 | } |
| 98 | |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 99 | } |