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

draw_indexed_indirect on DX12 doesn't handle non-zero base_instance #2471

Open
Tracked by #2719
FredrikNoren opened this issue Feb 10, 2022 · 6 comments
Open
Tracked by #2719
Assignees
Labels
api: dx12 Issues with DX12 or DXGI area: correctness We're behaving incorrectly type: enhancement New feature or request

Comments

@FredrikNoren
Copy link

Description
DrawIndexedIndirect.base_instance is always 0 in the shader when using draw_indexed_indirect on DX12, regardless of the value provided. This works on Vulcan and Metal. Setting the INDIRECT_FIRST_INSTANCE flag doesn't help.

Platform
wgpu 0.12.0, Windows DX12

(Filed this issue by request from @kvark from a discussion in the matrix chat)

@kvark kvark self-assigned this Feb 10, 2022
@kvark kvark added area: correctness We're behaving incorrectly type: enhancement New feature or request labels Feb 10, 2022
@kvark
Copy link
Member

kvark commented Feb 10, 2022

Doesn't look like Dawn has this implemented either - https://bugs.chromium.org/p/dawn/issues/detail?id=548&q=548&can=2

@kvark
Copy link
Member

kvark commented Feb 10, 2022

I concluded the research here. Good example code can be found in d3d functional spec. Unfortunately, we can't just re-use the start instance you have in the draw structures. The indirect command signature requires this value to be placed separately in a draw structure... So the only way around for us is to copy your draw structure into one we temporarily create, so that we can also copy the start instance.

This was the bad news. I definitely didn't want to involve a copy of indirect arguments here...
A bit of good news is that we have to copy it for safety anyway, see #2431. So there is no overhead on top of the safety precautions we wanted to do. But there is overhead if you don't need safety, yikes.

@jimblandy
Copy link
Member

Dawn has fixed that bug.

@teoxoy
Copy link
Member

teoxoy commented May 22, 2024

We should remember to also remove DownlevelFlags::VERTEX_AND_INSTANCE_INDEX_RESPECTS_RESPECTIVE_FIRST_VALUE_IN_INDIRECT_DRAW (added recently in #4723) once this is resolved.

@mikialex
Copy link

Dx12 non-zero base_instance actually works but the result is just not exposed in the shader. Before this issue get fixed, one way to workaround is to manually generate(by compute shader) a base_instance buffer and bind it as an instance vertex buffer.

ArvinSKushwaha added a commit to ArvinSKushwaha/raynforest that referenced this issue Jun 8, 2024
remove incompatible windows & rust testing (for now).

Refer to: gfx-rs/wgpu#2471
ArvinSKushwaha added a commit to ArvinSKushwaha/raynforest that referenced this issue Jun 8, 2024
remove incompatible windows & rust testing (for now).

Refer to: gfx-rs/wgpu#2471
@teoxoy teoxoy assigned teoxoy and unassigned kvark Jul 26, 2024
@teoxoy
Copy link
Member

teoxoy commented Jul 26, 2024

This has a lower priority than #2431 but I will work on it right after draw indirect validation since it will be easier to do while I still have that context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dx12 Issues with DX12 or DXGI area: correctness We're behaving incorrectly type: enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

5 participants