DX12 DXR: How do you manage the same HitGroup data between different state object?

Started by
0 comments, last by SquallLiu 3 years, 7 months ago

I've wrote a ray tracing shadow shader before. (abbreviated as ShaderA)

And recently I wrote another ray tracing shader. (abbreviated as ShaderB)

I create ID3D12StateObject for both.

But hit group shader identifier is unique between each ID3D12StateObject.

My hit group data struct is like this:

| shader identifier (32bytes) | material data (smooth, etc…224 bytes) |

It also used in rendering so I aligned it to 256 bytes.

A scene with 100 materials I would create 25600 bytes buffer for them.

With InstanceContributionToHitGroupIndex() I can know the material used by hit object.

I tried to reuse the hit group from ShaderA on ShaderB but GPU got device removal.

It is expected since DXR system recognizes shader identifier memory from state object but not the hit group name.

For every new dxr state object (different shader), I need to create a new material array for it.

Which means I need to create 25600 * 2 bytes for 2 shaders.

And the only difference is the identifier data in first 32 bytes….

Is there any way can optimize my case?

Seems creating only one state object is the solution. However it would be hard to maintain the shader codes for different jobs.

This topic is closed to new replies.

Advertisement