blob: 182e7bdf0901c0649bf3dbb0eb54c9de6ee631c8 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// 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 Capens68a82382018-10-02 13:16:55 -040017#include "SamplerCore.hpp"
Nicolas Capens1d8c8db2018-11-05 16:30:42 -050018#include "Device/Renderer.hpp"
19#include "Device/Vertex.hpp"
20#include "System/Half.hpp"
Chris Forbesebe5f7f2019-01-16 10:38:34 -080021#include "Vulkan/VkDebug.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040022
23namespace sw
24{
Ben Clayton76e9bc02019-02-26 15:02:18 +000025 VertexProgram::VertexProgram(
26 const VertexProcessor::State &state,
27 vk::PipelineLayout const *pipelineLayout,
28 SpirvShader const *spirvShader)
29 : VertexRoutine(state, pipelineLayout, spirvShader)
Nicolas Capens68a82382018-10-02 13:16:55 -040030 {
31 ifDepth = 0;
32 loopRepDepth = 0;
33 currentLabel = -1;
34 whileTest = false;
35
Nicolas Capens68a82382018-10-02 13:16:55 -040036 enableStack[0] = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
37
Chris Forbes26f1a862019-02-02 15:23:01 -080038 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 Forbese7b80202019-02-12 20:38:26 +000043 routine.getValue(it->second.Id)[it->second.FirstComponent] =
Chris Forbes26f1a862019-02-02 15:23:01 -080044 As<Float4>(Int4((*Pointer<Int>(data + OFFSET(DrawData, instanceID)))));
45 }
Nicolas Capens68a82382018-10-02 13:16:55 -040046 }
47
48 VertexProgram::~VertexProgram()
49 {
50 }
51
Nicolas Capens68a82382018-10-02 13:16:55 -040052 void VertexProgram::program(UInt &index)
53 {
Nicolas Capensdc2966a2018-10-31 11:25:15 -040054 // shader->print("VertexShader-%0.8X.txt", state.shaderID);
Nicolas Capens68a82382018-10-02 13:16:55 -040055
Nicolas Capens68a82382018-10-02 13:16:55 -040056 enableIndex = 0;
Nicolas Capens68a82382018-10-02 13:16:55 -040057
Chris Forbesd0077202019-02-10 19:52:08 +000058 auto it = spirvShader->inputBuiltins.find(spv::BuiltInVertexIndex);
59 if (it != spirvShader->inputBuiltins.end())
60 {
61 assert(it->second.SizeInComponents == 1);
Chris Forbese7b80202019-02-12 20:38:26 +000062 routine.getValue(it->second.Id)[it->second.FirstComponent] =
Chris Forbesd0077202019-02-10 19:52:08 +000063 As<Float4>(Int4(index) + Int4(0, 1, 2, 3));
64 }
Nicolas Capens68a82382018-10-02 13:16:55 -040065
Chris Forbesd5aed492019-02-02 15:18:52 -080066 spirvShader->emit(&routine);
Nicolas Capens68a82382018-10-02 13:16:55 -040067
68 if(currentLabel != -1)
69 {
70 Nucleus::setInsertBlock(returnBlock);
71 }
Chris Forbesc61271e2019-02-19 17:01:28 -080072
73 spirvShader->emitEpilog(&routine);
Nicolas Capens68a82382018-10-02 13:16:55 -040074 }
75
Nicolas Capens68a82382018-10-02 13:16:55 -040076 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 Forbes1845d5e2018-12-27 11:50:15 -080093 Int4 VertexProgram::enableMask()
Nicolas Capens68a82382018-10-02 13:16:55 -040094 {
Chris Forbes1845d5e2018-12-27 11:50:15 -080095 Int4 enable = true ? Int4(enableStack[enableIndex]) : Int4(0xFFFFFFFF);
Nicolas Capens68a82382018-10-02 13:16:55 -040096 return enable;
97 }
98
Nicolas Capens68a82382018-10-02 13:16:55 -040099}