Skip to content

[DX] Implement Sampler support (#1042)#1231

Draft
alsepkow wants to merge 9 commits into
llvm:mainfrom
alsepkow:alex/dx-samplers-1042
Draft

[DX] Implement Sampler support (#1042)#1231
alsepkow wants to merge 9 commits into
llvm:mainfrom
alsepkow:alex/dx-samplers-1042

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.

Adds D3D12 support for Sampler and SamplerComparisonState, matching the existing Vulkan implementation. The schema, root signature plumbing, descriptor heap layout, and bind path are all updated so tests can declare samplers in YAML and consume them from compute or graphics shaders.

The new ResourceKind::Sampler flows through the existing switch sites in Pipeline.h and the three Device.cpp backends. On D3D12, samplers live in a separate D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER heap; the root signature gains a parallel descriptor table whose range type is D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, and SetDescriptorHeaps binds both heaps simultaneously. Sampler properties (filter, address modes, comparison function, mip LOD bias, max anisotropy, border color) are mapped from the YAML Sampler struct one-to-one to D3D12_SAMPLER_DESC.

Tests: Sampler.Sample.test, Sampler.SampleLevel.test, SamplerComparisonState.SampleCmpLevelZero.test. PASS on d3d12, warp-d3d12, vk. Full Samplers sweep across 6 backends shows no regressions.

Resolves #1042


Assisted by Claude Opus 4.7.

alsepkow and others added 4 commits May 26, 2026 18:02
Adds D3D12 backend support for HLSL samplers. The DX device now creates a
shader-visible SAMPLER descriptor heap alongside the existing CBV_SRV_UAV
heap, splits each DescriptorSet's bindings into separate resource and
sampler descriptor tables in the implicit root signature, and writes
sampler descriptors via ID3D12Device::CreateSampler driven by the
pipeline.yaml Sampler entries. Helpers translate the offload-test-suite
Sampler schema (Address, MinFilter, MagFilter, SamplerKind, CompareFunc)
to D3D12_SAMPLER_DESC, including the comparison-reduction bit for
SamplerComparisonState. Both the compute and graphics command builders
now bind both heaps and emit one root descriptor table per present
table per set.

Removes the XFAIL on (or qualifies to Clang-only) the following tests
that now PASS on d3d12 / warp-d3d12: Texture2D.Sampler.address,
Texture2D.Sampler.filter, Texture2D.Gather. Adds a new minimal
compute-shader sampler test (Texture2D.Sampler.compute) that exercises
the new Sampler binding path with a 2x2 texture and nearest sampling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addresses code review feedback on the sampler-support change: the
explicit RootParams path in createComputeCommands advanced the
CBV/SRV/UAV descriptor handle by Resources.size() of the current set,
which includes Sampler descriptors. Samplers live in a separate
descriptor heap (SamplerHandle / SamplerHeap), so counting them here
misaligns subsequent DescriptorTable bindings for sets containing both
resources and samplers. Count only non-sampler resources, matching the
fallback (implicit) RootParams path. Binding sampler tables via
explicit RootParams remains unimplemented (the SAMPLER case of
RootDescriptor still hits llvm_unreachable) and no test currently
exercises this path, but the offset arithmetic is now correct in
preparation for that work.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply clang-format 19.1.6 to changed regions per pr-code-format CI.
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>
alsepkow and others added 5 commits May 27, 2026 13:29
Fixes misc-const-correctness warnings-as-errors from clang-tidy in CI.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Two additional sites in the graphics-pipeline CopyBackResource that I missed in the earlier const sweep. Same misc-const-correctness rule as Device.cpp:2350/2363.

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

[DirectX] Add Sampler[Comparison] resource support

1 participant