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

[spirv] Stop naga causing undefined behavior in rayQueryGet*Intersection #6752

Open
wants to merge 26 commits into
base: trunk
Choose a base branch
from

Conversation

Vecvec
Copy link
Contributor

@Vecvec Vecvec commented Dec 16, 2024

Connections
fixes #6731

Description
Naga previously unconditionally called operations that required the ray to hit something. This is undefined behavior according to the spirv raytracing spec. This caused seg-faults on lavapipe. This prevents that by separating the intersection getter into another function with conditional blocks.

Testing
added a test that previously failed (with a seg-fault) that now succeeds

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy. If applicable, add:
    • [n/a] --target wasm32-unknown-unknown
    • [n/a] --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@Vecvec Vecvec requested review from a team as code owners December 16, 2024 05:12
@jimblandy jimblandy self-assigned this Dec 18, 2024
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on the tests

tests/tests/ray_tracing/shader.rs Outdated Show resolved Hide resolved
tests/tests/ray_tracing/shader.rs Outdated Show resolved Hide resolved
tests/tests/ray_tracing/shader.rs Outdated Show resolved Hide resolved
Comment on lines +38 to +50
out = Intersection(
intersection.kind,
intersection.t,
intersection.instance_custom_index,
intersection.instance_id,
intersection.sbt_record_offset,
intersection.geometry_index,
intersection.primitive_index,
intersection.barycentrics,
u32(intersection.front_face),
intersection.world_to_object,
intersection.object_to_world,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What values do these have if they are not valid to read? Similarly might it be useful to assert that the values are sane coming out of the api?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is these are always valid to read, it should just be zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what happens on a mac though, it may still have undefined behavior.

Copy link
Contributor Author

@Vecvec Vecvec Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way metal's API is designed seems to suggest that undefined behavior is unlikely (but I can't find anything in the specification that suggests this).

@Vecvec Vecvec changed the title Stop naga causing undefined behavior in rayQueryGet*Intersection [spirv] Stop naga causing undefined behavior in rayQueryGet*Intersection Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lavapipe causes access violation accessing intersection.world_to_object
3 participants