diff --git a/Docs/MoltenVK_Configuration_Parameters.md b/Docs/MoltenVK_Configuration_Parameters.md index c4cec16da..ced0b2952 100644 --- a/Docs/MoltenVK_Configuration_Parameters.md +++ b/Docs/MoltenVK_Configuration_Parameters.md @@ -684,3 +684,15 @@ Determines the style used to implement _Vulkan_ semaphore (`VkSemaphore`) functi In the special case of `VK_SEMAPHORE_TYPE_TIMELINE` semaphores, **MoltenVK** will always use `MTLSharedEvent` if it is available on the platform, regardless of the value of this parameter. + +--------------------------------------- +#### MVK_CONFIG_VK_ENABLE_2DVIEWOF3D + +##### Type: Boolean +##### Default: `0` + +If enabled, **MoltenVK** will advertise the `VK_EXT_image_2d_view_of_3d` extension. The **MoltenVK** implementation of this extension uses +`MTLHeap`s to create 2D textures from memory allocated for 3D textures, which makes some assumptions about how a 3D texture's memory is laid +out by the metal driver. + +Note that the use of this feature depends on `MVK_CONFIG_USE_MTLHEAP`. diff --git a/MoltenVK/MoltenVK/API/mvk_private_api.h b/MoltenVK/MoltenVK/API/mvk_private_api.h index c50ae1bbe..8cd8c13dc 100644 --- a/MoltenVK/MoltenVK/API/mvk_private_api.h +++ b/MoltenVK/MoltenVK/API/mvk_private_api.h @@ -239,6 +239,7 @@ typedef struct { VkBool32 useMetalPrivateAPI; /**< MVK_CONFIG_USE_METAL_PRIVATE_API */ const char* shaderDumpDir; /**< MVK_CONFIG_SHADER_DUMP_DIR */ VkBool32 shaderLogEstimatedGLSL; /**< MVK_CONFIG_SHADER_LOG_ESTIMATED_GLSL */ + VkBool32 enable2DViewOf3D; /**< MVK_CONFIG_VK_ENABLE_2DVIEWOF3D */ } MVKConfiguration; // Legacy support for renamed struct elements. diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 2685be63d..bd7c63ede 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -441,7 +441,7 @@ portabilityFeatures->imageViewFormatReinterpretation = true; portabilityFeatures->imageViewFormatSwizzle = (_metalFeatures.nativeTextureSwizzle || getMVKConfig().fullImageViewSwizzle); - portabilityFeatures->imageView2DOn3DImage = true; + portabilityFeatures->imageView2DOn3DImage = getMVKConfig().enable2DViewOf3D; portabilityFeatures->multisampleArrayImage = _metalFeatures.multisampleArrayTextures; portabilityFeatures->mutableComparisonSamplers = _metalFeatures.depthSampleCompare; portabilityFeatures->pointPolygons = false; @@ -583,9 +583,11 @@ break; } case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_2D_VIEW_OF_3D_FEATURES_EXT: { - auto* extFeatures = (VkPhysicalDeviceImage2DViewOf3DFeaturesEXT*)next; - extFeatures->image2DViewOf3D = true; - extFeatures->sampler2DViewOf3D = true; + if (getMVKConfig().enable2DViewOf3D) { + auto* extFeatures = (VkPhysicalDeviceImage2DViewOf3DFeaturesEXT*)next; + extFeatures->image2DViewOf3D = true; + extFeatures->sampler2DViewOf3D = true; + } break; } default: diff --git a/MoltenVK/MoltenVK/Utility/MVKConfigMembers.def b/MoltenVK/MoltenVK/Utility/MVKConfigMembers.def index b1ef51593..87e52b47b 100644 --- a/MoltenVK/MoltenVK/Utility/MVKConfigMembers.def +++ b/MoltenVK/MoltenVK/Utility/MVKConfigMembers.def @@ -85,6 +85,7 @@ MVK_CONFIG_MEMBER(timestampPeriodLowPassAlpha, float, MVK_CONFIG_MEMBER(useMetalPrivateAPI, VkBool32, USE_METAL_PRIVATE_API) MVK_CONFIG_MEMBER_STRING(shaderDumpDir, char*, SHADER_DUMP_DIR) MVK_CONFIG_MEMBER(shaderLogEstimatedGLSL, VkBool32, SHADER_LOG_ESTIMATED_GLSL) +MVK_CONFIG_MEMBER(enable2DViewOf3D, VkBool32, ENABLE_2DVIEWOF3D) #undef MVK_CONFIG_MEMBER #undef MVK_CONFIG_MEMBER_STRING diff --git a/MoltenVK/MoltenVK/Utility/MVKEnvironment.cpp b/MoltenVK/MoltenVK/Utility/MVKEnvironment.cpp index 2a58530b2..0a6245b82 100644 --- a/MoltenVK/MoltenVK/Utility/MVKEnvironment.cpp +++ b/MoltenVK/MoltenVK/Utility/MVKEnvironment.cpp @@ -26,10 +26,9 @@ // Return the expected size of MVKConfiguration, based on contents of MVKConfigMembers.def. static constexpr uint32_t getExpectedMVKConfigurationSize() { #define MVK_CONFIG_MEMBER(member, mbrType, name) cfgSize += sizeof(mbrType); - uint32_t cfgSize = 0; + size_t cfgSize = 0; #include "MVKConfigMembers.def" - cfgSize += kMVKConfigurationInternalPaddingByteCount; - return cfgSize; + return (uint32_t)((cfgSize + (alignof(MVKConfiguration) - 1)) & ~(alignof(MVKConfiguration) - 1)); } // Return the expected number of string members in MVKConfiguration, based on contents of MVKConfigMembers.def. diff --git a/MoltenVK/MoltenVK/Utility/MVKEnvironment.h b/MoltenVK/MoltenVK/Utility/MVKEnvironment.h index 8649c4e14..73ad0dce6 100644 --- a/MoltenVK/MoltenVK/Utility/MVKEnvironment.h +++ b/MoltenVK/MoltenVK/Utility/MVKEnvironment.h @@ -370,3 +370,7 @@ void mvkSetConfig(MVKConfiguration& dstMVKConfig, const MVKConfiguration& srcMVK # define MVK_CONFIG_SHADER_LOG_ESTIMATED_GLSL 0 #endif +/** Advertise VK_EXT_image_2d_view_of_3d */ +#ifndef MVK_CONFIG_ENABLE_2DVIEWOF3D +# define MVK_CONFIG_ENABLE_2DVIEWOF3D 0 +#endif