Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow unsigned int for nonzero base instance #6120

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions tools/clang/lib/SPIRV/DeclResultIdMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3218,11 +3218,10 @@ 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) {
assert(type->isSpecificBuiltinType(BuiltinType::Kind::Int) ||
type->isSpecificBuiltinType(BuiltinType::Kind::UInt));
auto *baseInstanceVar = spvBuilder.addStageBuiltinVar(
type, spv::StorageClass::Input, spv::BuiltIn::BaseInstance, false,
semantic->loc);
Expand Down Expand Up @@ -3319,8 +3318,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);
Expand Down
5 changes: 4 additions & 1 deletion tools/clang/lib/SPIRV/DeclResultIdMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,11 @@ class DeclResultIdMapper {
//
// sigPoint: the signature point identifying which shader stage the variable
// will be used in.
//
// type: The type to use for the new variable. Must be int or unsigned int.
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`.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}