mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 17:44:09 +01:00
[SPIR-V out] Correctly lower instance_index in raytracing shaders (#10154)
This commit is contained in:
1 parent
52889ac2c4
commit
e9a873e5d2
6 files changed
+25
-11
No files matched your search
@@ -141,6 +141,7 @@ By @sagudev in [#10115](https://github.com/gfx-rs/wgpu/pull/10115).
|
||||
|
||||
- Fix panics when shader `var<immediate>` size is larger than 256 bytes. By @beicause in [#9725](https://github.com/gfx-rs/wgpu/pull/9725).
|
||||
- Fix a panic in the SPIR-V frontend when a subgroup collective operation (e.g. `OpGroupNonUniformUMin`) or `OpGroupNonUniformBallot` used an argument whose value needed to be spilled to a temporary variable, such as when the argument was computed inside a loop. By @nazar-pc in [#9957](https://github.com/gfx-rs/wgpu/issues/9957).
|
||||
- Lower `@builtin(instance_index)` in `@any_hit` and `@closest_hit` entry points to SPIR-V's `InstanceId` rather than `InstanceIndex`, which Vulkan only permits in the vertex stage. By @JMS55 in [10154](https://github.com/gfx-rs/wgpu/pull/10154).
|
||||
|
||||
#### Validation
|
||||
|
||||
|
||||
@@ -3210,7 +3210,12 @@ impl Writer {
|
||||
)?;
|
||||
BuiltIn::CullDistance
|
||||
}
|
||||
Bi::InstanceIndex => BuiltIn::InstanceIndex,
|
||||
Bi::InstanceIndex => match stage {
|
||||
crate::ShaderStage::AnyHit | crate::ShaderStage::ClosestHit => {
|
||||
BuiltIn::InstanceId
|
||||
}
|
||||
_ => BuiltIn::InstanceIndex,
|
||||
},
|
||||
Bi::PointSize => BuiltIn::PointSize,
|
||||
Bi::VertexIndex => BuiltIn::VertexIndex,
|
||||
Bi::DrawIndex => {
|
||||
|
||||
@@ -38,6 +38,7 @@ fn closest_hit_main(@builtin(object_ray_origin) origin: vec3<f32>, @builtin(obje
|
||||
|
||||
@closest_hit
|
||||
@incoming_payload(incoming_hit_num)
|
||||
fn closest_hit_triangle(@builtin(primitive_index) primitive_index: u32) {
|
||||
fn closest_hit_triangle(@builtin(instance_index) instance_index: u32, @builtin(primitive_index) primitive_index: u32) {
|
||||
incoming_hit_num.hit_num = primitive_index;
|
||||
incoming_hit_num.hit_num = instance_index;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
; SPIR-V
|
||||
; Version: 1.4
|
||||
; Generator: rspirv
|
||||
; Bound: 176
|
||||
; Bound: 179
|
||||
OpCapability Shader
|
||||
OpCapability RayTracingKHR
|
||||
OpExtension "SPV_KHR_ray_tracing"
|
||||
@@ -11,7 +11,7 @@ OpEntryPoint RayGenerationKHR %23 "ray_gen_main" %18 %21 %11 %13
|
||||
OpEntryPoint MissKHR %138 "miss" %130 %133 %135
|
||||
OpEntryPoint AnyHitKHR %150 "any_hit_main" %141 %144 %146 %148 %15
|
||||
OpEntryPoint ClosestHitKHR %168 "closest_hit_main" %159 %161 %163 %166
|
||||
OpEntryPoint ClosestHitKHR %173 "closest_hit_triangle" %171 %15
|
||||
OpEntryPoint ClosestHitKHR %175 "closest_hit_triangle" %171 %173 %15
|
||||
OpMemberDecorate %4 0 Offset 0
|
||||
OpMemberDecorate %4 1 Offset 4
|
||||
OpMemberDecorate %9 0 Offset 0
|
||||
@@ -35,7 +35,8 @@ OpDecorate %159 BuiltIn ObjectRayOriginKHR
|
||||
OpDecorate %161 BuiltIn ObjectRayDirectionKHR
|
||||
OpDecorate %163 BuiltIn ObjectToWorldKHR
|
||||
OpDecorate %166 BuiltIn WorldToObjectKHR
|
||||
OpDecorate %171 BuiltIn PrimitiveId
|
||||
OpDecorate %171 BuiltIn InstanceId
|
||||
OpDecorate %173 BuiltIn PrimitiveId
|
||||
%2 = OpTypeVoid
|
||||
%3 = OpTypeInt 32 0
|
||||
%4 = OpTypeStruct %3 %3
|
||||
@@ -94,6 +95,7 @@ OpDecorate %171 BuiltIn PrimitiveId
|
||||
%163 = OpVariable %164 Input
|
||||
%166 = OpVariable %164 Input
|
||||
%171 = OpVariable %142 Input
|
||||
%173 = OpVariable %142 Input
|
||||
%49 = OpFunction %2 None %48
|
||||
%50 = OpFunctionParameter %5
|
||||
%51 = OpFunctionParameter %9
|
||||
@@ -227,12 +229,15 @@ OpBranch %169
|
||||
%169 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%173 = OpFunction %2 None %24
|
||||
%175 = OpFunction %2 None %24
|
||||
%170 = OpLabel
|
||||
%172 = OpLoad %3 %171
|
||||
OpBranch %174
|
||||
%174 = OpLabel
|
||||
%175 = OpAccessChain %152 %15 %31
|
||||
OpStore %175 %172
|
||||
%174 = OpLoad %3 %173
|
||||
OpBranch %176
|
||||
%176 = OpLabel
|
||||
%177 = OpAccessChain %152 %15 %31
|
||||
OpStore %177 %174
|
||||
%178 = OpAccessChain %152 %15 %31
|
||||
OpStore %178 %172
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -161,5 +161,6 @@ layout(location = 0) rayPayloadInEXT _4 _15;
|
||||
void main()
|
||||
{
|
||||
_15._m0 = uint(gl_PrimitiveID);
|
||||
_15._m0 = uint(gl_InstanceID);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ fn closest_hit_main(@builtin(object_ray_origin) origin_1: vec3<f32>, @builtin(ob
|
||||
}
|
||||
|
||||
@closest_hit @incoming_payload(incoming_hit_num)
|
||||
fn closest_hit_triangle(@builtin(primitive_index) primitive_index: u32) {
|
||||
fn closest_hit_triangle(@builtin(instance_index) instance_index: u32, @builtin(primitive_index) primitive_index: u32) {
|
||||
incoming_hit_num.hit_num = primitive_index;
|
||||
incoming_hit_num.hit_num = instance_index;
|
||||
return;
|
||||
}
|
||||
Reference in new issue
Block a user