Repository navigation
[SPIR-V] Replace pixel shader SV_CullPrimitive inputs with 0 #9088
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
Open
Abir Deol (apollo-2006)
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
apollo-2006:spirv-cullprimitive-psin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f291f11
[SPIR-V] Replace pixel shader SV_CullPrimitive inputs with 0
apollo-2006 0d8977c
[SPIR-V] Test the value and layout of replaced SV_CullPrimitive inputs
apollo-2006 7681dc4
[SPIR-V] Drop the unneeded target env from the PS test runs
apollo-2006 9382ff8
[SPIR-V] Keep vk::builtin on pixel shader SV_CullPrimitive inputs
apollo-2006 dcff044
Merge remote-tracking branch 'origin/main' into spirv-cullprimitive-psin
apollo-2006 779d588
Merge remote-tracking branch 'origin/main' into spirv-cullprimitive-psin
apollo-2006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
tools/clang/test/CodeGenSPIRV/meshshading.ext.cullprimitive.ps.hlsl
This file contains hidden or 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,42 @@ | ||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -DCULL_TYPE=bool | FileCheck %s | ||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -DCULL_TYPE=uint | FileCheck %s | ||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -DCULL_TYPE=bool2 | FileCheck %s | ||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -DCULL_ARRAY | FileCheck %s | ||
|
|
||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -fcgl -DCULL_TYPE=bool | FileCheck %s --check-prefix=BOOL | ||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -fcgl -DCULL_TYPE=uint | FileCheck %s --check-prefix=UINT | ||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -fcgl -DCULL_TYPE=bool2 | FileCheck %s --check-prefix=BOOL2 | ||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -fcgl -DCULL_ARRAY | FileCheck %s --check-prefix=ARRAY | ||
| // RUN: %dxc -T ps_6_5 -E main %s -spirv -fcgl -DCULL_BUILTIN | FileCheck %s --check-prefix=BUILTIN | ||
|
|
||
| // SV_CullPrimitive as a pixel shader input is replaced with 0, like DXIL. | ||
|
apollo-2006 marked this conversation as resolved.
Resolved
|
||
| // DXIL doesn't check the type here, so aggregates are replaced too. | ||
|
|
||
| // CHECK-NOT: CullPrimitiveEXT | ||
| // CHECK: OpEntryPoint Fragment %main "main" %out_var_SV_Target | ||
| // CHECK-NOT: CullPrimitiveEXT | ||
|
|
||
| // BOOL: [[null:%[0-9]+]] = OpConstantNull %bool | ||
| // BOOL: OpStore %param_var_cull [[null]] | ||
|
|
||
| // UINT: [[null:%[0-9]+]] = OpConstantNull %uint | ||
| // UINT: OpStore %param_var_cull [[null]] | ||
|
|
||
| // BOOL2: [[null:%[0-9]+]] = OpConstantNull %v2bool | ||
| // BOOL2: OpStore %param_var_cull [[null]] | ||
|
|
||
| // ARRAY: [[null:%[0-9]+]] = OpConstantNull %_arr_bool_uint_2 | ||
| // ARRAY: OpStore %param_var_cull [[null]] | ||
|
|
||
| // An explicit vk::builtin is not replaced. | ||
| // BUILTIN-NOT: OpConstantNull | ||
| // BUILTIN: OpLoad %bool %HelperInvocation | ||
|
|
||
| #ifdef CULL_ARRAY | ||
| float4 main(bool cull[2] : SV_CullPrimitive) : SV_Target { return cull[1]; } | ||
| #elif defined(CULL_BUILTIN) | ||
| float4 main([[vk::builtin("HelperInvocation")]] bool cull : SV_CullPrimitive) | ||
| : SV_Target { return cull; } | ||
| #else | ||
| float4 main(CULL_TYPE cull : SV_CullPrimitive) : SV_Target { return cull.x; } | ||
| #endif | ||
64 changes: 64 additions & 0 deletions
64
tools/clang/test/CodeGenSPIRV/meshshading.ext.cullprimitive.ps.shared-struct.hlsl
This file contains hidden or 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,64 @@ | ||
| // RUN: %dxc -T ms_6_5 -E ms_main %s -spirv -fspv-target-env=vulkan1.3 -DCULL_FIRST | FileCheck %s --check-prefix=MS | ||
| // RUN: %dxc -T ms_6_5 -E ms_main %s -spirv -fspv-target-env=vulkan1.3 | FileCheck %s --check-prefix=MS | ||
| // RUN: %dxc -T ps_6_5 -E ps_main %s -spirv -DCULL_FIRST | FileCheck %s --check-prefix=PS | ||
| // RUN: %dxc -T ps_6_5 -E ps_main %s -spirv | FileCheck %s --check-prefix=PS | ||
| // RUN: %dxc -T ps_6_5 -E ps_main %s -spirv -fcgl -DCULL_FIRST | FileCheck %s --check-prefix=FIRST | ||
| // RUN: %dxc -T ps_6_5 -E ps_main %s -spirv -fcgl | FileCheck %s --check-prefix=LATER | ||
|
|
||
| // The other members keep the mesh shader's locations, and the 0 lands in the | ||
| // right member, whether SV_CullPrimitive is first or not. | ||
|
|
||
| // MS: OpDecorate {{%[0-9]+}} BuiltIn CullPrimitiveEXT | ||
| // MS-DAG: OpDecorate %out_var_PRIMID Location 0 | ||
| // MS-DAG: OpDecorate %out_var_COLOR0 Location 1 | ||
|
|
||
| // PS-NOT: CullPrimitiveEXT | ||
| // PS-DAG: OpDecorate %in_var_PRIMID Location 0 | ||
| // PS-DAG: OpDecorate %in_var_COLOR0 Location 1 | ||
| // PS-NOT: CullPrimitiveEXT | ||
|
|
||
| // FIRST: [[null:%[0-9]+]] = OpConstantNull %bool | ||
| // FIRST: [[id:%[0-9]+]] = OpLoad %uint %in_var_PRIMID | ||
| // FIRST: [[col:%[0-9]+]] = OpLoad %v4float %in_var_COLOR0 | ||
| // FIRST: OpCompositeConstruct %Prim [[null]] [[id]] [[col]] | ||
|
|
||
| // LATER: [[null:%[0-9]+]] = OpConstantNull %bool | ||
| // LATER: [[id:%[0-9]+]] = OpLoad %uint %in_var_PRIMID | ||
| // LATER: [[col:%[0-9]+]] = OpLoad %v4float %in_var_COLOR0 | ||
| // LATER: OpCompositeConstruct %Prim [[id]] [[null]] [[col]] | ||
|
|
||
| #ifdef CULL_FIRST | ||
| struct Prim { | ||
| bool cull : SV_CullPrimitive; | ||
| uint id : PRIMID; | ||
| float4 col : COLOR0; | ||
| }; | ||
| #else | ||
| struct Prim { | ||
| uint id : PRIMID; | ||
| bool cull : SV_CullPrimitive; | ||
| float4 col : COLOR0; | ||
| }; | ||
| #endif | ||
|
|
||
| struct Vert { | ||
| float4 pos : SV_Position; | ||
| }; | ||
|
|
||
| [outputtopology("triangle")] | ||
| [numthreads(1, 1, 1)] | ||
| void ms_main(out vertices Vert verts[3], out indices uint3 tris[1], | ||
| out primitives Prim prims[1]) { | ||
| SetMeshOutputCounts(3, 1); | ||
| verts[0].pos = 0; | ||
| verts[1].pos = 0; | ||
| verts[2].pos = 0; | ||
| tris[0] = uint3(0, 1, 2); | ||
| prims[0].cull = false; | ||
| prims[0].id = 7; | ||
| prims[0].col = 1; | ||
| } | ||
|
|
||
| float4 ps_main(Vert v, Prim p) : SV_Target { | ||
| return p.cull ? 0 : p.col * p.id; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.