gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 547 forks source link

dx12: Support VertexIndex and InstanceIndex semantics #2589

Open msiglreith opened 5 years ago

msiglreith commented 5 years ago

Nonzero base vertex or instance values are reflected properly when translating to HLSL. Recently a new feature has been added to spirv-cross to support this: https://github.com/KhronosGroup/SPIRV-Cross/pull/816

We need to a new root constant into graphics pipeline layouts for storing these two values and push them on draw calls. The drawIndirectFirstInstance can't be supported it seems.

VkPI

Further investigation needed if we need to restrict it also to base vertex due to the VertexIndex semantic?

fu5ha commented 5 years ago

Steps for completion:

  1. Familiarize yourself with root descriptors and root constants (https://docs.microsoft.com/en-us/windows/desktop/direct3d12/root-signatures-overview)
  2. Add new root constants here https://github.com/gfx-rs/gfx/blob/master/src/backend/dx12/src/device.rs#L1276
  3. Add to the signature here for the draw command https://github.com/gfx-rs/gfx/blob/master/src/backend/dx12/src/device.rs#L482-L483

(@msiglreith can you check my logic on this? I'm not sure if I'm right or not, not super familiar with d3d12 ;p)

msiglreith commented 5 years ago

@termhn Thanks! Command Signature is unrelated to this (Step 3). It defines the layout of the gpu commands in the buffers for indirect command execution. To extend on Step 2, see the comment here: https://github.com/gfx-rs/gfx/issues/2604#issuecomment-460385700

These two issues are basically the same, one for graphics pipelines and one for compute pipeline. We have 4 root constants spare IIRC, which will be shared for both pipeline types (basically like an union). In this case we need to allocate 2 u32 bit constants for these two builtins and patch spirv accordingly.