-
Notifications
You must be signed in to change notification settings - Fork 898
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
Ray Queries #6291
base: trunk
Are you sure you want to change the base?
Ray Queries #6291
Conversation
…u into hal-acceleration-structures
+ seperated RAY_QUERY
(better allocation strategy required)
# Conflicts: # tests/tests/root.rs # wgpu-core/src/command/compute.rs # wgpu-core/src/command/mod.rs # wgpu-core/src/command/ray_tracing.rs # wgpu-core/src/command/render.rs # wgpu-core/src/device/life.rs # wgpu-core/src/device/queue.rs # wgpu-core/src/device/ray_tracing.rs # wgpu-core/src/device/resource.rs # wgpu-core/src/hub.rs # wgpu-core/src/lock/rank.rs # wgpu-core/src/ray_tracing.rs # wgpu-core/src/resource.rs # wgpu-core/src/track/mod.rs # wgpu/src/backend/wgpu_core.rs # wgpu/src/context.rs # wgpu/src/ray_tracing.rs
I'm super excited for this! What makes this PR a draft? What do you think is missing? |
Examples, there is no case for no index buffer (but I'm working on it, hopefully done in a day or so). |
This looks very exciting. This is a pretty large PR and to my knowledge, none of the wgpu maintainers are ray tracing experts. So to facilitate the review process, while we try to ramp up our knowledge of the domain, could you summarize here the context (that is scattered in #1040 and other places)? In particular:
|
To preface this, I came later to this (after most of the design was finalized), so I may not know all of the missing validation, tradeoffs, etc. I will be talking about the safe tlas building (blas building is always safe but there is a extra unsafe function to do unsafe tlas building which might (?) be faster) To my knowledge the only missing pieces of validation are The main tradeoffs are not exposing the scratch buffers because they are harder to validate (possibly) and could cause confusion (especially since most of that is lower level than wgpu provides, and also could be accidently be read back, giving garbage info and leaving the user confused) , which is why in an attempt to mitigate the allocation time blas building and tlas building are unified. This implementation lacks compaction, which was in the initial API design, but needs another HAL function. Procedural geometry (naga needs to implement this, and if most people want to partially support this they will mainly use triangles). I believe there is a full wgpu API (though without ray-tracing pipelines) Extra things to note: this is just for wgpu and wgpu-core, naga support (for ray queries) was added earlier. There is a ray-tracing pipeline that would be nice to have (it could allow a ray-tracer - e.g path-tracer - to be extended). Edit: wgpu-hal support was also added earlier, but only for vulkan (so some things here still have to consider metal and dx12, though dx12 also was considered) The naming is slightly confusing, this might be called ray-tracing, but something that uses this API to create something that simulates light bouncing around a scene might also be said to be ray-tracing (this does not do the second thing). I think that is everything. Tell me if there are other questions about the API. Edit # 2: mostly api is from #1040 (comment) |
…RAY_TRACING_ACCELERATION_STRUCTURE is enabled
I've realised my previous comment requies quite some preexisting raytracing knowledge, so here are the API concepts:
All metal, vulkan, and DXR use roughly these concepts (and they are based on one another). |
I've noticed that a validation fix for spv (in trunk now see #5760) was duplicated in this PR, so I've removed that. (I think this was why gfx-rs/naga was requested for review) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a first pass, it looks like a solid contribution, thanks a lot! Since I'm still wrapping my head around the domain, so what is coming out of this first review is the usual round of stylistic changes. There is probably going to be more of those in the next pass and hopefully soon a more thorough review of the more interesting/technical aspects of the work.
.map(|x| { | ||
let geometries = match x.geometries { | ||
BlasGeometries::TriangleGeometries(triangle_geometries) => { | ||
crate::ray_tracing::TraceBlasGeometries::TriangleGeometries( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: let's use
symbols like crate::ray_tracing::TraceBlasGeometries
at the top of the file to avoid the long names.
Let's also use crate::device::trace
to shorten these as well (keeping the trace
part visible in the code is valuable in this case).
) | ||
.unwrap(); | ||
|
||
#[cfg(feature = "trace")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be easier to read if this sequence of conditionally compiled code was all in a
#[cfg(feature = "trace")]
{
// move the code in here
}
block.
Ok(()) | ||
} | ||
|
||
/// Iterates over the buffers generated [iter_blas] and convert the barriers into hal barriers, and the triangles into [hal::AccelerationStructureEntries] (and also some validation). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Iterates over the buffers generated [iter_blas] and convert the barriers into hal barriers, and the triangles into [hal::AccelerationStructureEntries] (and also some validation). | |
/// Iterates over the buffers generated in [iter_blas], convert the barriers into hal barriers, and the triangles into [hal::AccelerationStructureEntries] (and also some validation). |
Vec::<hal::AccelerationStructureTriangles<dyn hal::DynBuffer>>::with_capacity( | ||
desc.len(), | ||
); | ||
for x in desc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's give x
a descriptive name.
for x in desc { | |
for desc in descriptors { |
/// - lazy instance buffer allocation | ||
/// - maybe share scratch and instance staging buffer allocation | ||
/// - partial instance buffer uploads (api surface already designed with this in mind) | ||
/// - ([non performance] extract function in build (rust function extraction with guards is a pain)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit off how this comment for the file sits between two use statements and seems to apply to the use std::{num::NonZeroU64, slice};
under it. Let's move it to the first line and also make it a regular //
comment instead of a doc comment.
pub enum BlasGeometrySizeDescriptors { | ||
/// Triangle geometry version. | ||
Triangles { | ||
/// Descriptor for each triangle geometry. | ||
desc: Vec<BlasTriangleGeometrySizeDescriptor>, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This descriptor should take a slice instead of a vector.
Also, wgpu so far has avoided chopping off words in the public API. I think that it's a good thing, and the plural form is informative.
pub enum BlasGeometrySizeDescriptors { | |
/// Triangle geometry version. | |
Triangles { | |
/// Descriptor for each triangle geometry. | |
desc: Vec<BlasTriangleGeometrySizeDescriptor>, | |
}, | |
} | |
pub enum BlasGeometrySizeDescriptors<'a> { | |
/// Triangle geometry version. | |
Triangles { | |
/// Descriptor for each triangle geometry. | |
descriptors: &'[BlasTriangleGeometrySizeDescriptor], | |
}, | |
} |
For consistency with the rest of the API, BlasGeometrySizeDescriptors should be passed by reference (for example in create_blas
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required to have no lifetimes because it is used in the wgpu-core BLAS here
https://github.com/Vecvec/wgpu/blob/0fcc749efda0f22ccbcd5dffed3442d68fd17850/wgpu-core/src/resource.rs#L1924-L1925
doing this would require a duplicate size descriptor for wgpu-core that was a vector.
Edit: This sounds like I'm disagreeing, which I am not, I just want to know whether I should still do this if it had a reason.
@@ -0,0 +1,154 @@ | |||
// Ray tracing api proposal for wgpu (underlining Vulkan, Metal and DX12 implementations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should be removed from the PR before merging.
*.mtl binary | ||
*.obj binary | ||
wgpu/src/backend/webgpu/webgpu_sys/** linguist-generated=true | ||
>>>>>>> trunk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this change is not intentional.
Connections
Works towards #1040
Description
This PR provides BLASes (bottom level acceleration structures), TLASes (top level acceleration structures), TLAS instances (which contain BLASes and data, like transforms, about them), TLAS packages (which contain vectors of TLAS instances).
Testing
Running tests & examples included in PR
This a updated version of #3631 and is inteanded to replace it.
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.Later (follow-up PR)
as_hal
methods