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
4 changes: 4 additions & 0 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ struct VulkanDeviceInfo {
// VK_EXT_conservative_rasterization is enabled on the logical device. Tier 1/2 depend on the physical
// precision/overestimation properties; Tier 2 also requires post-snap degenerate triangles.
bool conservative_rasterization = false;
// VK_EXT_line_rasterization features enabled on the logical device.
bool line_bresenham = false;
bool line_smooth = false;
bool line_rectangular = false;
// Opt in only for shader libraries whose InnerCoverage input contract uses FullyCoveredEXT. The device
// still checks physical Tier 2 and fullyCoveredFragmentShaderInputVariable properties. The standalone
// device leaves this false until the Xbox PS input mapping is confirmed (synthetic GLSL is not that ABI).
Expand Down
61 changes: 58 additions & 3 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6640,7 +6640,9 @@ 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) {
leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc, int line_mode = -1,
const D3D12_SHADER_BYTECODE* ms = nullptr,
const D3D12_SHADER_BYTECODE* as = nullptr) {
leonida::cached_pso::KeyBuilder key;
key.tag("graphics");
key_root_signature(key, desc.pRootSignature);
Expand All @@ -6649,6 +6651,8 @@ leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC&
key_shader(key, "ds", desc.DS);
key_shader(key, "hs", desc.HS);
key_shader(key, "gs", desc.GS);
if (ms && ms->BytecodeLength) key_shader(key, "ms", *ms);
if (as && as->BytecodeLength) key_shader(key, "as", *as);
const D3D12_STREAM_OUTPUT_DESC& so = desc.StreamOutput;
key.u32(so.pSODeclaration ? so.NumEntries : 0);
for (UINT i = 0; so.pSODeclaration && i < so.NumEntries; ++i) {
Expand All @@ -6672,6 +6676,7 @@ leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC&
key.u32(r.FillMode).u32(r.CullMode).u32(r.FrontCounterClockwise).u32(std::uint32_t(r.DepthBias)).u32(bias_clamp);
key.u32(slope).u32(r.DepthClipEnable).u32(r.MultisampleEnable).u32(r.AntialiasedLineEnable);
key.u32(r.ForcedSampleCount).u32(r.ConservativeRaster);
if (line_mode >= 0) key.tag("line_rasterization_mode").u32(std::uint32_t(line_mode));
const D3D12_DEPTH_STENCIL_DESC& d = desc.DepthStencilState;
key.u32(d.DepthEnable).u32(d.DepthWriteMask).u32(d.DepthFunc).u32(d.StencilEnable).u32(d.StencilReadMask);
key.u32(d.StencilWriteMask);
Expand Down Expand Up @@ -6740,6 +6745,7 @@ struct PipelineStream {
D3D12_COMPUTE_PIPELINE_STATE_DESC compute{};
D3D12_SHADER_BYTECODE ms{};
D3D12_SHADER_BYTECODE as{};
int line_mode = -1; // Only RASTERIZER2 has an explicit line mode.
bool has_cs = false;
bool has_graphics_stage = false; // VS, PS, DS, HS, GS, AS or MS
};
Expand Down Expand Up @@ -6924,6 +6930,7 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe
r = {d.FillMode, d.CullMode, d.FrontCounterClockwise, 0, d.DepthBiasClamp, d.SlopeScaledDepthBias,
d.DepthClipEnable, FALSE, FALSE, d.ForcedSampleCount, d.ConservativeRaster};
bias = d.DepthBias;
out.line_mode = int(d.LineRasterizationMode);
}
r.DepthBias = INT(bias);
if (ok && FLOAT(r.DepthBias) != bias) log_once("a fractional depth bias is truncated; bias x1000", int(bias * 1000));
Expand Down Expand Up @@ -7116,7 +7123,8 @@ 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,
int line_mode = -1) {
auto& vk = device_.context->vk;
const VkDevice dev = device_.info.device;
const bool mesh = ms && ms->pShaderBytecode && ms->BytecodeLength;
Expand Down Expand Up @@ -7772,6 +7780,7 @@ class PipelineState final
recipe_.assembly = assembly;
recipe_.raster = raster;
recipe_.conservative = r.ConservativeRaster == D3D12_CONSERVATIVE_RASTERIZATION_MODE_ON;
recipe_.line_mode = line_mode;
recipe_.multisample = multisample;
graphics_.samples = samples;
recipe_.sample_mask = sample_mask;
Expand Down Expand Up @@ -8136,6 +8145,7 @@ class PipelineState final
VkPipelineInputAssemblyStateCreateInfo assembly{};
VkPipelineRasterizationStateCreateInfo raster{};
bool conservative = false;
int line_mode = -1;
VkPipelineMultisampleStateCreateInfo multisample{};
VkSampleMask sample_mask = ~0u;
VkPipelineDepthStencilStateCreateInfo depth{};
Expand Down Expand Up @@ -8187,6 +8197,29 @@ class PipelineState final
conservative.pNext = raster.pNext;
raster.pNext = &conservative;
}
VkPipelineRasterizationLineStateCreateInfoEXT line{VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT};
// Vulkan has no narrow quadrilateral mode; rectangular is the closest available approximation. Both
// QUADRILATERAL_WIDE and QUADRILATERAL_NARROW therefore become a rectangular line of the default width 1,
// so WIDE is not wider than NARROW here.
bool use_line = false;
switch (r.line_mode) {
case D3D12_LINE_RASTERIZATION_MODE_ALIASED:
line.lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
use_line = device_.info.line_bresenham && !multisample.alphaToCoverageEnable; break;
case D3D12_LINE_RASTERIZATION_MODE_ALPHA_ANTIALIASED:
line.lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
use_line = device_.info.line_smooth && !multisample.alphaToCoverageEnable; break;
case D3D12_LINE_RASTERIZATION_MODE_QUADRILATERAL_WIDE:
case D3D12_LINE_RASTERIZATION_MODE_QUADRILATERAL_NARROW:
line.lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
use_line = device_.info.line_rectangular; break;
default: break;
}
if (use_line) {
line.stippledLineEnable = VK_FALSE;
line.pNext = raster.pNext;
raster.pNext = &line;
}
multisample.pSampleMask = &r.sample_mask;
VkPipelineColorBlendStateCreateInfo blend = r.blend;
blend.attachmentCount = std::uint32_t(r.blends.size());
Expand Down Expand Up @@ -12094,11 +12127,14 @@ 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.line_mode);
if (FAILED(hr)) {
pipeline->Release();
return finish(hr);
}
if (!stream.has_cs && stream.line_mode >= 0)
pipeline->set_cache_key(pipeline_key(stream.graphics, stream.line_mode, &stream.ms, &stream.as));
const HRESULT result = hand_out(pipeline, riid, out);
if (SUCCEEDED(result) && stream.ms.pShaderBytecode) d3d12_trace::record("PipelineStream::Mesh", "accepted");
return finish(result);
Expand Down Expand Up @@ -16186,6 +16222,24 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
info.conservative_rasterization = std::any_of(extensions.begin(), extensions.end(), [](const auto& e) {
return std::strcmp(e.extensionName, VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME) == 0;
});
const bool has_line_rasterization = std::any_of(extensions.begin(), extensions.end(), [](const auto& e) {
return std::strcmp(e.extensionName, VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME) == 0;
});
VkPhysicalDeviceLineRasterizationFeaturesEXT line_features{
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT};
if (has_line_rasterization) {
VkPhysicalDeviceFeatures2 query{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &line_features};
vkGetPhysicalDeviceFeatures2(info.physical, &query);
info.line_bresenham = line_features.bresenhamLines == VK_TRUE;
info.line_smooth = line_features.smoothLines == VK_TRUE;
info.line_rectangular = line_features.rectangularLines == VK_TRUE;
// Stippled lines are not used by this layer.
line_features.stippledRectangularLines = VK_FALSE;
line_features.stippledBresenhamLines = VK_FALSE;
line_features.stippledSmoothLines = VK_FALSE;
line_features.pNext = *v13.next();
*v13.next() = &line_features;
}
const bool has_host_image_copy = std::any_of(extensions.begin(), extensions.end(), [](const auto& e) {
return std::strcmp(e.extensionName, VK_EXT_HOST_IMAGE_COPY_EXTENSION_NAME) == 0;
});
Expand Down Expand Up @@ -16483,6 +16537,7 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
if (trace_pipeline_compile() && !v13.core && info.pipeline_creation_feedback)
device_extensions.push_back(VK_EXT_PIPELINE_CREATION_FEEDBACK_EXTENSION_NAME);
if (info.conservative_rasterization) device_extensions.push_back(VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME);
if (has_line_rasterization) device_extensions.push_back(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
if (info.image_view_min_lod) device_extensions.push_back(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME);
if (info.vertex_attribute_divisor) device_extensions.push_back(divisor_extension);
if (info.conditional_rendering) device_extensions.push_back(conditional_extension);
Expand Down
Loading
Loading