diff --git a/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp b/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp index 26a9d04aec..5a3adc28ac 100644 --- a/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp +++ b/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp @@ -3218,11 +3218,8 @@ SpirvVariable *DeclResultIdMapper::getInstanceIdFromIndexAndBase( return instanceIdVar; } -SpirvVariable * -DeclResultIdMapper::getBaseInstanceVariable(SemanticInfo *semantic, - const hlsl::SigPoint *sigPoint) { - - QualType type = astContext.IntTy; +SpirvVariable *DeclResultIdMapper::getBaseInstanceVariable( + SemanticInfo *semantic, const hlsl::SigPoint *sigPoint, QualType type) { auto *baseInstanceVar = spvBuilder.addStageBuiltinVar( type, spv::StorageClass::Input, spv::BuiltIn::BaseInstance, false, semantic->loc); @@ -3319,8 +3316,8 @@ SpirvVariable *DeclResultIdMapper::createSpirvInterfaceVariable( // The above call to createSpirvStageVar creates the gl_InstanceIndex. // We should now manually create the gl_BaseInstance variable and do the // subtraction. - auto *baseInstanceVar = - getBaseInstanceVariable(stageVarData.semantic, stageVarData.sigPoint); + auto *baseInstanceVar = getBaseInstanceVariable( + stageVarData.semantic, stageVarData.sigPoint, stageVarData.type); // SPIR-V code for 'SV_InstanceID = gl_InstanceIndex - gl_BaseInstance' varInstr = getInstanceIdFromIndexAndBase(varInstr, baseInstanceVar); diff --git a/tools/clang/lib/SPIRV/DeclResultIdMapper.h b/tools/clang/lib/SPIRV/DeclResultIdMapper.h index 64b941745a..d5b1259beb 100644 --- a/tools/clang/lib/SPIRV/DeclResultIdMapper.h +++ b/tools/clang/lib/SPIRV/DeclResultIdMapper.h @@ -762,7 +762,8 @@ class DeclResultIdMapper { // sigPoint: the signature point identifying which shader stage the variable // will be used in. SpirvVariable *getBaseInstanceVariable(SemanticInfo *semantic, - const hlsl::SigPoint *sigPoint); + const hlsl::SigPoint *sigPoint, + QualType type); // Creates and return a new interface variable from the information provided. // The new variable with be add to `this->StageVars`. diff --git a/tools/clang/test/CodeGenSPIRV/semantic.unsigned-nonzero-base-instance.vs.hlsl b/tools/clang/test/CodeGenSPIRV/semantic.unsigned-nonzero-base-instance.vs.hlsl new file mode 100644 index 0000000000..70b2b56b13 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/semantic.unsigned-nonzero-base-instance.vs.hlsl @@ -0,0 +1,29 @@ +// RUN: %dxc -T vs_6_0 -E main -fvk-support-nonzero-base-instance -fcgl %s -spirv | FileCheck %s + +// CHECK: OpEntryPoint Vertex %main "main" +// CHECK-SAME: %gl_InstanceIndex +// CHECK-SAME: %gl_BaseInstance +// CHECK-SAME: %out_var_SV_InstanceID + +// CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex +// CHECK: OpDecorate %gl_BaseInstance BuiltIn BaseInstance +// CHECK: OpDecorate %out_var_SV_InstanceID Location 0 + +// CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input +// CHECK: %gl_BaseInstance = OpVariable %_ptr_Input_uint Input +// CHECK: %out_var_SV_InstanceID = OpVariable %_ptr_Output_uint Output + +// CHECK: %main = OpFunction +// CHECK: %SV_InstanceID = OpVariable %_ptr_Function_uint Function +// CHECK: [[gl_InstanceIndex:%[0-9]+]] = OpLoad %uint %gl_InstanceIndex +// CHECK: [[gl_BaseInstance:%[0-9]+]] = OpLoad %uint %gl_BaseInstance +// CHECK: [[instance_id:%[0-9]+]] = OpISub %uint [[gl_InstanceIndex]] [[gl_BaseInstance]] +// CHECK: OpStore %SV_InstanceID [[instance_id]] +// CHECK: [[instance_id_0:%[0-9]+]] = OpLoad %uint %SV_InstanceID +// CHECK: OpStore %param_var_input [[instance_id_0]] +// CHECK: {{%[0-9]+}} = OpFunctionCall %uint %src_main %param_var_input + +unsigned int main(unsigned int input: SV_InstanceID) : SV_InstanceID { + return input; +} +