Skip to content

Commit 563fc0c

Browse files
author
Tim Foley
authored
Fix up parameter block emit for mixed rewriter+IR (shader-slang#316)
* Fix up parameter block emit for mixed rewriter+IR The basic problem here arose when a parameter block was declared in code that will be lowered via IR, but is referenced from user code that will use the AST-based lowering pass. The type legalization would split up the parameter block, and the AST would refer to the new variables, but it would fail to recognize when those variables represent constant buffers, and thus should get implicit-dereference behavior. The fix here was just to propagate type information through when creating new AST (pseudo-)expressions to represent IR declarations that were split. A more complete fix down the road should try to make sure that both the expression emit logic and the declaration-emit logic agree on whether a particular declaration of a parameter block or constant buffer needs to support the "implicit dereference" case or not. I'm leaving that to future work. With this change, two test cases that had been disabled now pass. * Fixup: don't do implicit deref for `ParameterBlock` values Right now the rules for `ParameterBlock` and all other uniform praameter groups needs to be different, but the `isImplicitBaseExpr` logic wasn't taking that into account.
1 parent acf2625 commit 563fc0c

6 files changed

+21
-5
lines changed

source/slang/ast-legalize.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,10 @@ struct LoweringVisitor
26832683
String mangledName = globalVar->mangledName;
26842684
SLANG_ASSERT(mangledName.Length() != 0);
26852685

2686-
return LegalExpr(createUncheckedVarRef(mangledName));
2686+
RefPtr<Expr> varRef = createUncheckedVarRef(mangledName);
2687+
varRef->type.type = globalVar->getType()->getValueType();
2688+
2689+
return LegalExpr(varRef);
26872690
}
26882691
break;
26892692

source/slang/emit.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,13 @@ struct EmitVisitor
14101410
return true;
14111411
}
14121412

1413-
// Is the expression referencing a constant buffer?
1414-
if (auto cbufferType = e->type->As<ConstantBufferType>())
1413+
// Is the expression referencing a uniform parameter group,
1414+
// but *not* a `ParameterBlock<T>`?
1415+
if (auto parameterBlockType = e->type->As<ParameterBlockType>())
1416+
{
1417+
return false;
1418+
}
1419+
if (auto uniformParameterGroupType = e->type->As<UniformParameterGroupType>())
14151420
{
14161421
return true;
14171422
}

tests/compute/rewriter-parameter-block-complex.hlsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//TEST(compute):HLSL_COMPUTE:-xslang -no-checking
22
//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir
3-
//DISABLED_TEST(compute):HLSL_COMPUTE:-xslang -no-checking -xslang -use-ir
3+
//TEST(compute):HLSL_COMPUTE:-xslang -no-checking -xslang -use-ir
44

55
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1110
2+
1121
3+
1132
4+
1143

tests/compute/rewriter-parameter-block.hlsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//TEST(compute):HLSL_COMPUTE:-xslang -no-checking
22
//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir
3-
//DISABLED_TEST(compute):HLSL_COMPUTE:-xslang -no-checking -xslang -use-ir
3+
//TEST(compute):HLSL_COMPUTE:-xslang -no-checking -xslang -use-ir
44

55
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
11110
2+
11121
3+
11132
4+
11143

0 commit comments

Comments
 (0)