// Tier 2: tight uncertainty, exact and post-snap degenerates. RGB independently encodes varying colour, // constant depth and facing. No game data. #include "conservative_raster_fixture.h" using namespace conservative_test; namespace { double cross(const Triangle& t) { return (t[1].x-t[0].x)*(t[2].y-t[0].y) - (t[1].y-t[0].y)*(t[2].x-t[0].x); } bool tight_coverage(const Triangle& original, const Triangle* snapped, const D3D12_RECT& scissor, const Mask& mask, bool log = true) { constexpr double epsilon = 1e-7, uncertainty = 1.0 / 256; unsigned required_count = 0, covered = 0; for (UINT y=0;y=scissor.left && LONG(x)=scissor.top && LONG(y) 1e-12); area(original,x-uncertainty-epsilon,y-uncertainty-epsilon, x+1+uncertainty+epsilon,y+1+uncertainty+epsilon,&hits); const bool allowed = in && hits; if ((required && !mask[y*width+x]) || (!allowed && mask[y*width+x])) { if (log) std::fprintf(stderr,"Tier 2 coverage (%u,%u): required=%d allowed=%d actual=%d\n", x,y,int(required),int(allowed),int(mask[y*width+x])); return false; } required_count += unsigned(required); covered += unsigned(mask[y*width+x]); } // A snapped point on a pixel corner has no required open-pixel intersection, but must cover at least one // adjacent pixel. Its particular edge/corner tie-breaking is not asserted. if (snapped && !required_count && !covered && log) std::fprintf(stderr,"snapped corner produced no fragments\n"); return !snapped || required_count || covered; } VertexInput vertices(const std::vector& points, std::vector indices, D3D_PRIMITIVE_TOPOLOGY topology) { // Keep depth planar: native D3D12 and Vulkan may extrapolate SV_Position.z for screen-space degenerates. static constexpr float depths[] = {0.375f,0.375f,0.375f,0.375f}; static constexpr float markers[] = {0.25f,0.75f,0.375f,0.875f}; VertexInput out; out.indices=std::move(indices); out.topology=topology; for (std::size_t i=0;i& rgba, unsigned provoking) { static constexpr std::array expected[] = { {64,96,0,255},{191,96,0,255},{96,96,0,255},{223,96,0,255}}; for (unsigned i=0;i1e-12; CHECK(tight_coverage(triangle,nullptr,full,mask)); mask[8*width+7]=true; // within Tier 1's half-pixel margin, outside Tier 2's 1/256 margin CHECK(coverage(triangle,full,mask)); CHECK(!tight_coverage(triangle,nullptr,full,mask,false)); return true; } } // namespace int main(int argc, char** argv) { const bool warp_corner = argc > 1 && std::strcmp(argv[1], "--warp-corner") == 0; if (!oracle_control()) return 1; if (hostwine::host_is_wine()) return 77; vktest::Device vk; vk.request_buffer_device_address=true; const auto status=vk.initialize(); if(status==vktest::DeviceStatus::unavailable)return 77; if(status!=vktest::DeviceStatus::ready)return 1; VkPhysicalDeviceConservativeRasterizationPropertiesEXT cr{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT}; VkPhysicalDeviceProperties2 properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; if(vk.conservative_rasterization)properties.pNext=&cr; reinterpret_cast(vk.instance_proc(vk.instance,"vkGetPhysicalDeviceProperties2"))(vk.physical,&properties); const auto tier=leonida::conservative_raster::tier(vk.conservative_rasterization, properties.properties.limits.subPixelPrecisionBits,cr.primitiveOverestimationSize,cr.degenerateTrianglesRasterized==VK_TRUE); if(!vk.buffer_device_address||properties.properties.limits.maxPushConstantsSize<144)return 77; const auto vs_program=d3d12test::fssm_program({0x54325653,0xbf810000}); const auto ps_program=d3d12test::fssm_program({0x54325053,0xbf810000}); const auto vs_bytes=d3d12test::shader_container(vs_program),ps_bytes=d3d12test::shader_container(ps_program); const auto directory=std::filesystem::temp_directory_path()/("leonida_conservative_tier2_"+std::to_string(GetCurrentProcessId())); std::filesystem::create_directories(directory); std::filesystem::copy_file(LEONIDA_CONSERVATIVE_TIER2_VS,directory/"vs.spv",std::filesystem::copy_options::overwrite_existing); std::filesystem::copy_file(LEONIDA_CONSERVATIVE_TIER2_PS,directory/"ps.spv",std::filesystem::copy_options::overwrite_existing); { std::ofstream index(directory/"index.json",std::ios::binary); index<<"{\"vs\":{\"stage\":\"vs\",\"fssm_sha256\":\""< ours,host; if(FAILED(rt::d3d12::create_vulkan_device(info,IID_PPV_ARGS(&ours.p))))return 1; D3D12_FEATURE_DATA_D3D12_OPTIONS options{}; if(FAILED(ours->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS,&options,sizeof(options)))||unsigned(options.ConservativeRasterizationTier)!=tier)return 1; if(tier<2){std::puts("SKIP: device does not meet conservative raster Tier 2 requirements");return 77;} std::string adapter;if(!copycmp::create_host(host,adapter))return 1; if(FAILED(host->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS,&options,sizeof(options))))return 1; if(options.ConservativeRasterizationTier(reinterpret_cast(GetProcAddress(compiler,"D3DCompile"))):nullptr; if(!compile)return 77; const char* hlsl="struct O{float4 p:SV_Position;float m:COLOR;}; O vs(float3 p:POSITION,float m:COLOR){O o;o.p=float4(p,1);o.m=m;return o;} float4 ps(O o,bool front:SV_IsFrontFace):SV_Target{return float4(o.m,o.p.z,front?1:0,1);}"; copycmp::Ptr vs,ps,error; if(FAILED(compile(hlsl,std::strlen(hlsl),nullptr,nullptr,nullptr,"vs","vs_5_0",0,0,&vs.p,&error.p))|| FAILED(compile(hlsl,std::strlen(hlsl),nullptr,nullptr,nullptr,"ps","ps_5_0",0,0,&ps.p,nullptr)))return 1; Fixture a,b; if(!setup(a,ours.p,true,{vs_bytes.data(),vs_bytes.size()},{ps_bytes.data(),ps_bytes.size()})|| !setup(b,host.p,false,{vs->GetBufferPointer(),vs->GetBufferSize()},{ps->GetBufferPointer(),ps->GetBufferSize()}))return 1; const D3D12_INPUT_ELEMENT_DESC elements[]={ {"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA,0}, {"COLOR",0,DXGI_FORMAT_R32_FLOAT,0,12,D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA,0}}; a.input=b.input=elements; const D3D12_RECT full{0,0,32,32},inset{8,8,24,24}; unsigned tight_cases=0,degenerate_cases=0; const Triangle tight_scenes[]={ {{{8.015625,4.25},{9.25,4.25},{8.015625,24.25}}}, {{{3.125,8.001953125},{28.125,8.005859375},{3.125,9.125}}}, {{{3.125,3.125},{28.125,28.125},{3.125,3.140625}}}, {{{-0.125,8.125},{12.125,8.125},{8.125,28.125}}}, }; for(auto* fixture:{&a,&b})for(const auto& triangle:tight_scenes)for(const auto scissor:{full,inset}) { Mask mask{};std::vector rgba; const auto input=vertices(std::vector(triangle.begin(),triangle.end()),{0,1,2},D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); if(!render(*fixture,triangle,true,1,false,scissor,mask,D3D12_CULL_MODE_NONE,&input,&rgba)|| !tight_coverage(triangle,nullptr,scissor,mask))return 1; ++tight_cases; } constexpr double delta=1.0/(1u<<20); const std::vector> collapsed={ {{16.125,16.125},{16.125+delta,16.125},{16.125,16.125+delta}}, {{4.125,16.125},{24.125,16.125},{4.125,16.125+delta}}, {{4.125,4.125},{24.125,24.125},{4.125,4.125+delta}}, {{16,16},{16+delta,16},{16,16+delta}}, {{4.125,16.125},{24.125,16.125},{12.125,16.125}}, {{16.125,16.125},{16.125,16.125},{16.125,16.125}}, {{16.125,16.125},{16.125+delta,16.125},{16.125,16.125+delta},{16.125+delta,16.125+delta}}, }; for(auto* fixture:{&a,&b})for(const auto& points:collapsed) for(const auto scissor:{full,inset})for(const bool variant:{false,true}) { std::vector> orders=points.size()==4 ?std::vector>{{0,1,2,3},{3,2,1,0}} :std::vector>{{0,1,2},{2,1,0},{1,2,0}}; // WARP drops the exact pixel-corner fixture; retain a strict opt-in reproducer. if (!fixture->run.ours && adapter.find("Microsoft Basic") != std::string::npos && points[0].x == 16 && !warp_corner) { std::puts("WARP reference: corner fixture excluded (use --warp-corner to reproduce); Vulkan still checks it"); continue; } for(const auto& order:orders) { const bool strip=points.size()==4; const auto input=vertices(points,order,strip?D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP:D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); const auto triangle=actual_triangle(input); const auto snapped=quantized(triangle,properties.properties.limits.subPixelPrecisionBits); const bool must_have_area = points.size() == 4 || points[2].y != points[0].y; if (cross(snapped) != 0 || (must_have_area && cross(triangle) == 0)) { std::fprintf(stderr,"fixture lost its intended pre/post-snap area\n"); return 1; } for(const auto cull:{D3D12_CULL_MODE_NONE,D3D12_CULL_MODE_FRONT,D3D12_CULL_MODE_BACK}) { Mask mask{};std::vector rgba; if(!render(*fixture,triangle,true,1,variant,scissor,mask,cull,&input,&rgba))return 1; if(cull==D3D12_CULL_MODE_BACK) { if(std::any_of(mask.begin(),mask.end(),[](bool x){return x;})){std::fprintf(stderr,"post-snap degenerate was not back-facing\n");return 1;} } else if(!tight_coverage(triangle,&snapped,scissor,mask)||!attributes(mask,rgba,order[strip?1:0])) { std::fprintf(stderr,"%s degenerate points=%zu first=%u strip=%d cull=%u\n", fixture->run.ours?"Vulkan":adapter.c_str(),points.size(),order[0],int(strip),unsigned(cull)); std::fprintf(stderr,"point=(%.9f,%.9f) scissor=%ld variant=%d\n",points[0].x,points[0].y,scissor.left,int(variant));return 1; } ++degenerate_cases; } } } std::printf("Tier 2: %u tight-bound scenes and %u degenerate draw cases across Vulkan and %s; colour/constant-depth/facing, index permutations, strips, culling, scissor and variants checked\n", tight_cases,degenerate_cases,adapter.c_str()); return vk.validation_errors()?1:0; }