Skip to content

Commit

Permalink
Add configuration variable for VK_EXT_image_2d_view_of_3d
Browse files Browse the repository at this point in the history
Since the implementation makes some assumptions as to how 3D texture
memory is laid out by the metal driver, only advertise
VK_EXT_image_2d_view_of_3d if MVK_CONFIG_ENABLE_2DVIEWOF3D is enabled.
MVK_CONFIG_ENABLE_2DVIEWOF3D is off by default.
  • Loading branch information
ncesario-lunarg committed Oct 31, 2024
1 parent 57d6688 commit c305941
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Docs/MoltenVK_Configuration_Parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/API/mvk_private_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/Utility/MVKConfigMembers.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions MoltenVK/MoltenVK/Utility/MVKEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions MoltenVK/MoltenVK/Utility/MVKEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c305941

Please sign in to comment.