-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a flag to control type splitting
The `-split-mixed-types` flag can be provided to command-line `slangc`, and the `SLANG_COMPILE_FLAG_SPLIT_MIXED_TYPE` flag can be passed to `spSetCompileFlags`. Either of these turns on a mode where Slang will split types that included both resource and non-resource fields. The declaration of such a type will just drop the resource fields, while a variable declare using such a type turns into multiple declararations: one for the non-resource fields, and then one for each resource field (recursively). This behavior was already implemented for GLSL support, and this change just adds a flag so that the user can turn it on unconditionally. Caveats: - This does not apply in "full rewriter" mode, which is what happens if the user doesn't use any `import`s. I could try to fix that, but it seems like in that mode people are asking to bypass as much of the compiler as possible. - When it *does* apply, it applies to user code as well as library/Slang code. So this will potentially rewrite the user's own HLSL in ways they wouldn't expect. I don't see a great way around it, though.
- Loading branch information
1 parent
3dd88c2
commit d13bd05
Showing
5 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//TEST:COMPARE_HLSL: -split-mixed-types -no-checking -target dxbc-assembly -profile ps_4_0 -entry main | ||
|
||
// Confirm that the `-split-mixed-types` flag works. | ||
|
||
#ifdef __SLANG__ | ||
|
||
// HLSL input: | ||
// | ||
// - Uses at least one `import` of Slang code | ||
// - Uses an aggregate type that mixes resource and non-resource types | ||
// | ||
|
||
__import type_splitting; | ||
|
||
struct Foo | ||
{ | ||
Texture2D t; | ||
SamplerState s; | ||
float2 u; | ||
}; | ||
|
||
cbuffer C | ||
{ | ||
Foo foo; | ||
} | ||
|
||
float4 main() : SV_Target | ||
{ | ||
return foo.t.Sample(foo.s, foo.u); | ||
} | ||
|
||
#else | ||
|
||
// Equivalent raw HLSL: | ||
// | ||
// - Fields of resource type have been stripped from original type definition | ||
// - Fields of resource type get hoisted out of variable declarations | ||
// | ||
|
||
struct Foo | ||
{ | ||
float2 u; | ||
}; | ||
|
||
cbuffer C | ||
{ | ||
Foo foo; | ||
} | ||
|
||
Texture2D SLANG_parameterBlock_C_foo_t; | ||
SamplerState SLANG_parameterBlock_C_foo_s; | ||
|
||
float4 main() : SV_Target | ||
{ | ||
return SLANG_parameterBlock_C_foo_t.Sample(SLANG_parameterBlock_C_foo_s, foo.u); | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//TEST_IGNORE_FILE: | ||
|
||
// This file only exists so that `type-splitting.hlsl` officially appears to be using some Slang code. |