Is your feature request related to a problem? Please describe.
Currently, acceleration structure building does not handle vertex positions with Nan in them. Building an BLAS with a buffer that has a vertex containing a Nan is UB in both DX12 and Vulkan (in theory the current code can work with Nans in the x position due to some interesting mechanics).
Describe solutions you've considered
- Copy vertex buffer into a temporary buffer
We could copy every vertex into a new buffer, zeroing Nans as we went (e.g in a compute shader)
- Pros
- Cons
- Requires a lot of memory for large scenes (as we have to keep all these buffers around until the command encoder ends)
- Additionally, instead of disposing of these buffers, they could be placed into a vec to be reused. BLAS build could also be split if the combined buffer uses too much space.
- Remove
Nans from users buffer
We could state that building BLASes may modify memory if there are Nans in the bit representation
- Pros
- Simple
- Low memory footprint
- Cons
- Really confusing for users - No other API I know of can modify any buffer except the scratch buffer
- Change
Nans out of being Nans and then back to being Nans
Use the fact that a Nan is a fully set exponent - Store a packed bool array (a bit per vertex component) whether a float is a Nan and if it is a Nan, remove a bit from the exponent (re-adding it after building).
I think that option 2 is probably not good, its confusing for users who would get their buffers changed under very edge case scenarios. Option 1 vs option 3 probably depends on how large real world vertex buffer usage is.
Additional context
I can't find anything in the Metal docs on whether Nans are allowed or not, so it might be UB.
Is your feature request related to a problem? Please describe.
Currently, acceleration structure building does not handle vertex positions with Nan in them. Building an BLAS with a buffer that has a vertex containing a
Nanis UB in both DX12 and Vulkan (in theory the current code can work withNans in the x position due to some interesting mechanics).Describe solutions you've considered
We could copy every vertex into a new buffer, zeroing
Nans as we went (e.g in a compute shader)Nans from users bufferWe could state that building BLASes may modify memory if there are
Nans in the bit representationNans out of beingNans and then back to beingNansUse the fact that a
Nanis a fully set exponent - Store a packed bool array (a bit per vertex component) whether a float is aNanand if it is aNan, remove a bit from the exponent (re-adding it after building).I think that option 2 is probably not good, its confusing for users who would get their buffers changed under very edge case scenarios. Option 1 vs option 3 probably depends on how large real world vertex buffer usage is.
Additional context
I can't find anything in the Metal docs on whether
Nans are allowed or not, so it might be UB.