Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3353,7 +3353,11 @@ The trace will enumerate them.
a VS stream builds the same PSO as the classic call.
- `E_INVALIDARG`, as on the PC runtime: a type given twice, an unknown type, a truncated stream, MS with VS,
tessellation or GS, CS with a graphics stage, or no stage at all.
- `E_NOTIMPL` with a log, for what is not built yet: an AS, a depth-bounds test, view instancing.
- `E_NOTIMPL` with a log, for what is not built yet: an AS, view instancing.
- `DEPTH_STENCIL1`/`DEPTH_STENCIL2` `DepthBoundsTestEnable` maps to hardware `depthBoundsTestEnable` +
`VK_DYNAMIC_STATE_DEPTH_BOUNDS` and `OMSetDepthBounds` — recorded on both direct lists and bundles, with
out-of-range/inverted/`NaN` bounds accepted at record time as on D3D12 and sanitized into Vulkan's `0..1`
range at replay — refusing with `E_NOTIMPL` when `VkPhysicalDeviceFeatures::depthBounds` is absent.
- `DEPTH_STENCIL2`'s per-face read and write masks go to each face's `VkStencilOpState` (the front face's in the
description, the back face's beside it), so `OPTIONS14.IndependentFrontAndBackStencilRefMaskSupported` is TRUE:
with `OMSetFrontAndBackStencilRef`'s per-face references, both of that cap's parts.
Expand Down Expand Up @@ -3483,7 +3487,8 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv
- `OPTIONS19` maps `SupportedSampleCountsWithNoOutputs` from `framebufferNoAttachmentsSampleCounts`, ties
`AnisoFilterWithPointMipSupported` to `VulkanDeviceInfo::sampler_anisotropy`, and reports the baseline heap
limits (`2048` samplers, `1000000` views);
- `OPTIONS21` reports baseline `D3D12_EXECUTE_INDIRECT_TIER_1_0`, and unimplemented features/tiers (`DepthBounds`,
- `OPTIONS2` reports `DepthBoundsTestSupported` from `VkPhysicalDeviceFeatures::depthBounds`;
- `OPTIONS21` reports baseline `D3D12_EXECUTE_INDIRECT_TIER_1_0`, and unimplemented features/tiers (
`CastingFullyTypedFormat`, MSAA UAVs, independent stencil masks, render passes, RT, mesh shaders, sampler
feedback, wave MMA, work graphs, GPU upload heaps) stay `FALSE`/`NOT_SUPPORTED`/`TIER_0`. Checked live against
the host D3D12 runtime on the same adapter (`NVIDIA GeForce RTX 5080`, driver `616.56`, Windows 11): 15/15 feature
Expand Down
11 changes: 11 additions & 0 deletions runtime/shims/d3d12_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class GraphicsCommandList final
}
UINT front_stencil_ref() const { return front_stencil_ref_; }
UINT back_stencil_ref() const { return back_stencil_ref_; }
const std::array<float, 2>& depth_bounds() const { return depth_bounds_; }
D3D12_GPU_VIRTUAL_ADDRESS cbv_srv_uav_base() const { return cbv_srv_uav_base_; }
D3D12_GPU_VIRTUAL_ADDRESS sampler_base() const { return sampler_base_; }

Expand Down Expand Up @@ -557,6 +558,7 @@ class GraphicsCommandList final
// ID3D12GraphicsCommandList1: the depth-bounds test's range for the draws after it, read by pipelines that enable
// the test (DEPTH_STENCIL1/2). D3D12's default is [0, 1].
void STDMETHODCALLTYPE OMSetDepthBounds(FLOAT min, FLOAT max) override {
d3d12_trace::record("ID3D12GraphicsCommandList1::OMSetDepthBounds");
if (list_->closed()) return;
const std::array<float, 2> value{min, max};
if (defer([=](GraphicsCommandList& l) { l.depth_bounds_ = value; })) return;
Expand Down Expand Up @@ -3543,6 +3545,15 @@ bool hold_until_reset(ID3D12GraphicsCommandList* list, IUnknown* object) {
return true;
}

bool depth_bounds(ID3D12GraphicsCommandList1* list, float& min_depth, float& max_depth) {
const GraphicsCommandList* l = GraphicsCommandList::from(list);
if (!l) return false;
const auto& bounds = l->depth_bounds();
min_depth = bounds[0];
max_depth = bounds[1];
return true;
}

bool recorded_commands(ID3D12GraphicsCommandList* list, std::vector<leonida::Command>& commands) {
const GraphicsCommandList* l = GraphicsCommandList::from(list);
if (!l) return false;
Expand Down
3 changes: 3 additions & 0 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,9 @@ bool front_back_stencil_ref(ID3D12GraphicsCommandList8* list, UINT& front, UINT&
// lists or `object` is null.
bool hold_until_reset(ID3D12GraphicsCommandList* list, IUnknown* object);

// The depth-bounds range last recorded by ID3D12GraphicsCommandList1::OMSetDepthBounds on `list` (default 0..1).
bool depth_bounds(ID3D12GraphicsCommandList1* list, float& min_depth, float& max_depth);

// A copy of the commands `list` has recorded so far, for tests of what a bundle puts into its parent. False when
// `list` is not one of this module's command lists.
bool recorded_commands(ID3D12GraphicsCommandList* list, std::vector<leonida::Command>& commands);
Expand Down
20 changes: 17 additions & 3 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17098,7 +17098,10 @@ leonida::cached_pso::Key pipeline_key(const D3D12_COMPUTE_PIPELINE_STATE_DESC& d
return leonida::sha256_hex(key.data());
}

leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc) {
// `extra` carries fields only a console stream has (back-face masks, depth bounds); they are hashed into the same key,
// as the cached blob holds just the first 64 characters. Without it the key is the plain description's.
leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc,
const leonida::cached_pso::KeyBuilder* extra = nullptr) {
leonida::cached_pso::KeyBuilder key;
key.tag("graphics");
key_root_signature(key, desc.pRootSignature);
Expand Down Expand Up @@ -17148,6 +17151,7 @@ leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC&
.u32(desc.NumRenderTargets);
for (const DXGI_FORMAT format : desc.RTVFormats) key.u32(format);
key.u32(desc.DSVFormat).u32(desc.SampleDesc.Count).u32(desc.SampleDesc.Quality).u32(desc.NodeMask);
if (extra) key.bytes(extra->data().data(), extra->data().size());
return leonida::sha256_hex(key.data());
}

Expand Down Expand Up @@ -18043,7 +18047,7 @@ class PipelineState final
const auto* record=rt::d3d12_xs::find_pso_record(this);
PipelineStream stream{};
HRESULT hr=record?parse_pipeline_stream(record->desc(),stream):E_INVALIDARG;
if(SUCCEEDED(hr))hr=stream.has_cs?create_compute(stream.compute):create_graphics(stream.graphics,&stream.ms,&stream.as);
if(SUCCEEDED(hr))hr=stream.has_cs?create_compute(stream.compute):create_graphics(stream.graphics,&stream.ms,&stream.as,stream.back_masks?&stream.back_stencil:nullptr,&stream.extras);
});
}
return registered_ && (is_graphics_==graphics);
Expand Down Expand Up @@ -23521,7 +23525,17 @@ class Device final
if(!record)return E_INVALIDARG;
auto* pipeline=new PipelineState(state_);
pipeline->attach_device(identity());
pipeline->set_cache_key(stream.has_cs?pipeline_key(stream.compute):pipeline_key(stream.graphics));
if(stream.has_cs) {
pipeline->set_cache_key(pipeline_key(stream.compute));
} else {
// The stream description carries fields the plain graphics description cannot:
// DEPTH_STENCIL2 back-face masks and the depth-bounds enable. Mix them in so two
// console PSOs differing only in these do not share one cache key.
leonida::cached_pso::KeyBuilder extra;
extra.u32(stream.back_masks?1u:0u).u32(stream.back_stencil.read).u32(stream.back_stencil.write)
.u32(stream.extras.depth_bounds_test?1u:0u);
pipeline->set_cache_key(pipeline_key(stream.graphics,&extra));
}
if(state_.order_log||state_.prewarm_plan) pipeline->set_order_key(order_key(stream));
if(!rt::d3d12_xs::attach_pso_record(pipeline,std::move(record))){pipeline->Release();return E_OUTOFMEMORY;}
pipeline->set_pending_stream(stream.has_cs);
Expand Down
10 changes: 7 additions & 3 deletions runtime/src/vulkan_replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -6098,9 +6098,13 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_
cache.set_stencil_reference(command_buffer, vk, draw->stencil_front, draw->stencil_back);
cache.set_blend_constants(command_buffer, vk, draw->blend_factor);
if (graphics.depth_bounds) {
// Vulkan takes bounds in [0, 1] only (without VK_EXT_depth_range_unrestricted), as D3D12 does.
const float lo = std::clamp(draw->depth_bounds[0], 0.0f, 1.0f);
const float hi = std::clamp(draw->depth_bounds[1], 0.0f, 1.0f);
// D3D12 converts NaN to zero; then apply the clamp, with an inverted or disjoint range empty.
// Vulkan takes bounds in [0, 1] only (without VK_EXT_depth_range_unrestricted).
const float mn = draw->depth_bounds[0] != draw->depth_bounds[0] ? 0.0f : draw->depth_bounds[0];
const float mx = draw->depth_bounds[1] != draw->depth_bounds[1] ? 0.0f : draw->depth_bounds[1];
const bool empty = mn > mx || mn > 1.0f || mx < 0.0f;
const float lo = empty ? 1.0f : std::max(mn, 0.0f);
const float hi = empty ? 0.0f : std::min(mx, 1.0f);
cache.set_depth_bounds(command_buffer, vk, lo, hi);
}
for (std::uint32_t slot = 0; slot < d.vertex_buffers.size(); ++slot) {
Expand Down
3 changes: 3 additions & 0 deletions runtime/test/d3d12_bundle_forbidden_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ std::vector<Call> calls() {
{"OMSetBlendFactor", [](Env&, ID3D12GraphicsCommandList* b) {
const FLOAT factor[4] = {1, 1, 1, 1};
b->OMSetBlendFactor(factor); }},
{"OMSetDepthBounds", [](Env&, ID3D12GraphicsCommandList* b) {
Ref<ID3D12GraphicsCommandList1> b1;
if (SUCCEEDED(b->QueryInterface(IID_PPV_ARGS(&b1.p)))) b1->OMSetDepthBounds(0.25f, 0.75f); }},
};
}

Expand Down
35 changes: 35 additions & 0 deletions runtime/test/d3d12_close_parity_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,41 @@ std::vector<Case> cases() {
{"OMSetBlendFactor", true, match,
CALLS(const FLOAT factor[4] = {0.25f, 0.5f, 0.75f, 1.0f}; e.list->OMSetBlendFactor(factor))},
{"OMSetStencilRef(7)", true, match, CALLS(e.list->OMSetStencilRef(7))},
{"OMSetDepthBounds(0.25, 0.75)", true, match,
[](Env& e) {
Ref<ID3D12GraphicsCommandList1> list1;
if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false;
list1->OMSetDepthBounds(0.25f, 0.75f);
return true;
}},
{"OMSetDepthBounds(-0.1, 0.5)", true, match,
[](Env& e) {
Ref<ID3D12GraphicsCommandList1> list1;
if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false;
list1->OMSetDepthBounds(-0.1f, 0.5f);
return true;
}},
{"OMSetDepthBounds(0.5, 1.1)", true, match,
[](Env& e) {
Ref<ID3D12GraphicsCommandList1> list1;
if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false;
list1->OMSetDepthBounds(0.5f, 1.1f);
return true;
}},
{"OMSetDepthBounds(0.8, 0.2)", true, match,
[](Env& e) {
Ref<ID3D12GraphicsCommandList1> list1;
if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false;
list1->OMSetDepthBounds(0.8f, 0.2f);
return true;
}},
{"OMSetDepthBounds(NaN, 0.5)", true, match,
[](Env& e) {
Ref<ID3D12GraphicsCommandList1> list1;
if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false;
list1->OMSetDepthBounds(std::numeric_limits<float>::quiet_NaN(), 0.5f);
return true;
}},
{"ExecuteBundle after post-close state calls on bundle", true, match,
CALLS(const FLOAT factor[4] = {0.25f, 0.5f, 0.75f, 1.0f};
e.closed_bundle->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
Expand Down
17 changes: 16 additions & 1 deletion runtime/test/d3d12_com_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include "../src/gfx10_descriptors.h"

#include <array>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <limits>

#define EXPECT(condition) do { \
if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \
Expand Down Expand Up @@ -136,6 +138,9 @@ int main(int argc, char** argv) {
Ref<ID3D12GraphicsCommandList8> list8;
EXPECT(SUCCEEDED(list->QueryInterface(IID_PPV_ARGS(&list8.p))));
list8->OMSetFrontAndBackStencilRef(1, 2);
list8->OMSetDepthBounds(0.25f, 0.75f);
float min_depth = 0.0f, max_depth = 0.0f;
EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.25f && max_depth == 0.75f);
Ref<ID3D12CommandAllocator> bundle_allocator;
Ref<ID3D12GraphicsCommandList8> bundle;
EXPECT(SUCCEEDED(rt::d3d12::create_command_allocator(D3D12_COMMAND_LIST_TYPE_BUNDLE,
Expand All @@ -153,10 +158,12 @@ int main(int argc, char** argv) {
IID_PPV_ARGS(&wrong_bundle.p)) == E_INVALIDARG);
EXPECT(!wrong_bundle.p);
bundle->OMSetFrontAndBackStencilRef(7, 9);
bundle->OMSetDepthBounds(0.125f, 0.875f);
EXPECT(bundle->Close() == S_OK);
list8->ExecuteBundle(bundle.p);
UINT front = 0, back = 0;
EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 7 && back == 9);
EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.125f && max_depth == 0.875f);

// An untouched bundle inherits the parent's current sticky state; its default values must not overwrite it.
Ref<ID3D12CommandAllocator> untouched_allocator;
Expand All @@ -168,6 +175,7 @@ int main(int argc, char** argv) {
EXPECT(untouched_bundle->Close() == S_OK);
list8->ExecuteBundle(untouched_bundle.p);
EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 7 && back == 9);
EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.125f && max_depth == 0.875f);
list8->ExecuteBundle(bundle.p); // the same closed bundle can be executed repeatedly

ID3D12CommandList* bundle_submission[] = {bundle.p};
Expand Down Expand Up @@ -464,26 +472,32 @@ int main(int argc, char** argv) {
list->ClearDepthStencilView(dsv_handle, D3D12_CLEAR_FLAG_DEPTH, 2.0f, 0, 0, nullptr);
EXPECT(list->Close() == S_OK);

// State-setting calls on a closed direct list or bundle are ignored and do not mutate recorded state.
// Post-close state calls on a closed direct list or bundle are ignored and do not mutate recorded state.
EXPECT(SUCCEEDED(allocator->Reset()));
EXPECT(SUCCEEDED(list->Reset(allocator.p, nullptr)));
list8->OMSetDepthBounds(std::numeric_limits<float>::quiet_NaN(), 0.5f);
list->OMSetStencilRef(5);
list8->OMSetDepthBounds(0.25f, 0.75f);
EXPECT(list->Close() == S_OK);
EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 5 && back == 5);
EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.25f && max_depth == 0.75f);
const FLOAT post_close_factor[4] = {0.1f, 0.2f, 0.3f, 0.4f};
list->OMSetStencilRef(99);
list->OMSetBlendFactor(post_close_factor);
list8->OMSetDepthBounds(0.9f, 0.95f);
list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
list->IASetIndexBuffer(nullptr);
list->SetPipelineState(nullptr);
list->ClearState(nullptr);
list->ExecuteBundle(bundle.p);
EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 5 && back == 5);
EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.25f && max_depth == 0.75f);
EXPECT(list->Close() == E_FAIL);

// Post-close state calls on a closed bundle do not append calls or invalidate the bundle.
bundle->OMSetStencilRef(99);
bundle->OMSetBlendFactor(post_close_factor);
bundle->OMSetDepthBounds(0.9f, 0.95f);
bundle->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINELIST);
bundle->IASetIndexBuffer(nullptr);
bundle->SetPipelineState(nullptr);
Expand All @@ -493,6 +507,7 @@ int main(int argc, char** argv) {
EXPECT(SUCCEEDED(list->Reset(allocator.p, nullptr)));
list->ExecuteBundle(bundle.p);
EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 7 && back == 9);
EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.125f && max_depth == 0.875f);
EXPECT(list->Close() == S_OK);
}

Expand Down
Loading
Loading