From 2c01c8b7e066ec9c95c53b4613066e7561a6ac4a Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Fri, 3 Feb 2023 14:46:37 -0800 Subject: [PATCH] Work around problems with explicit LoD with arrayed depth images on Apple Silicon. Use an explicit gradient to make it sample the correct level. Update SPIRV-Cross to pull in the change needed for this. --- Docs/Whats_New.md | 2 ++ ExternalRevisions/SPIRV-Cross_repo_revision | 2 +- MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h | 1 + MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 3 +++ MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm | 6 +++++- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index 21b0d2cd..634865ba 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -20,6 +20,8 @@ Released TBA - Fix issue where extension `VK_KHR_fragment_shader_barycentric` was sometimes incorrectly disabled due to a Metal driver bug. +- Work around problems with using explicit LoD with arrayed depth images + on Apple Silicon. diff --git a/ExternalRevisions/SPIRV-Cross_repo_revision b/ExternalRevisions/SPIRV-Cross_repo_revision index adbf4dc9..4ecdce5f 100644 --- a/ExternalRevisions/SPIRV-Cross_repo_revision +++ b/ExternalRevisions/SPIRV-Cross_repo_revision @@ -1 +1 @@ -eb9b2732982b8eea3395216be825a74dd84fe4be +4e2fdb25671c742a9fbe93a6034eb1542244c7e1 diff --git a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h index e78c00fc..55d7476f 100644 --- a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h +++ b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h @@ -979,6 +979,7 @@ typedef struct { VkBool32 programmableSamplePositions; /**< If true, programmable MSAA sample positions are supported. */ VkBool32 shaderBarycentricCoordinates; /**< If true, fragment shader barycentric coordinates are supported. */ MTLArgumentBuffersTier argumentBuffersTier; /**< The argument buffer tier available on this device, as a Metal enumeration. */ + VkBool32 needsSampleDrefLodArrayWorkaround; /**< If true, sampling from arrayed depth images with explicit LoD is broken and needs a workaround. */ } MVKPhysicalDeviceMetalFeatures; /** MoltenVK performance of a particular type of activity. */ diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 4ede8a47..5ec47c4c 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -1493,6 +1493,9 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.clearColorFloatRounding = MVK_FLOAT_ROUNDING_DOWN; break; case kAppleVendorId: + // TODO: Other GPUs? + _metalFeatures.needsSampleDrefLodArrayWorkaround = true; + // fallthrough case kIntelVendorId: case kNVVendorId: default: diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm index 65ef8eeb..30acafc1 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm @@ -1152,6 +1152,9 @@ bool MVKGraphicsPipeline::addFragmentShaderToPipeline(MTLRenderPipelineDescripto shaderConfig.options.mslOptions.capture_output_to_buffer = false; shaderConfig.options.mslOptions.fixed_subgroup_size = mvkIsAnyFlagEnabled(_pFragmentSS->flags, VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT) ? 0 : _device->_pMetalFeatures->maxSubgroupSize; shaderConfig.options.mslOptions.check_discarded_frag_stores = true; + if (_device->_pMetalFeatures->needsSampleDrefLodArrayWorkaround) { + shaderConfig.options.mslOptions.sample_dref_lod_array_as_grad = true; + } if (_isRasterizing && pCreateInfo->pMultisampleState) { // Must ignore allowed bad pMultisampleState pointer if rasterization disabled if (pCreateInfo->pMultisampleState->pSampleMask && pCreateInfo->pMultisampleState->pSampleMask[0] != 0xffffffff) { shaderConfig.options.mslOptions.additional_fixed_sample_mask = pCreateInfo->pMultisampleState->pSampleMask[0]; @@ -2253,7 +2256,8 @@ namespace SPIRV_CROSS_NAMESPACE { opt.vertex_index_type, opt.force_sample_rate_shading, opt.manual_helper_invocation_updates, - opt.check_discarded_frag_stores); + opt.check_discarded_frag_stores, + opt.sample_dref_lod_array_as_grad); } template