diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 6df6657bdf..1e34399d57 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -954,7 +954,8 @@ The compute path, end to end: primitive overestimation no greater than `0.5 - 1/512` pixels, leaving half a minimum grid step within the Tier 1 uncertainty bound. `ConservativeRaster=ON` uses overestimate mode with zero extra overestimation, including unbound-attachment variants. OFF keeps the ordinary pipeline. Missing support, unknown modes, - wireframe and non-triangle PSOs are refused; conservative TIR (`ForcedSampleCount != 0`) remains `E_NOTIMPL`. + wireframe and non-triangle PSOs are refused (a mesh PSO needs no topology type: its module has to output + triangles, `conservative_raster::mesh_outputs_triangles`); conservative TIR (`ForcedSampleCount != 0`) remains `E_NOTIMPL`. Tier 2 additionally requires `degenerateTrianglesRasterized` and primitive overestimation plus half a device subpixel step no greater than 1/256 pixel. Other eligible devices retain Tier 1. The standalone device does not expose Tier 3: the Xbox `SV_InnerCoverage` input mapping has not been confirmed. See diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 36f3556090..5809fb8aa1 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -8689,8 +8689,11 @@ class PipelineState final log_once("conservative rasterization needs enabled VK_EXT_conservative_rasterization and Tier 1 precision", 1); return E_INVALIDARG; } - if (r.FillMode != D3D12_FILL_MODE_SOLID || - topology_type != D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE) return E_INVALIDARG; + // A mesh pipeline has no input assembler, so its stream need not set the topology type: what is rasterized + // is the module's output, and it has to be triangles as well. + if (r.FillMode != D3D12_FILL_MODE_SOLID) return E_INVALIDARG; + if (mesh ? !leonida::conservative_raster::mesh_outputs_triangles(stages[0].words) + : topology_type != D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE) return E_INVALIDARG; // Target-independent rasterization is a separate pipeline path; do not silently ignore its count. if (r.ForcedSampleCount) return stream_unsupported("target-independent rasterization; forced sample count", int(r.ForcedSampleCount)); diff --git a/runtime/src/conservative_raster.h b/runtime/src/conservative_raster.h index 469066d17f..82d6dfaca1 100644 --- a/runtime/src/conservative_raster.h +++ b/runtime/src/conservative_raster.h @@ -46,4 +46,21 @@ inline InnerCoverageRequirements inner_coverage_requirements(std::span words) { + if (words.size() < 5 || words[0] != 0x07230203) return false; + bool triangles = false; + for (std::size_t i = 5; i < words.size();) { + const auto count = words[i] >> 16, op = words[i] & 0xffff; + if (!count || count > words.size() - i) return false; + if (op == 16 && count >= 3) { // OpExecutionMode + if (words[i + 2] == 5298) triangles = true; + else if (words[i + 2] == 5269 || words[i + 2] == 27) return false; + } + i += count; + } + return triangles; +} } // namespace leonida::conservative_raster diff --git a/runtime/test/conservative_raster_test.cpp b/runtime/test/conservative_raster_test.cpp index b862e5fcba..72ee4d5163 100644 --- a/runtime/test/conservative_raster_test.cpp +++ b/runtime/test/conservative_raster_test.cpp @@ -1,6 +1,7 @@ #include "../src/conservative_raster.h" #include #include +#include int main() { using leonida::conservative_raster::tier1; @@ -38,6 +39,18 @@ int main() { const auto requirements = inner_coverage_requirements(module); check(requirements.valid && requirements.fully_covered && requirements.post_depth); check(!inner_coverage_requirements(std::span(module).first(9)).valid); + using leonida::conservative_raster::mesh_outputs_triangles; + const auto with_mode = [](std::uint32_t mode) { + return std::vector{0x07230203, 0x00010500, 0, 2, 0, (3u << 16) | 16, 1, mode}; + }; + check(mesh_outputs_triangles(with_mode(5298))); // OutputTrianglesEXT + check(!mesh_outputs_triangles(with_mode(5269))); // OutputLinesEXT + check(!mesh_outputs_triangles(with_mode(27))); // OutputPoints + check(!mesh_outputs_triangles(with_mode(26))); // OutputVertices: no output topology + check(!mesh_outputs_triangles({})); + auto truncated = with_mode(5298); + truncated.pop_back(); + check(!mesh_outputs_triangles(truncated)); const std::uint32_t zero_count[] = {0x07230203, 0x00010500, 0, 2, 0, 0}; check(!inner_coverage_requirements(zero_count).valid); const std::uint32_t ordinary[] = {0x07230203, 0x00010500, 0, 2, 0, (2u << 16) | 17, 1}; diff --git a/runtime/test/d3d12_mesh_test.cpp b/runtime/test/d3d12_mesh_test.cpp index 2d9bc5212e..802e67d62d 100644 --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp @@ -160,6 +160,7 @@ int main(int argc, char** argv) { info.mesh_shader = mesh; info.mesh_shader_queries = mesh && d.mesh_shader_queries; info.pipeline_statistics_query = d.pipeline_statistics_query; + info.conservative_rasterization = d.conservative_rasterization; return info; }; const auto make_device = [&](bool mesh, Ref& device) { @@ -252,6 +253,34 @@ int main(int argc, char** argv) { vs_stream.add(TopologySubobject{.inner = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE}); vs_stream.add(TargetsSubobject{.inner = one_target()}); EXPECT(SUCCEEDED(create(device.p, vs_stream, vs_pso))); + // Conservative rasterization in a mesh pipeline: its stream has no input assembler, so it need not name a topology + // type. A vertex pipeline without TRIANGLE is still refused, as is a wireframe mesh one. + { + D3D12_FEATURE_DATA_D3D12_OPTIONS options{}; + EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof options))); + if (options.ConservativeRasterizationTier != D3D12_CONSERVATIVE_RASTERIZATION_TIER_NOT_SUPPORTED) { + std::printf("conservative rasterization tier %d: mesh pipelines checked\n", int(options.ConservativeRasterizationTier)); + D3D12_RASTERIZER_DESC conservative{}; + conservative.FillMode = D3D12_FILL_MODE_SOLID; + conservative.CullMode = D3D12_CULL_MODE_NONE; + conservative.DepthClipEnable = TRUE; + conservative.ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_ON; + Ref made; + Stream conservative_mesh = mesh_stream; + conservative_mesh.add(RasterizerSubobject{.inner = conservative}); + EXPECT(SUCCEEDED(create(device.p, conservative_mesh, made)) && made.p); + conservative.FillMode = D3D12_FILL_MODE_WIREFRAME; + Stream wireframe_mesh = mesh_stream; + wireframe_mesh.add(RasterizerSubobject{.inner = conservative}); + EXPECT(create(device.p, wireframe_mesh, refused) == E_INVALIDARG && !refused.p); + conservative.FillMode = D3D12_FILL_MODE_SOLID; + Stream no_topology_vs; + no_topology_vs.add(RootSubobject{.inner = root.p}).add(VsSubobject{.inner = vs}).add(PsSubobject{.inner = ps}); + no_topology_vs.add(TargetsSubobject{.inner = one_target()}); + no_topology_vs.add(RasterizerSubobject{.inner = conservative}); + EXPECT(create(device.p, no_topology_vs, refused) == E_INVALIDARG && !refused.p); + } + } // A mesh shader translated before the graphics root window would read its root arguments from the wrong // dwords: refused, with a log line that asks for the shaders stage again. {