-
Notifications
You must be signed in to change notification settings - Fork 236
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
Hoist resource variables using a global initializer function correctly #4894
base: master
Are you sure you want to change the base?
Changes from 4 commits
38c84bb
1764468
ba467a5
0d9d601
b521d9b
bf97d6b
ea5399d
dbc7ae2
dc2b47a
d0b23e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// type-legalize-global-with-init.slang | ||
// | ||
// Confirm that type legalization can handle a global constant | ||
// with a resource type or a type that recursively contains | ||
// resources. | ||
// | ||
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -shaderobj | ||
// | ||
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer | ||
RWStructuredBuffer<uint> outputBuffer; | ||
|
||
//TEST_INPUT:ubuffer(data=[1 2 3 4 5 6 7 8], stride=4):name=inputBuffer | ||
RWStructuredBuffer<uint> inputBuffer; | ||
|
||
static const RWStructuredBuffer<uint> gBuffer = inputBuffer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general I think we will have issues when there are global resource variables that is being written to dynamically, so I am not sure if this is something we want to allow... static const currently is overloaded to also mean compile time constants, maybe we should disallow static consts of resource type as well. Is this test coming from some existing user code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We will have an issue with dynamic resource variable accesses.
From what I understand to add this would just piggy-back on our dynamic dispatch system logic:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No test currently uses |
||
|
||
struct Stuff | ||
{ | ||
__init(RWStructuredBuffer<uint> inA, RWStructuredBuffer<uint> inB) | ||
{ | ||
a = inA; | ||
b = inB; | ||
} | ||
RWStructuredBuffer<uint> a; | ||
RWStructuredBuffer<uint> b; | ||
} | ||
|
||
static const Stuff gStuff = Stuff( inputBuffer, inputBuffer ); | ||
|
||
uint test(uint x) | ||
{ | ||
return gBuffer[x] | ||
+ gStuff.a[x + 1] * 16 | ||
+ gStuff.b[x + 2] * 256; | ||
} | ||
|
||
[numthreads(4, 1, 1)] | ||
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) | ||
{ | ||
let tid = dispatchThreadID.x; | ||
let inVal = tid; | ||
let outVal = test(inVal); | ||
outputBuffer[tid] = outVal; | ||
} | ||
//BUF: 321 | ||
//BUF: 432 | ||
//BUF: 543 | ||
//BUF: 654 |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what this is trying to achieve here, but I think this is likely not the right way.
Usually if you have a global variable and you want to initialize it with some code (e.g. a call), you create a
IRGlobalVar
, which is aIRGlobalValueWithCode
that can have a body just like aIRFunc
. Inside the body you create a basic block with instructions + areturn
instruct that returns the value of the init expr.Here instead of inserting a call into global scope, we should be creating that IRGlobalVar, and rely on follow up passes to insert the logic in the body into entry points.