Skip to content
Open
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
9 changes: 8 additions & 1 deletion tools/clang/lib/SPIRV/DeclResultIdMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,10 @@ DeclResultIdMapper::createFnParam(const ParmVarDecl *param,
(void)getTypeAndCreateCounterForPotentialAliasVar(param, &isAlias);
fnParamInstr->setContainsAliasComponent(isAlias);

if (isConstantTextureBuffer(type))
if (isConstantBuffer(type))
fnParamInstr->setLayoutRule(spirvOptions.cBufferLayoutRule);
if (isTextureBuffer(type))
fnParamInstr->setLayoutRule(spirvOptions.tBufferLayoutRule);

assert(astDecls[param].instr == nullptr);
registerVariableForDecl(param, fnParamInstr);
Expand Down Expand Up @@ -1118,6 +1120,11 @@ DeclResultIdMapper::createFnVar(const VarDecl *var,
spvBuilder.addFnVar(type, loc, name, isPrecise, isNointerp,
init.hasValue() ? init.getValue() : nullptr);

if (isConstantBuffer(type))
varInstr->setLayoutRule(spirvOptions.cBufferLayoutRule);
if (isTextureBuffer(type))
varInstr->setLayoutRule(spirvOptions.tBufferLayoutRule);

bool isAlias = false;
(void)getTypeAndCreateCounterForPotentialAliasVar(var, &isAlias);
varInstr->setContainsAliasComponent(isAlias);
Expand Down
40 changes: 40 additions & 0 deletions tools/clang/test/CodeGenSPIRV/type.constant-buffer.fn-var.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: %dxc -T vs_6_0 -E main -fcgl %s -spirv | FileCheck %s

// CHECK-DAG: OpMemberDecorate %Inner 0 Offset 0

// CHECK-DAG: %Inner = OpTypeStruct %float
// CHECK-DAG: %type_ConstantBuffer_CBS = OpTypeStruct %Inner
// CHECK-DAG: %Inner_0 = OpTypeStruct %float
// CHECK-DAG: %CBS = OpTypeStruct %Inner_0
struct Inner
{
float field;
};

struct CBS
{
Inner entry;
};

ConstantBuffer<CBS> input;

float foo()
{
ConstantBuffer<CBS> local = input;
CBS alias = local;
// CHECK: %local = OpVariable %_ptr_Function_type_ConstantBuffer_CBS Function
// CHECK: [[loadedInput:%[0-9]+]] = OpLoad %type_ConstantBuffer_CBS %input
// CHECK: OpStore %local [[loadedInput]]
// CHECK: [[loadedLocal:%[0-9]+]] = OpLoad %type_ConstantBuffer_CBS %local
// CHECK: [[e1:%[0-9]+]] = OpCompositeExtract %Inner [[loadedLocal]]
// CHECK: [[e2:%[0-9]+]] = OpCompositeExtract %float [[e1]]
// CHECK: [[c2:%[0-9]+]] = OpCompositeConstruct %Inner_0 [[e2]]
// CHECK: [[c1:%[0-9]+]] = OpCompositeConstruct %CBS [[c2]]
// CHECK: OpStore %alias [[c1]]
return alias.entry.field;
}

float main() : A
{
return foo();
}
34 changes: 34 additions & 0 deletions tools/clang/test/CodeGenSPIRV/type.texture-buffer.fn-var.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %dxc -T vs_6_0 -E main -fvk-use-gl-layout -fcgl %s -spirv | FileCheck %s

// CHECK-DAG: OpDecorate %_arr_float_uint_2 ArrayStride 4
// CHECK-DAG: %type_TextureBuffer_CBS = OpTypeStruct %_arr_float_uint_2
// CHECK-DAG: %CBS = OpTypeStruct %_arr_float_uint_2_0

struct CBS
{
float entry[2];
};

TextureBuffer<CBS> input;

float foo()
{
TextureBuffer<CBS> local = input;
CBS alias = local;
// CHECK: %local = OpVariable %_ptr_Function_type_TextureBuffer_CBS Function
// CHECK: [[loadedInput:%[0-9]+]] = OpLoad %type_TextureBuffer_CBS %input
// CHECK: OpStore %local [[loadedInput]]
// CHECK: [[loadedLocal:%[0-9]+]] = OpLoad %type_TextureBuffer_CBS %local
// CHECK: [[e1:%[0-9]+]] = OpCompositeExtract %_arr_float_uint_2 [[loadedLocal]]
// CHECK: [[e2:%[0-9]+]] = OpCompositeExtract %float [[e1]] 0
// CHECK: [[e3:%[0-9]+]] = OpCompositeExtract %float [[e1]] 1
// CHECK: [[c1:%[0-9]+]] = OpCompositeConstruct %_arr_float_uint_2_0 [[e2]] [[e3]]
// CHECK: [[c2:%[0-9]+]] = OpCompositeConstruct %CBS [[c1]]
// CHECK: OpStore %alias [[c2]]
return alias.entry[1];
}

float main() : A
{
return foo();
}
31 changes: 13 additions & 18 deletions tools/clang/test/CodeGenSPIRV/type.texture-buffer.pass.hlsl
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
// RUN: %dxc -T vs_6_0 -E main -fcgl %s -spirv | FileCheck %s
// RUN: %dxc -T vs_6_0 -E main -fvk-use-gl-layout -fcgl %s -spirv | FileCheck %s

// CHECK-DAG: OpMemberDecorate %Inner 0 Offset 0

// CHECK-DAG: %Inner = OpTypeStruct %float
// CHECK-DAG: %type_TextureBuffer_CBS = OpTypeStruct %Inner
// CHECK-DAG: %Inner_0 = OpTypeStruct %float
// CHECK-DAG: %CBS = OpTypeStruct %Inner_0
struct Inner
{
float field;
};
// CHECK-DAG: OpDecorate %_arr_float_uint_2 ArrayStride 4
// CHECK-DAG: %type_TextureBuffer_CBS = OpTypeStruct %_arr_float_uint_2
// CHECK-DAG: %CBS = OpTypeStruct %_arr_float_uint_2_0

struct CBS
{
Inner entry;
float entry[2];
};

float foo(TextureBuffer<CBS> param)
{
CBS alias = param;
// CHECK: %param = OpFunctionParameter %_ptr_Function_type_TextureBuffer_CBS
// CHECK: [[copy:%[0-9]+]] = OpLoad %type_TextureBuffer_CBS %param
// CHECK: [[e1:%[0-9]+]] = OpCompositeExtract %Inner [[copy]]
// CHECK: [[e2:%[0-9]+]] = OpCompositeExtract %float [[e1]]
// CHECK: [[c2:%[0-9]+]] = OpCompositeConstruct %Inner_0 [[e2]]
// CHECK: [[c1:%[0-9]+]] = OpCompositeConstruct %CBS [[c2]]
// CHECK: OpStore %alias [[c1]]
return alias.entry.field;
// CHECK: [[e1:%[0-9]+]] = OpCompositeExtract %_arr_float_uint_2 [[copy]]
// CHECK: [[e2:%[0-9]+]] = OpCompositeExtract %float [[e1]] 0
// CHECK: [[e3:%[0-9]+]] = OpCompositeExtract %float [[e1]] 1
// CHECK: [[c1:%[0-9]+]] = OpCompositeConstruct %_arr_float_uint_2_0 [[e2]] [[e3]]
// CHECK: [[c2:%[0-9]+]] = OpCompositeConstruct %CBS [[c1]]
// CHECK: OpStore %alias [[c2]]
return alias.entry[1];
}

TextureBuffer<CBS> input;
Expand Down
Loading