Skip to content

Conversation

@inner-daemons
Copy link
Collaborator

@inner-daemons inner-daemons commented Nov 8, 2025

Connections
Closes #8376
Followup to #8206
Depends on #8377

CC @Wumpf : will you review this, or someone else?

Description
Adds multiview support to DX12

Testing
Using standard multiview tests introduced in #8206

Squash or Rebase?
Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unification in device.rs looks nice!

Definitely still need to improve helpfulness (and language!) of those comments.

Actual logic might actually be alright (minus open questions in the comments, in particular is the mask actually set? Oo) but I'm still brooding on how to make it safer & easier to maintain; I suggested pinning for safety, but tbh I haven't thought it through entirely yet.

Comment on lines 17 to 18
/// Returned bytes contain pointers into this struct, for them to be valid,
/// this struct not move or be dropped. As if `as_bytes<'a>(&'a self) -> Vec<u8> + 'a`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we emit pointers to this struct we have to pin it. Otherwise, Rust may move it around thus invalidating those pointers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the safety around that. But I'll leave this open since I'm not 100% sure I'm doing this right, even though both code paths work on my machine

@Wumpf
Copy link
Member

Wumpf commented Nov 9, 2025

eh, guess I should have checked on the "depends on". Well, some feedback for the other PR in here as well I reckon

@inner-daemons
Copy link
Collaborator Author

@Wumpf Damn, thanks for the quick and thorough review! Much appreciated!

I definitely need to get better at writing comments lol. Will look at this over the next few days.

@inner-daemons
Copy link
Collaborator Author

inner-daemons commented Nov 14, 2025

@Wumpf The parent PR has gotten merged. One thing I will say is that @cwfitzgerald was skeptical about using pin in some places, and I don't really understand this stuff, but are you sure we need to pin the data like we do with these few lines?

let mut view_instancing =
    core::pin::pin!(ArrayVec::<Direct3D12::D3D12_VIEW_INSTANCE_LOCATION, 32>::new());
if let Some(mask) = desc.multiview_mask {
    let mask = mask.get();
    // This array is just what _could_ be rendered to. We actually apply the mask at
    // renderpass creation time. The `view_index` passed to the shader depends on the
    // view's index in this array, so if we include every view in this array, `view_index`
    // actually the texture array layer, like in vulkan.
    for i in 0..32 - mask.leading_zeros() {
        view_instancing.push(Direct3D12::D3D12_VIEW_INSTANCE_LOCATION {
            ViewportArrayIndex: 0,
            RenderTargetArrayIndex: i,
        });
    }
}

Anyway, if possible, lets try to merge this soon-ish

@Wumpf Wumpf self-requested a review November 16, 2025 09:41
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wager @cwfitzgerald has more experience with the pins here, so if he says it's not a good idea here I'd stick with that.
I'm mostly just worried about accidentally moving the contents while we have a pointer to them, but admittedly I can't see how that could be happening here anyways.

Changes lgtm!

@Wumpf Wumpf merged commit 05369a6 into gfx-rs:trunk Nov 16, 2025
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[hal/dx12] Multiview

2 participants