Skip to content

Commit

Permalink
Reduce memory used by MVKPixelFormats lookups.
Browse files Browse the repository at this point in the history
- Add MVKInflectionMap collection to manage lookups based on enums
  that have a large set of consecutive elements, plus additional enum
  values that are more sparsely assigned.
- Recognize every MTLPixelFormat value can be held in uint16_t.
- Reduce inflection-map sizes by calling shrink_to_fit().
- runcts script log completion time (unrelated).
  • Loading branch information
billhollings committed Jan 3, 2024
2 parents 88799cf + ad8b963 commit 0654928
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
6 changes: 6 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2926,6 +2926,9 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
#if MVK_XCODE_14 || (MVK_IOS && MVK_XCODE_13)
if (supportsMTLGPUFamily(Apple8)) { gpuFam = MTLGPUFamilyApple8; }
#endif
#if MVK_XCODE_15 && (MVK_IOS || MVK_MACOS)
if (supportsMTLGPUFamily(Apple9)) { gpuFam = MTLGPUFamilyApple9; }
#endif

// Combine OS major (8 bits), OS minor (8 bits), and GPU family (16 bits)
// into one 32-bit value summarizing highest GPU capability.
Expand Down Expand Up @@ -3326,6 +3329,9 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
logMsg += "\n\tsupports the following Metal Versions, GPU's and Feature Sets:";
logMsg += "\n\t\tMetal Shading Language %s";

#if MVK_XCODE_15 && (MVK_IOS || MVK_MACOS)
if (supportsMTLGPUFamily(Apple9)) { logMsg += "\n\t\tGPU Family Apple 9"; }
#endif
#if MVK_XCODE_14 || (MVK_IOS && MVK_XCODE_13)
if (supportsMTLGPUFamily(Apple8)) { logMsg += "\n\t\tGPU Family Apple 8"; }
#endif
Expand Down
47 changes: 42 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
# define MTLPixelFormatASTC_12x12_HDR MTLPixelFormatInvalid
#endif

#if !MVK_XCODE_15
# define MTLVertexFormatFloatRG11B10 MTLVertexFormatInvalid
# define MTLVertexFormatFloatRGB9E5 MTLVertexFormatInvalid
#endif


#pragma mark -
#pragma mark MVKPixelFormats
Expand Down Expand Up @@ -963,9 +968,9 @@
addVkFormatDesc( R64G64B64A64_SINT, Invalid, Invalid, Invalid, Invalid, 1, 1, 32, ColorFloat );
addVkFormatDesc( R64G64B64A64_SFLOAT, Invalid, Invalid, Invalid, Invalid, 1, 1, 32, ColorFloat );

addVkFormatDesc( B10G11R11_UFLOAT_PACK32, RG11B10Float, Invalid, Invalid, Invalid, 1, 1, 4, ColorFloat );
addVkFormatDesc( E5B9G9R9_UFLOAT_PACK32, RGB9E5Float, Invalid, Invalid, Invalid, 1, 1, 4, ColorFloat );

addVkFormatDesc( B10G11R11_UFLOAT_PACK32, RG11B10Float, Invalid, FloatRG11B10, Invalid, 1, 1, 4, ColorFloat );
addVkFormatDesc( E5B9G9R9_UFLOAT_PACK32, RGB9E5Float, Invalid, FloatRGB9E5, Invalid, 1, 1, 4, ColorFloat );
addVkFormatDesc( D32_SFLOAT, Depth32Float, Invalid, Invalid, Invalid, 1, 1, 4, DepthStencil );
addVkFormatDesc( D32_SFLOAT_S8_UINT, Depth32Float_Stencil8, Invalid, Invalid, Invalid, 1, 1, 5, DepthStencil );

Expand Down Expand Up @@ -1295,15 +1300,15 @@
// If necessary, resize vector with empty elements
#define addMTLVertexFormatDesc(MTL_VTX_FMT, IOS_CAPS, MACOS_CAPS) \
mtlVtxFmt = MTLVertexFormat ##MTL_VTX_FMT; \
if (mtlVtxFmt >= _mtlVertexFormatDescriptions.size()) { _mtlVertexFormatDescriptions.resize(mtlVtxFmt + 1, {}); } \
if (mtlVtxFmt >= _mtlVertexFormatDescriptions.size()) { _mtlVertexFormatDescriptions.resize(mtlVtxFmt + 1, {}); } \
_mtlVertexFormatDescriptions[mtlVtxFmt] = { .mtlVertexFormat = mtlVtxFmt, VK_FORMAT_UNDEFINED, \
mvkSelectPlatformValue<MVKMTLFmtCaps>(kMVKMTLFmtCaps ##MACOS_CAPS, kMVKMTLFmtCaps ##IOS_CAPS), \
MVKMTLViewClass::None, MTLPixelFormatInvalid, "MTLVertexFormat" #MTL_VTX_FMT };

void MVKPixelFormats::initMTLVertexFormatCapabilities() {
MTLVertexFormat mtlVtxFmt;

_mtlVertexFormatDescriptions.reserve(MTLVertexFormatHalf + 3);
_mtlVertexFormatDescriptions.resize(MTLVertexFormatHalf + 3, {});

addMTLVertexFormatDesc( Invalid, None, None ); // MTLVertexFormatInvalid must come first.

Expand Down Expand Up @@ -1371,6 +1376,11 @@
addMTLVertexFormatDesc( Half, None, None );

addMTLVertexFormatDesc( UChar4Normalized_BGRA, None, None );

#if MVK_XCODE_15
addMTLVertexFormatDesc( FloatRG11B10, None, None );
addMTLVertexFormatDesc( FloatRGB9E5, None, None );
#endif

_mtlVertexFormatDescriptions.shrink_to_fit();
}
Expand Down Expand Up @@ -1623,6 +1633,12 @@
addGPUOSMTLPixFmtCaps( Apple5, 11.0, BGR10_XR, All );
addGPUOSMTLPixFmtCaps( Apple5, 11.0, BGR10_XR_sRGB, All );
#endif

#if MVK_XCODE_15
addGPUOSMTLPixFmtCaps( Apple9, 14.0, R32Float, All );
addGPUOSMTLPixFmtCaps( Apple9, 14.0, RG32Float, All );
addGPUOSMTLPixFmtCaps( Apple9, 14.0, RGBA32Float, All );
#endif

addFeatSetMTLVtxFmtCaps( macOS_GPUFamily1_v3, UCharNormalized, Vertex );
addFeatSetMTLVtxFmtCaps( macOS_GPUFamily1_v3, CharNormalized, Vertex );
Expand All @@ -1634,6 +1650,11 @@
addFeatSetMTLVtxFmtCaps( macOS_GPUFamily1_v3, Short, Vertex );
addFeatSetMTLVtxFmtCaps( macOS_GPUFamily1_v3, Half, Vertex );
addFeatSetMTLVtxFmtCaps( macOS_GPUFamily1_v3, UChar4Normalized_BGRA, Vertex );

#if MVK_XCODE_15
addGPUOSMTLVtxFmtCaps( Apple5, 14.0, FloatRG11B10, Vertex );
addGPUOSMTLVtxFmtCaps( Apple5, 14.0, FloatRGB9E5, Vertex );
#endif
#endif

#if MVK_TVOS
Expand Down Expand Up @@ -1727,6 +1748,11 @@
addFeatSetMTLVtxFmtCaps( tvOS_GPUFamily1_v3, Short, Vertex );
addFeatSetMTLVtxFmtCaps( tvOS_GPUFamily1_v3, Half, Vertex );
addFeatSetMTLVtxFmtCaps( tvOS_GPUFamily1_v3, UChar4Normalized_BGRA, Vertex );

#if MVK_XCODE_15
addGPUOSMTLVtxFmtCaps( Apple5, 17.0, FloatRG11B10, Vertex );
addGPUOSMTLVtxFmtCaps( Apple5, 17.0, FloatRGB9E5, Vertex );
#endif

// Disable for tvOS simulator last.
#if MVK_OS_SIMULATOR
Expand Down Expand Up @@ -1872,6 +1898,12 @@

addGPUOSMTLPixFmtCaps( Apple1, 13.0, Depth16Unorm, DRFM );
addGPUOSMTLPixFmtCaps( Apple3, 13.0, Depth16Unorm, DRFMR );

#if MVK_XCODE_15
addGPUOSMTLPixFmtCaps( Apple9, 14.0, R32Float, All );
addGPUOSMTLPixFmtCaps( Apple9, 14.0, RG32Float, All );
addGPUOSMTLPixFmtCaps( Apple9, 14.0, RGBA32Float, All );
#endif

// Vertex formats
addFeatSetMTLVtxFmtCaps( iOS_GPUFamily1_v4, UCharNormalized, Vertex );
Expand All @@ -1884,6 +1916,11 @@
addFeatSetMTLVtxFmtCaps( iOS_GPUFamily1_v4, Short, Vertex );
addFeatSetMTLVtxFmtCaps( iOS_GPUFamily1_v4, Half, Vertex );
addFeatSetMTLVtxFmtCaps( iOS_GPUFamily1_v4, UChar4Normalized_BGRA, Vertex );

#if MVK_XCODE_15
addGPUOSMTLVtxFmtCaps( Apple5, 17.0, FloatRG11B10, Vertex );
addGPUOSMTLVtxFmtCaps( Apple5, 17.0, FloatRGB9E5, Vertex );
#endif

// Disable for iOS simulator last.
#if MVK_OS_SIMULATOR
Expand Down

0 comments on commit 0654928

Please sign in to comment.