Skip to content
Merged
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
3 changes: 2 additions & 1 deletion docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
17 changes: 17 additions & 0 deletions runtime/src/conservative_raster.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ inline InnerCoverageRequirements inner_coverage_requirements(std::span<const std
result.valid = true;
return result;
}

// True when the mesh shader module outputs triangles (OutputTrianglesEXT, 5298). A module with lines (5269), points (27)
// or no output mode does not. Each mesh entry point of a valid module has exactly one of the three.
inline bool mesh_outputs_triangles(std::span<const std::uint32_t> 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
13 changes: 13 additions & 0 deletions runtime/test/conservative_raster_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../src/conservative_raster.h"
#include <cstdio>
#include <limits>
#include <vector>

int main() {
using leonida::conservative_raster::tier1;
Expand Down Expand Up @@ -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<std::uint32_t>{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};
Expand Down
29 changes: 29 additions & 0 deletions runtime/test/d3d12_mesh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ID3D12Device>& device) {
Expand Down Expand Up @@ -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<ID3D12PipelineState> 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.
{
Expand Down
Loading