Set MSL version for shader compiling from Metal feature set.
Add MVKPhysicalDeviceMetalFeatures::mslVersionEnum and set from Metal feature sets. Derive MVKPhysicalDeviceMetalFeatures:: mslVersion from mslVersionEnum. MVKDevice::getMTLCompileOptions() sets MTLCompileOptions::languageVersion from MVKPhysicalDeviceMetalFeatures::mslVersionEnum. MVKAssert logs error even when assertions disabled. Update VK_MVK_MOLTENVK_SPEC_VERSION to 18.
This commit is contained in:
parent
fbb906f163
commit
0984b11bc0
@ -190,16 +190,19 @@ void MVKLogImpl(bool logToPrintf, bool logToASL, int aslLvl, const char* lvlStr,
|
|||||||
#define MVKLogDebugImpl(fmt, ...) MVKLogImpl(true, !(MVK_DEBUG), ASL_LEVEL_DEBUG, "mvk-debug", fmt, ##__VA_ARGS__)
|
#define MVKLogDebugImpl(fmt, ...) MVKLogImpl(true, !(MVK_DEBUG), ASL_LEVEL_DEBUG, "mvk-debug", fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
#if NS_BLOCK_ASSERTIONS
|
#ifdef NS_BLOCK_ASSERTIONS
|
||||||
# define MVKAssert(test, fmt, ...)
|
# define MVK_BLOCK_ASSERTIONS 1
|
||||||
#else
|
#else
|
||||||
# define MVKAssert(test, fmt, ...) \
|
# define MVK_BLOCK_ASSERTIONS 0
|
||||||
if (!(test)) { \
|
|
||||||
MVKLogError(fmt, ##__VA_ARGS__); \
|
|
||||||
assert(false); \
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MVKAssert(test, fmt, ...) \
|
||||||
|
do { \
|
||||||
|
bool isErr = !(test); \
|
||||||
|
MVKLogErrorIf(isErr, fmt, ##__VA_ARGS__); \
|
||||||
|
assert(!isErr || MVK_BLOCK_ASSERTIONS); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define MVKAssertUnimplemented(name) MVKAssert(false, "%s is not implemented!", name)
|
#define MVKAssertUnimplemented(name) MVKAssert(false, "%s is not implemented!", name)
|
||||||
|
|
||||||
// Use this macro to open a break-point programmatically.
|
// Use this macro to open a break-point programmatically.
|
||||||
|
@ -31,6 +31,8 @@ extern "C" {
|
|||||||
#ifdef __OBJC__
|
#ifdef __OBJC__
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
#import <IOSurface/IOSurfaceRef.h>
|
#import <IOSurface/IOSurfaceRef.h>
|
||||||
|
#else
|
||||||
|
typedef unsigned long MTLLanguageVersion;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -53,7 +55,7 @@ extern "C" {
|
|||||||
#define MVK_MAKE_VERSION(major, minor, patch) (((major) * 10000) + ((minor) * 100) + (patch))
|
#define MVK_MAKE_VERSION(major, minor, patch) (((major) * 10000) + ((minor) * 100) + (patch))
|
||||||
#define MVK_VERSION MVK_MAKE_VERSION(MVK_VERSION_MAJOR, MVK_VERSION_MINOR, MVK_VERSION_PATCH)
|
#define MVK_VERSION MVK_MAKE_VERSION(MVK_VERSION_MAJOR, MVK_VERSION_MINOR, MVK_VERSION_PATCH)
|
||||||
|
|
||||||
#define VK_MVK_MOLTENVK_SPEC_VERSION 17
|
#define VK_MVK_MOLTENVK_SPEC_VERSION 18
|
||||||
#define VK_MVK_MOLTENVK_EXTENSION_NAME "VK_MVK_moltenvk"
|
#define VK_MVK_MOLTENVK_EXTENSION_NAME "VK_MVK_moltenvk"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -512,6 +514,7 @@ typedef struct {
|
|||||||
VkBool32 combinedStoreResolveAction; /**< If true, the device supports VK_ATTACHMENT_STORE_OP_STORE with a simultaneous resolve attachment. */
|
VkBool32 combinedStoreResolveAction; /**< If true, the device supports VK_ATTACHMENT_STORE_OP_STORE with a simultaneous resolve attachment. */
|
||||||
VkBool32 arrayOfTextures; /**< If true, arrays of textures is supported. */
|
VkBool32 arrayOfTextures; /**< If true, arrays of textures is supported. */
|
||||||
VkBool32 arrayOfSamplers; /**< If true, arrays of texture samplers is supported. */
|
VkBool32 arrayOfSamplers; /**< If true, arrays of texture samplers is supported. */
|
||||||
|
MTLLanguageVersion mslVersionEnum; /**< The version of the Metal Shading Language available on this device, as a Metal enumeration. */
|
||||||
} MVKPhysicalDeviceMetalFeatures;
|
} MVKPhysicalDeviceMetalFeatures;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -443,7 +443,8 @@ void MVKCommandResourceFactory::initMTLLibrary() {
|
|||||||
_mtlLibrary = [getMTLDevice() newLibraryWithSource: _MVKStaticCmdShaderSource
|
_mtlLibrary = [getMTLDevice() newLibraryWithSource: _MVKStaticCmdShaderSource
|
||||||
options: getDevice()->getMTLCompileOptions()
|
options: getDevice()->getMTLCompileOptions()
|
||||||
error: &err]; // retained
|
error: &err]; // retained
|
||||||
MVKAssert( !err, "Could not compile command shaders %s (code %li) %s", err.localizedDescription.UTF8String, (long)err.code, err.localizedFailureReason.UTF8String);
|
MVKAssert( !err, "Could not compile command shaders (code %li):\n%s\n%s",
|
||||||
|
(long)err.code, err.localizedDescription.UTF8String, err.localizedFailureReason.UTF8String);
|
||||||
}
|
}
|
||||||
_device->addActivityPerformance(_device->_performanceStatistics.shaderCompilation.mslCompile, startTime);
|
_device->addActivityPerformance(_device->_performanceStatistics.shaderCompilation.mslCompile, startTime);
|
||||||
}
|
}
|
||||||
|
@ -499,7 +499,7 @@ public:
|
|||||||
inline id<MTLDevice> getMTLDevice() { return _physicalDevice->getMTLDevice(); }
|
inline id<MTLDevice> getMTLDevice() { return _physicalDevice->getMTLDevice(); }
|
||||||
|
|
||||||
/** Returns standard compilation options to be used when compiling MSL shaders. */
|
/** Returns standard compilation options to be used when compiling MSL shaders. */
|
||||||
inline MTLCompileOptions* getMTLCompileOptions() { return [[MTLCompileOptions new] autorelease]; }
|
MTLCompileOptions* getMTLCompileOptions();
|
||||||
|
|
||||||
/** Returns the Metal vertex buffer index to use for the specified vertex attribute binding number. */
|
/** Returns the Metal vertex buffer index to use for the specified vertex attribute binding number. */
|
||||||
uint32_t getMetalBufferIndexForVertexAttributeBinding(uint32_t binding);
|
uint32_t getMetalBufferIndexForVertexAttributeBinding(uint32_t binding);
|
||||||
|
@ -671,7 +671,7 @@ void MVKPhysicalDevice::initMetalFeatures() {
|
|||||||
_metalFeatures.maxSwapchainImageCount = 3;
|
_metalFeatures.maxSwapchainImageCount = 3;
|
||||||
|
|
||||||
#if MVK_IOS
|
#if MVK_IOS
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion1_0;
|
||||||
_metalFeatures.maxPerStageTextureCount = 31;
|
_metalFeatures.maxPerStageTextureCount = 31;
|
||||||
_metalFeatures.mtlBufferAlignment = 64;
|
_metalFeatures.mtlBufferAlignment = 64;
|
||||||
_metalFeatures.mtlCopyBufferAlignment = 1;
|
_metalFeatures.mtlCopyBufferAlignment = 1;
|
||||||
@ -679,23 +679,23 @@ void MVKPhysicalDevice::initMetalFeatures() {
|
|||||||
_metalFeatures.maxTextureDimension = (4 * KIBI);
|
_metalFeatures.maxTextureDimension = (4 * KIBI);
|
||||||
|
|
||||||
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v2] ) {
|
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v2] ) {
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1, 1);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion1_1;
|
||||||
_metalFeatures.dynamicMTLBuffers = true;
|
_metalFeatures.dynamicMTLBuffers = true;
|
||||||
_metalFeatures.maxTextureDimension = (8 * KIBI);
|
_metalFeatures.maxTextureDimension = (8 * KIBI);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v3] ) {
|
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v3] ) {
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1, 2);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion1_2;
|
||||||
_metalFeatures.shaderSpecialization = true;
|
_metalFeatures.shaderSpecialization = true;
|
||||||
_metalFeatures.stencilViews = true;
|
_metalFeatures.stencilViews = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v4] ) {
|
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v4] ) {
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(2);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion2_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v5] ) {
|
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily1_v5] ) {
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(2, 1);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion2_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily3_v1] ) {
|
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily3_v1] ) {
|
||||||
@ -720,7 +720,7 @@ void MVKPhysicalDevice::initMetalFeatures() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MVK_MACOS
|
#if MVK_MACOS
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1, 1);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion1_1;
|
||||||
_metalFeatures.maxPerStageTextureCount = 128;
|
_metalFeatures.maxPerStageTextureCount = 128;
|
||||||
_metalFeatures.mtlBufferAlignment = 256;
|
_metalFeatures.mtlBufferAlignment = 256;
|
||||||
_metalFeatures.mtlCopyBufferAlignment = 4;
|
_metalFeatures.mtlCopyBufferAlignment = 4;
|
||||||
@ -730,7 +730,7 @@ void MVKPhysicalDevice::initMetalFeatures() {
|
|||||||
_metalFeatures.maxTextureDimension = (16 * KIBI);
|
_metalFeatures.maxTextureDimension = (16 * KIBI);
|
||||||
|
|
||||||
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v2] ) {
|
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v2] ) {
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1, 2);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion1_2;
|
||||||
_metalFeatures.dynamicMTLBuffers = true;
|
_metalFeatures.dynamicMTLBuffers = true;
|
||||||
_metalFeatures.shaderSpecialization = true;
|
_metalFeatures.shaderSpecialization = true;
|
||||||
_metalFeatures.stencilViews = true;
|
_metalFeatures.stencilViews = true;
|
||||||
@ -740,7 +740,7 @@ void MVKPhysicalDevice::initMetalFeatures() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v3] ) {
|
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v3] ) {
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(2);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion2_0;
|
||||||
_metalFeatures.texelBuffers = true;
|
_metalFeatures.texelBuffers = true;
|
||||||
_metalFeatures.arrayOfTextures = true;
|
_metalFeatures.arrayOfTextures = true;
|
||||||
_metalFeatures.arrayOfSamplers = true;
|
_metalFeatures.arrayOfSamplers = true;
|
||||||
@ -748,7 +748,7 @@ void MVKPhysicalDevice::initMetalFeatures() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v4] ) {
|
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v4] ) {
|
||||||
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(2, 1);
|
_metalFeatures.mslVersionEnum = MTLLanguageVersion2_1;
|
||||||
_metalFeatures.multisampleArrayTextures = true;
|
_metalFeatures.multisampleArrayTextures = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,6 +763,33 @@ void MVKPhysicalDevice::initMetalFeatures() {
|
|||||||
_metalFeatures.supportedSampleCounts |= sc;
|
_metalFeatures.supportedSampleCounts |= sc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (_metalFeatures.mslVersionEnum) {
|
||||||
|
case MTLLanguageVersion2_1:
|
||||||
|
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(2, 1);
|
||||||
|
break;
|
||||||
|
case MTLLanguageVersion2_0:
|
||||||
|
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(2, 0);
|
||||||
|
break;
|
||||||
|
case MTLLanguageVersion1_2:
|
||||||
|
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1, 2);
|
||||||
|
break;
|
||||||
|
case MTLLanguageVersion1_1:
|
||||||
|
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1, 1);
|
||||||
|
break;
|
||||||
|
#if MVK_IOS
|
||||||
|
case MTLLanguageVersion1_0:
|
||||||
|
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1, 0);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if MVK_MACOS
|
||||||
|
// Silence compiler warning catch-22 on MTLLanguageVersion1_0.
|
||||||
|
// But allow iOS to be explicit so it warns on future enum values
|
||||||
|
default:
|
||||||
|
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(1, 0);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initializes the physical device features of this instance. */
|
/** Initializes the physical device features of this instance. */
|
||||||
@ -1882,6 +1909,12 @@ void MVKDevice::getPerformanceStatistics(MVKPerformanceStatistics* pPerf) {
|
|||||||
|
|
||||||
#pragma mark Metal
|
#pragma mark Metal
|
||||||
|
|
||||||
|
MTLCompileOptions* MVKDevice::getMTLCompileOptions() {
|
||||||
|
MTLCompileOptions* opts = [[MTLCompileOptions new] autorelease];
|
||||||
|
opts.languageVersion = _pMetalFeatures->mslVersionEnum;
|
||||||
|
return opts;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t MVKDevice::getMetalBufferIndexForVertexAttributeBinding(uint32_t binding) {
|
uint32_t MVKDevice::getMetalBufferIndexForVertexAttributeBinding(uint32_t binding) {
|
||||||
return ((_pMetalFeatures->maxPerStageBufferCount - 1) - binding);
|
return ((_pMetalFeatures->maxPerStageBufferCount - 1) - binding);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user