Skip to content
Open
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 @@ -2452,7 +2452,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 @@ -2582,7 +2586,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
34 changes: 32 additions & 2 deletions runtime/shims/d3d12_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class GraphicsCommandList final
}
UINT front_stencil_ref() const { return front_stencil_ref_; }
UINT back_stencil_ref() const { return back_stencil_ref_; }
float min_depth_bounds() const { return min_depth_bounds_; }
float max_depth_bounds() const { return max_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 @@ -565,7 +567,8 @@ class GraphicsCommandList final
}
if (!any_nonempty_viewport()) return; // as record_draw: nothing is rasterized
leonida::Draw draw{graphics_pipeline_, graphics_user_data(), draw_views(), depth_, {}, 0, viewport_,
scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0};
scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_,
min_depth_bounds_, max_depth_bounds_, false, x, y, z, 0, 0};
note_direct_heap_indexing(graphics_.layout);
draw.mesh = true;
draw.viewports = draw_viewports();
Expand Down Expand Up @@ -938,6 +941,20 @@ class GraphicsCommandList final
check(list_.resolve_queries({query_heap_id(heap), u(type), first, count, resource_id(dst), offset}));
}

// GCL1. Dynamic depth-bounds range (default 0.0..1.0), allowed in bundles and accepting out-of-range/NaN at record
// time as D3D12 does (replayed cleanly inside Vulkan's 0..1 domain in vulkan_replay.h).
void STDMETHODCALLTYPE OMSetDepthBounds(FLOAT min, FLOAT max) override {
d3d12_trace::record("ID3D12GraphicsCommandList1::OMSetDepthBounds");
if (list_.closed()) return;
if (defer([=](GraphicsCommandList& l) {
l.min_depth_bounds_ = min;
l.max_depth_bounds_ = max;
}))
return;
min_depth_bounds_ = min;
max_depth_bounds_ = max;
}

// GCL8. Each draw applies the two faces with vkCmdSetStencilReference(VK_STENCIL_FACE_FRONT_BIT / BACK_BIT).
void STDMETHODCALLTYPE OMSetFrontAndBackStencilRef(UINT front, UINT back) override {
d3d12_trace::record("ID3D12GraphicsCommandList8::OMSetFrontAndBackStencilRef");
Expand Down Expand Up @@ -1552,6 +1569,8 @@ class GraphicsCommandList final
bool invalid_ = false;
UINT front_stencil_ref_ = 0;
UINT back_stencil_ref_ = 0;
float min_depth_bounds_ = 0.0f;
float max_depth_bounds_ = 1.0f;
RootState compute_;
RootState graphics_;
std::uintptr_t compute_pipeline_ = 0;
Expand Down Expand Up @@ -1681,6 +1700,8 @@ class GraphicsCommandList final

void reset_state(ID3D12PipelineState* state) {
front_stencil_ref_ = back_stencil_ref_ = 0;
min_depth_bounds_ = 0.0f;
max_depth_bounds_ = 1.0f;
compute_ = {};
graphics_ = {};
cbv_srv_uav_heap_ = nullptr;
Expand Down Expand Up @@ -2052,7 +2073,8 @@ class GraphicsCommandList final
void record_raster_draw(bool indexed, UINT count, UINT instances, UINT first, INT base_vertex, UINT first_instance,
const leonida::IndirectDrawArgs* indirect = nullptr) {
leonida::Draw draw{graphics_pipeline_, graphics_user_data(), draw_views(), depth_, index_, topology_, viewport_,
scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, indexed, count, instances,
scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_,
min_depth_bounds_, max_depth_bounds_, indexed, count, instances,
first, base_vertex, first_instance};
draw.viewports = draw_viewports();
const bool recorded = indirect ? list_.draw_indirect(std::move(draw), *indirect) : list_.draw(std::move(draw));
Expand Down Expand Up @@ -2807,6 +2829,14 @@ bool front_back_stencil_ref(ID3D12GraphicsCommandList8* list, UINT& front, UINT&
return true;
}

bool depth_bounds(ID3D12GraphicsCommandList1* list, float& min_depth, float& max_depth) {
const GraphicsCommandList* l = GraphicsCommandList::from(list);
if (!l) return false;
min_depth = l->min_depth_bounds();
max_depth = l->max_depth_bounds();
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 @@ -578,6 +578,9 @@ void set_global_realtime_privilege_override_for_test(int state);
// not one of this module's command lists.
bool front_back_stencil_ref(ID3D12GraphicsCommandList8* list, UINT& front, UINT& back);

// 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
50 changes: 37 additions & 13 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7691,7 +7691,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 @@ -7741,6 +7744,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 @@ -7784,13 +7788,18 @@ struct StencilFaceMasks {
UINT8 write = D3D12_DEFAULT_STENCIL_WRITE_MASK;
};

struct GraphicsStreamExtras {
bool depth_bounds_test = false;
};

struct PipelineStream {
D3D12_GRAPHICS_PIPELINE_STATE_DESC graphics{};
bool back_masks = false; // DEPTH_STENCIL2: back_stencil holds the back face's masks
StencilFaceMasks back_stencil;
D3D12_COMPUTE_PIPELINE_STATE_DESC compute{};
D3D12_SHADER_BYTECODE ms{};
D3D12_SHADER_BYTECODE as{};
GraphicsStreamExtras extras{};
bool has_cs = false;
bool has_graphics_stage = false; // VS, PS, DS, HS, GS, AS or MS
};
Expand Down Expand Up @@ -7931,9 +7940,7 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1: {
D3D12_DEPTH_STENCIL_DESC1 d{};
take(d);
if (ok && d.DepthBoundsTestEnable) {
return stream_unsupported("depth-bounds tests are not supported yet; stream subobject", int(type));
}
out.extras.depth_bounds_test = ok && (d.DepthBoundsTestEnable != FALSE);
g.DepthStencilState = {d.DepthEnable, d.DepthWriteMask, d.DepthFunc, d.StencilEnable, d.StencilReadMask,
d.StencilWriteMask, d.FrontFace, d.BackFace};
break;
Expand All @@ -7942,9 +7949,7 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe
D3D12_DEPTH_STENCIL_DESC2 d{};
take(d);
if (!ok) break;
if (d.DepthBoundsTestEnable) {
return stream_unsupported("depth-bounds tests are not supported yet; stream subobject", int(type));
}
out.extras.depth_bounds_test = d.DepthBoundsTestEnable != FALSE;
// Each face has its own read and write mask (OPTIONS14.IndependentFrontAndBackStencilRefMaskSupported):
// the description takes the front face's, back_stencil the back face's.
out.back_masks = true;
Expand Down Expand Up @@ -8142,7 +8147,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 @@ -8203,7 +8208,9 @@ class PipelineState final
if (seen.insert(line).second) std::fprintf(stderr, "%s\n", line);
}
HRESULT create_graphics(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc, const D3D12_SHADER_BYTECODE* ms = nullptr,
const D3D12_SHADER_BYTECODE* as = nullptr, const StencilFaceMasks* back_masks = nullptr) {
const D3D12_SHADER_BYTECODE* as = nullptr,
const StencilFaceMasks* back_masks = nullptr,
const GraphicsStreamExtras* extras = nullptr) {
auto& vk = device_.context->vk;
const VkDevice dev = device_.info.device;
const bool mesh = ms && ms->pShaderBytecode && ms->BytecodeLength;
Expand Down Expand Up @@ -8708,6 +8715,7 @@ class PipelineState final
depth.depthTestEnable = ds.DepthEnable;
depth.depthWriteEnable = ds.DepthEnable && ds.DepthWriteMask == D3D12_DEPTH_WRITE_MASK_ALL;
depth.depthCompareOp = compare_op(ds.DepthFunc);
depth.depthBoundsTestEnable = (extras && extras->depth_bounds_test) ? VK_TRUE : VK_FALSE;
depth.stencilTestEnable = ds.StencilEnable;
depth.front = stencil_face(ds.FrontFace, ds.StencilReadMask, ds.StencilWriteMask);
depth.back = back_masks ? stencil_face(ds.BackFace, back_masks->read, back_masks->write)
Expand Down Expand Up @@ -8779,6 +8787,8 @@ class PipelineState final
return stream_unsupported("logic ops need logicOp, which the device lacks; op", int(first.LogicOp));
if (raster.depthClampEnable && !features.depthClamp)
return stream_unsupported("DepthClipEnable = FALSE needs depthClamp, which the device lacks; flag", 0);
if (depth.depthBoundsTestEnable && !features.depthBounds)
return stream_unsupported("depth-bounds testing needs depthBounds, which the device lacks; enabled", 1);

graphics_.viewport_with_count =
features.multiViewport && vk.vkCmdSetViewportWithCount && vk.vkCmdSetScissorWithCount;
Expand Down Expand Up @@ -8878,6 +8888,7 @@ class PipelineState final

// Kept for variants: a draw that leaves a slot unbound needs this pipeline with that format undefined.
graphics_.mesh = mesh;
graphics_.depth_bounds_test = depth.depthBoundsTestEnable == VK_TRUE;
recipe_.mesh = mesh;
recipe_.stages = std::move(stage_infos);
recipe_.attributes = std::move(attributes);
Expand Down Expand Up @@ -9324,7 +9335,7 @@ class PipelineState final
// A mesh pipeline takes neither the topology nor the strides as dynamic state
// (VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-07065 and -07066).
// With multiViewport enabled, VIEWPORT_WITH_COUNT / SCISSOR_WITH_COUNT allow 1..16 dynamic viewports/scissors.
VkDynamicState dyn_list[8]{};
VkDynamicState dyn_list[9]{};
std::uint32_t dyn_count = 0;
dyn_list[dyn_count++] =
graphics_.viewport_with_count ? VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT : VK_DYNAMIC_STATE_VIEWPORT;
Expand All @@ -9336,6 +9347,7 @@ class PipelineState final
}
dyn_list[dyn_count++] = VK_DYNAMIC_STATE_STENCIL_REFERENCE;
dyn_list[dyn_count++] = VK_DYNAMIC_STATE_BLEND_CONSTANTS;
if (r.depth.depthBoundsTestEnable == VK_TRUE) dyn_list[dyn_count++] = VK_DYNAMIC_STATE_DEPTH_BOUNDS;
if (!r.mesh && !r.bindings.empty()) dyn_list[dyn_count++] = VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE;
VkPipelineDynamicStateCreateInfo dynamic{VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO};
dynamic.dynamicStateCount = dyn_count;
Expand Down Expand Up @@ -11638,7 +11650,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(!rt::d3d12_xs::attach_pso_record(pipeline,std::move(record))){pipeline->Release();return E_OUTOFMEMORY;}
pipeline->set_pending_stream(stream.has_cs);
return hand_out(pipeline,iid,out);
Expand Down Expand Up @@ -13721,7 +13743,8 @@ class Device final
pipeline->attach_device(identity());
const HRESULT hr = stream.has_cs ? pipeline->create_compute(stream.compute)
: pipeline->create_graphics(stream.graphics, &stream.ms, &stream.as,
stream.back_masks ? &stream.back_stencil : nullptr);
stream.back_masks ? &stream.back_stencil : nullptr,
&stream.extras);
if (FAILED(hr)) {
pipeline->Release();
return finish(hr);
Expand Down Expand Up @@ -15513,7 +15536,7 @@ class Device final
if (size != sizeof(D3D12_FEATURE_DATA_D3D12_OPTIONS2)) return d3d12_trace::result(method, E_INVALIDARG);
auto* opts = static_cast<D3D12_FEATURE_DATA_D3D12_OPTIONS2*>(data);
*opts = {};
opts->DepthBoundsTestSupported = FALSE;
opts->DepthBoundsTestSupported = state_.info.features.depthBounds ? TRUE : FALSE;
opts->ProgrammableSamplePositionsTier = D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_NOT_SUPPORTED;
return d3d12_trace::result(method, S_OK);
}
Expand Down Expand Up @@ -18125,6 +18148,7 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
enable.logicOp = chosen_features.logicOp;
enable.depthClamp = chosen_features.depthClamp;
enable.multiViewport = chosen_features.multiViewport;
enable.depthBounds = chosen_features.depthBounds;
enable.geometryShader = chosen_features.geometryShader; // translated geometry shaders (195 in the corpus)
// What translated shaders declare (the index's `features`): 64-bit integers in most of the corpus (25,803 of
// 26,503 entries), doubles, 16-bit integers, clip and cull distances in a few vertex shaders, formatless image
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/command_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ struct Draw {
std::array<float, 4> blend_factor{1, 1, 1, 1};
std::uint32_t stencil_front = 0;
std::uint32_t stencil_back = 0;
float min_depth_bounds = 0.0f;
float max_depth_bounds = 1.0f;
bool indexed = false;
std::uint32_t count = 0; // vertices or indices per instance
std::uint32_t instances = 0;
Expand Down
3 changes: 2 additions & 1 deletion runtime/src/vulkan_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct VulkanDeviceFunctions {
X(vkCmdBindVertexBuffers2) X(vkCmdBindIndexBuffer) X(vkCmdSetViewport) X(vkCmdSetScissor) \
X(vkCmdSetViewportWithCount) X(vkCmdSetScissorWithCount) \
X(vkCmdSetPrimitiveTopology) X(vkCmdSetPrimitiveRestartEnable) X(vkCmdSetStencilReference) \
X(vkCmdSetBlendConstants) X(vkCmdDraw) \
X(vkCmdSetDepthBounds) X(vkCmdSetBlendConstants) X(vkCmdDraw) \
X(vkCmdDrawIndexed) X(vkCreateGraphicsPipelines) X(vkQueueBindSparse) X(vkGetImageSparseMemoryRequirements) \
X(vkCreatePipelineCache) X(vkDestroyPipelineCache) X(vkGetPipelineCacheData) X(vkMergePipelineCaches) \
X(vkCreateEvent) X(vkDestroyEvent) X(vkResetEvent) X(vkCmdSetEvent) X(vkCmdWaitEvents) X(vkCmdDrawMeshTasksEXT) \
Expand Down Expand Up @@ -1147,6 +1147,7 @@ class VulkanContext {
replay_.set_primitive_topology = vk.vkCmdSetPrimitiveTopology;
replay_.set_primitive_restart_enable = vk.vkCmdSetPrimitiveRestartEnable;
replay_.set_stencil_reference = vk.vkCmdSetStencilReference;
replay_.set_depth_bounds = vk.vkCmdSetDepthBounds;
replay_.set_blend_constants = vk.vkCmdSetBlendConstants;
replay_.draw = vk.vkCmdDraw;
replay_.draw_mesh_tasks = vk.vkCmdDrawMeshTasksEXT; // null unless VK_EXT_mesh_shader is enabled
Expand Down
Loading