// Explicit FullyCoveredEXT library contract versus native SV_InnerCoverage. Synthetic data only. #include "conservative_raster_fixture.h" using namespace conservative_test; namespace { double cross(Point a, Point b, Point p) { return (b.x-a.x)*(p.y-a.y)-(b.y-a.y)*(p.x-a.x); } // Same geometric construction as #3970. The conservative margin avoids implementation-dependent edge pixels. bool inside(const Triangle& t, UINT x, UINT y, double margin) { const double winding = cross(t[0],t[1],t[2]); if (std::abs(winding)<1e-12) return false; const double sign = winding>0 ? 1.0 : -1.0; const Point corners[]={{double(x),double(y)},{double(x+1),double(y)}, {double(x),double(y+1)},{double(x+1),double(y+1)}}; for (unsigned i=0;i<3;++i) { const Point a=t[i], b=t[(i+1)%3]; const double length=std::hypot(b.x-a.x,b.y-a.y); if (!length) return false; for (const auto p:corners) if (sign*cross(a,b,p)/length<=margin) return false; } return true; } bool oracle(const Triangle& t, const D3D12_RECT& scissor, const Mask& mask, const std::vector& rgba, bool log=true) { for (UINT y=0;y=scissor.left && LONG(x)=scissor.top && LONG(y) rgba(width*height*4); for (UINT y=0;y device; CHECK(SUCCEEDED(rt::d3d12::create_vulkan_device(info,IID_PPV_ARGS(&device.p)))); D3D12_FEATURE_DATA_D3D12_OPTIONS options{}; CHECK(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS,&options,sizeof(options)))); CHECK(unsigned(options.ConservativeRasterizationTier)==expected_tier); Fixture fixture; CHECK(setup(fixture,device.p,true,vs,ps)); for (const bool conservative:{false,true}) { auto desc=description(fixture,conservative,1,false); copycmp::Ptr pso; CHECK(device->CreateGraphicsPipelineState(&desc,IID_PPV_ARGS(&pso.p))==E_NOTIMPL); CHECK(!pso.p); } return true; } } // namespace int main(int argc, char** argv) { if (!oracle_controls()) return 1; if (argc>1 && std::strcmp(argv[1],"--oracle-only")==0) return 0; const bool guards_only=argc>1 && std::strcmp(argv[1],"--guards-only")==0; const bool native_only=argc>1 && std::strcmp(argv[1],"--native-only")==0; 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}; VkPhysicalDeviceIDProperties id{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES}; id.pNext=vk.conservative_rasterization?&cr:nullptr; VkPhysicalDeviceProperties2 properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,&id}; const auto get_properties=reinterpret_cast(vk.instance_proc(vk.instance,"vkGetPhysicalDeviceProperties2")); if (!get_properties) return 1; get_properties(vk.physical,&properties); if (!vk.buffer_device_address || properties.properties.limits.maxPushConstantsSize<144) return 77; const auto vs_program=d3d12test::fssm_program({0x54335653,0xbf810000}); const auto ps_program=d3d12test::fssm_program({0x54335053,0xbf810000}); const auto vs_bytes=d3d12test::shader_container(vs_program), ps_bytes=d3d12test::shader_container(ps_program); const auto dir=std::filesystem::temp_directory_path()/("leonida_conservative_tier3_"+std::to_string(GetCurrentProcessId())); std::filesystem::create_directories(dir); std::filesystem::copy_file(LEONIDA_CONSERVATIVE_VS,dir/"vs.spv",std::filesystem::copy_options::overwrite_existing); std::filesystem::copy_file(LEONIDA_CONSERVATIVE_TIER3_PS,dir/"ps.spv",std::filesystem::copy_options::overwrite_existing); { // Omit optional capability metadata deliberately: the actual SPIR-V must enforce the unsupported guard. std::ofstream out(dir/"index.json",std::ios::binary); out<<"{\"vs\":{\"stage\":\"vs\",\"fssm_sha256\":\""< host,ours; std::string adapter; if (!copycmp::try_create_host(host,adapter,&luid)) return 77; D3D12_FEATURE_DATA_D3D12_OPTIONS options{}; if (FAILED(host->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS,&options,sizeof(options)))) return 1; if (options.ConservativeRasterizationTier(reinterpret_cast(GetProcAddress(dll,"D3DCompile"))):nullptr; if (!compile) return 77; const char* hlsl="float4 vs(float2 p:POSITION):SV_Position{return float4(p,0.5,1);}" "float4 ps(uint inner:SV_InnerCoverage):SV_Target0{return float4(1,(inner&1u)?1:0,inner==0u?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 (!native_only) { if (FAILED(rt::d3d12::create_vulkan_device(info,IID_PPV_ARGS(&ours.p)))) return 1; if (FAILED(ours->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS,&options,sizeof(options))) || options.ConservativeRasterizationTier!=D3D12_CONSERVATIVE_RASTERIZATION_TIER_3) return 1; if (!setup(a,ours.p,true,vs_code,ps_code)) return 1; } if (!setup(b,host.p,false,{vs->GetBufferPointer(),vs->GetBufferSize()},{ps->GetBufferPointer(),ps->GetBufferSize()})) return 1; const Triangle scenes[]={ {{{3.125,3.125},{28.125,3.125},{3.125,28.125}}}, {{{3.125,6.125},{27.125,11.125},{8.125,28.125}}}, {{{4.125,24.125},{27.125,6.125},{27.125,25.125}}}, {{{3.125,8.125},{28.125,8.625},{16.125,25.125}}}, {{{3.0625,3.0625},{3.3125,3.0625},{3.0625,3.3125}}}, {{{4.125,16.125},{24.125,16.125},{12.125,16.125}}}, }; unsigned comparisons=0; for (const auto& triangle:scenes) for (const UINT samples:{1u,4u}) for (const bool variant:{false,true}) for (const D3D12_RECT scissor:{D3D12_RECT{0,0,32,32},D3D12_RECT{8,8,24,24}}) { // InnerCoverage is undefined in D3D12 when conservative rasterization is off: no off-mode oracle. for (auto* fixture:{&a,&b}) { if (native_only && fixture==&a) continue; Mask mask{}; std::vector rgba; if (!render(*fixture,triangle,true,samples,variant,scissor,mask,D3D12_CULL_MODE_NONE,nullptr,&rgba) || !coverage(triangle,scissor,mask) || !oracle(triangle,scissor,mask,rgba)) { std::fprintf(stderr,"%s Tier 3 scene=%zu samples=%u variant=%d scissor=%ld\n", fixture->run.ours?"Vulkan":adapter.c_str(),std::size_t(&triangle-scenes),samples,int(variant),scissor.left); return 1; } } ++comparisons; } std::printf("Tier 3 explicit ABI: %u %s %s scenarios; inner positives/negatives, 1x/4x, scissor and variants\n", comparisons,native_only?"native-only":"Vulkan/native paired",adapter.c_str()); return vk.validation_errors()?1:0; }