Skip to content
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

Naga generates invalid SPIR-V in a shader with a unused acceleration structure #5446

Closed
Vecvec opened this issue Mar 27, 2024 · 3 comments · Fixed by #5463
Closed

Naga generates invalid SPIR-V in a shader with a unused acceleration structure #5446

Vecvec opened this issue Mar 27, 2024 · 3 comments · Fixed by #5463
Labels
area: naga back-end Outputs of naga shader conversion lang: SPIR-V Vulkan's Shading Language naga Shader Translator type: bug Something isn't working

Comments

@Vecvec
Copy link
Contributor

Vecvec commented Mar 27, 2024

Description
When converting a shader with one acceleration structure that is never used using Naga to SPIR-V and using it (using #3631) the vulkan validation layers give

Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-08737 ] | MessageID = 0xa5625282 | vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error):
    1st operand of Capability: operand RayQueryKHR(4472) requires one of these extensions: SPV_KHR_ray_query
      OpCapability RayQueryKHR
    . The Vulkan spec states: If pCode is a pointer to SPIR-V code, pCode must adhere to the validation rules described by the Validation Rules within a Module section of the SPIR-V Environment appendix (https://vulkan.lunarg.com/doc/view/1.3.275.0/windows/1.3-extensions/vkspec.html#VUID-VkShaderModuleCreateInfo-pCode-08737)

while this is a fork of #3631, no naga changes are in either.

Repro steps

@group(0) @binding(0)
var acc_struct: acceleration_structure;

@workgroup_size(1)
@compute
fn comp_main() {}

gives this error, while changing comp_main to

fn comp_main() {
    var rq: ray_query;
    rayQueryInitialize(&rq, acc_struct, RayDesc(0u, 0xFFu, 0.001, 100000.0, vec3f(0.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0)));
    rayQueryProceed(&rq);
    let intersection = rayQueryGetCommittedIntersection(&rq);
}

fixes the issue

Expected vs observed behavior
Expected: No validation error
Observed: Validation error

Extra materials
test log (just this test, I don't think the other tests would help):
failed test.txt

Platform
This is a fork of #3631.

@teoxoy
Copy link
Member

teoxoy commented Mar 28, 2024

There is probably some validation missing. The fix should be part of #3631.

@Vecvec
Copy link
Contributor Author

Vecvec commented Mar 28, 2024

I think this might be the cause

let has_ray_query = ir_module.special_types.ray_desc.is_some()
| ir_module.special_types.ray_intersection.is_some();

this only puts the extension in if there is a ray desc or a ray intersection used, should there be a bool that is set somewhere (maybe in the shader module?) to tell the writer that this feature is enabled if any ray-tracing type is used?

@teoxoy
Copy link
Member

teoxoy commented Mar 29, 2024

Ah, I misunderstood what the issue was.

The backend should loop over all types and set the has_ray_query var if it sees TypeInner::AccelerationStructure or TypeInner::RayQuery in addition to the special types.

@teoxoy teoxoy added type: bug Something isn't working area: naga back-end Outputs of naga shader conversion naga Shader Translator lang: SPIR-V Vulkan's Shading Language labels Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga back-end Outputs of naga shader conversion lang: SPIR-V Vulkan's Shading Language naga Shader Translator type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants