Skip to content

[DX] View instancing follow-up: 4-view test (#1051)#1238

Draft
alsepkow wants to merge 7 commits into
llvm:mainfrom
alsepkow:alex/dx-viewinst-1051
Draft

[DX] View instancing follow-up: 4-view test (#1051)#1238
alsepkow wants to merge 7 commits into
llvm:mainfrom
alsepkow:alex/dx-viewinst-1051

Conversation

@alsepkow

@alsepkow alsepkow commented May 27, 2026

Copy link
Copy Markdown
Collaborator

EXPERIMENTAL - NOT FOR REVIEW

AI-assisted exploration driving design discussion for llvm/wg-hlsl#400. Not intended for review/merge in current form.

Follow-up to the initial view instancing scaffolding: adds a 4-view test exercising SV_ViewID across multiple viewports. The schema gains Pipeline.Viewports (a list of {X, Y, Width, Height}) and the DX backend configures both RSSetViewports and RSSetScissorRects from the list, with view instancing enabled at PSO creation when more than one viewport is declared. Feature is gated on D3D12_VIEW_INSTANCING_TIER_1.

Tests: ViewInstancing.4view.test renders a single draw call broadcast across four viewports, each with its own per-view color selected by SV_ViewID in the VS. PASS on d3d12.

Remaining on parent #1051 (not in this PR):

  • VK: enable multiview and multiViewport device features, configure the render pass for multiview rendering, set multiple viewports / scissors at draw time.
  • DX: migrate the PSO creation path from the legacy descriptor to PSO_STREAM so view instancing configuration is first-class (covered separately by draft [DRAFT] [DirectX] Migrate all PSO creation to PSO_STREAM (CD3DX12_PIPELINE_STATE_STREAM2) #1263).
  • Lit feature for view instancing capability detection.
  • Independent VK tests once the VK side lands.

Refs #1051


Assisted by Claude Opus 4.7.

alsepkow and others added 7 commits May 26, 2026 19:50
Adds a new `Texture2DArray` `ResourceKind` and wires it through the
DirectX backend so shaders can `Load` from layered SRVs:

* `OutputProperties` gains an `ArraySize` field (default 1) and the
  YAML size validation now accounts for it.
* `getResourceDescription` sets `DepthOrArraySize` from
  `ArraySize` for `Texture2DArray` resources and rejects mismatched
  uses of `ArraySize > 1` on non-array kinds.
* `getSRVDescription` emits a `TEXTURE2DARRAY` view covering all
  slices.
* The upload path enumerates slices via `CopyTextureRegion` with a
  per-slice `D3D12_PLACED_SUBRESOURCE_FOOTPRINT`; the host-side data
  layout is tightly packed slice-major (slice0 rows | slice1 rows |
  ...).

Vulkan and Metal switches gain `Texture2DArray` cases for build
completeness; their device implementations remain TODO and the new
test is gated `UNSUPPORTED: Vulkan || Metal`.

Adds `Feature/Textures/Texture2DArray.Load.test.yaml` exercising a
2x2x3 array with `Load(int4)` and offset variants. Verified passing
on d3d12 (NVIDIA RTX 5060 Ti) and warp-d3d12.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
First slice of view-instancing support: schema, pipeline plumbing, and
the alternate PSO_STREAM creation path needed to attach a view-instancing
subobject. Render-target multi-slice readback and the actual test land
in a follow-up commit; existing graphics tests are unaffected because
the new code path is gated on `ViewInstanceCount > 1`.

* Pipeline schema: new `Pipeline.ViewInstanceCount` (default 1)
  parsed in `Pipeline.cpp`.
* API plumbing: `TraditionalRasterPipelineCreateDesc.ViewInstanceCount`
  and `TextureCreateDesc.ArraySize`; `createRenderTargetFromCPUBuffer`
  now threads `OutputProps.ArraySize` so render targets become
  `Texture2DArray` resources when requested.
* DX backend:
  - `createTexture` honours `Desc.ArraySize` for the resource
    descriptor (`DepthOrArraySize`); the default `nullptr` RTV/DSV
    descriptor naturally yields a TEXTURE2DARRAY view covering all
    slices.
  - `createTraditionalRasterPipeline` now builds a
    `CD3DX12_PIPELINE_STATE_STREAM2` and attaches a
    `CD3DX12_VIEW_INSTANCING_DESC` (view N -> RT array slice N) when
    `ViewInstanceCount > 1`; non-VI pipelines continue to use the
    existing `D3D12_GRAPHICS_PIPELINE_STATE_DESC` path.
  - `executeProgram` propagates `P.ViewInstanceCount` to the
    pipeline descriptor.

Follow-up (next commit / tick):
* Multi-slice render-target readback (`CopyTextureRegion` per slice,
  larger readback buffer, slice-major `copyFromTexture`).
* Per-view depth-stencil target ArraySize matching.
* `Feature/ViewInstancing/multiview-2views.test`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…1051)

Extends the D3D12 render target readback path to handle Texture2DArray render targets:

* getAlignedTextureBufferSize() rounds each slice up to D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT (512) and multiplies by ArraySize so the staging buffer is sized correctly.

* createGraphicsCommands() now issues one CopyTextureRegion per array slice with placement-aligned per-slice footprints.

* readBack() walks slices, copying each one tightly into CPUBuffer.Data[0] slice-major using the actual padded RowPitch reported by GetCopyableFootprints.

* createDefaultDepthStencilTarget gains an ArraySize argument; createDepthStencil threads OutputProps.ArraySize through so the DSV slice count matches the bound RT when a view-instanced pipeline is dispatched.

* validateTextureCreateDesc cross-checks ArraySize and the expected total buffer size now factors ArraySize in.

Adds Feature/ViewInstancing/multiview-2views.test which exercises a 2x2 ArraySize=2 RT with ViewInstanceCount=2 (PSO ViewInstancingDesc routes view N to RT slice N). Pixel shader reads SV_ViewID (ps_6_1) so each slice gets a distinct color. PASSes on d3d12 (RTX 5060 Ti) and warp-d3d12; UNSUPPORTED on Vulkan/Metal until those backends gain a setViewInstanceCount equivalent.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Picks up the DriverVer fix (upstream llvm#1228) so clang-tidy stops failing on Device.cpp.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a 4-view D3D12 view-instancing variant that validates SV_ViewID output routing across four render target array slices.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes misc-const-correctness warnings-as-errors from clang-tidy in CI.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants