Merge branch 'master' into combined-store-resolve

This commit is contained in:
Bill Hollings 2019-01-22 10:58:06 -08:00 committed by GitHub
commit a9420c2898
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 165 additions and 61 deletions

View File

@ -48,7 +48,7 @@ extern "C" {
*/
#define MVK_VERSION_MAJOR 1
#define MVK_VERSION_MINOR 0
#define MVK_VERSION_PATCH 31
#define MVK_VERSION_PATCH 32
#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)
@ -133,7 +133,7 @@ typedef struct {
* will be dispatched to a GCD dispatch_queue whose priority is determined by
* VkDeviceQueueCreateInfo::pQueuePriorities during vkCreateDevice().
*
* The value of this parameter may be changed before creating a VkDevice,
* The value of this parameter must be changed before creating a VkDevice,
* for the change to take effect.
*
* The initial value or this parameter is set by the
@ -193,7 +193,7 @@ typedef struct {
* is required per command buffer queue submission, which may be significantly less than the
* number of Vulkan command buffers.
*
* The value of this parameter may be changed before creating a VkDevice,
* The value of this parameter must be changed before creating a VkDevice,
* for the change to take effect.
*
* The initial value or this parameter is set by the
@ -331,7 +331,7 @@ typedef struct {
* as having specialized graphics OR compute OR transfer functionality, to make it easier for some
* apps to select a queue family with the appropriate requirements.
*
* The value of this parameter may be changed before creating a VkDevice, and before
* The value of this parameter must be changed before creating a VkDevice, and before
* querying a VkPhysicalDevice for queue family properties, for the change to take effect.
*
* The initial value or this parameter is set by the
@ -364,7 +364,7 @@ typedef struct {
* system window compositor to determine how best to blend content with the windowing
* system, and as a result, may want to disable this parameter.
*
* The value of this parameter may be changed before creating a VkDevice,
* The value of this parameter must be changed before creating a VkDevice,
* for the change to take effect.
*
* The initial value or this parameter is set by the
@ -414,6 +414,35 @@ typedef struct {
*/
VkBool32 fullImageViewSwizzle;
/**
* The index of the queue family whose presentation submissions will
* be used as the default GPU Capture Scope during debugging in Xcode.
*
* The value of this parameter must be changed before creating a VkDevice,
* for the change to take effect.
*
* The initial value or this parameter is set by the
* MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_FAMILY_INDEX
* runtime environment variable or MoltenVK compile-time build setting.
* If neither is set, the value of this parameter defaults to zero (the first queue family).
*/
uint32_t defaultGPUCaptureScopeQueueFamilyIndex;
/**
* The index of the queue, within the queue family identified by the
* defaultGPUCaptureScopeQueueFamilyIndex parameter, whose presentation submissions
* will be used as the default GPU Capture Scope during debugging in Xcode.
*
* The value of this parameter must be changed before creating a VkDevice,
* for the change to take effect.
*
* The initial value or this parameter is set by the
* MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_INDEX
* runtime environment variable or MoltenVK compile-time build setting.
* If neither is set, the value of this parameter defaults to zero (the first queue).
*/
uint32_t defaultGPUCaptureScopeQueueIndex;
} MVKConfiguration;
/**
@ -454,8 +483,9 @@ typedef struct {
VkSampleCountFlags supportedSampleCounts; /**< A bitmask identifying the sample counts supported by the device. */
uint32_t minSwapchainImageCount; /**< The minimum number of swapchain images that can be supported by a surface. */
uint32_t maxSwapchainImageCount; /**< The maximum number of swapchain images that can be supported by a surface. */
// v17
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 arrayOfSamplers; /**< If true, arrays of texture samplers is supported. */
} MVKPhysicalDeviceMetalFeatures;
/**

View File

@ -73,7 +73,7 @@ typedef struct MVKShaderResourceBinding {
#pragma mark MVKDescriptorSetLayoutBinding
/** Represents a Vulkan descriptor set layout binding. */
class MVKDescriptorSetLayoutBinding : public MVKConfigurableObject {
class MVKDescriptorSetLayoutBinding : public MVKBaseDeviceObject {
public:
@ -100,7 +100,8 @@ public:
uint32_t dslIndex);
/** Constructs an instance. */
MVKDescriptorSetLayoutBinding(MVKDescriptorSetLayout* layout,
MVKDescriptorSetLayoutBinding(MVKDevice* device,
MVKDescriptorSetLayout* layout,
const VkDescriptorSetLayoutBinding* pBinding);
MVKDescriptorSetLayoutBinding(const MVKDescriptorSetLayoutBinding& binding);
@ -112,7 +113,7 @@ protected:
friend class MVKDescriptorBinding;
friend class MVKPipelineLayout;
VkResult initMetalResourceIndexOffsets(MVKShaderStageResourceBinding* pBindingIndexes,
void initMetalResourceIndexOffsets(MVKShaderStageResourceBinding* pBindingIndexes,
MVKShaderStageResourceBinding* pDescSetCounts,
const VkDescriptorSetLayoutBinding* pBinding);

View File

@ -405,8 +405,9 @@ void MVKDescriptorSetLayoutBinding::populateShaderConverterContext(SPIRVToMSLCon
}
}
MVKDescriptorSetLayoutBinding::MVKDescriptorSetLayoutBinding(MVKDescriptorSetLayout* layout,
const VkDescriptorSetLayoutBinding* pBinding) : MVKConfigurableObject() {
MVKDescriptorSetLayoutBinding::MVKDescriptorSetLayoutBinding(MVKDevice* device,
MVKDescriptorSetLayout* layout,
const VkDescriptorSetLayoutBinding* pBinding) : MVKBaseDeviceObject(device) {
// Determine the shader stages used by this binding
_applyToVertexStage = mvkAreFlagsEnabled(pBinding->stageFlags, VK_SHADER_STAGE_VERTEX_BIT);
_applyToFragmentStage = mvkAreFlagsEnabled(pBinding->stageFlags, VK_SHADER_STAGE_FRAGMENT_BIT);
@ -414,20 +415,20 @@ MVKDescriptorSetLayoutBinding::MVKDescriptorSetLayoutBinding(MVKDescriptorSetLay
// If this binding is used by the vertex shader, set the Metal resource index
if (_applyToVertexStage) {
setConfigurationResult(initMetalResourceIndexOffsets(&_mtlResourceIndexOffsets.vertexStage,
&layout->_mtlResourceCounts.vertexStage, pBinding));
initMetalResourceIndexOffsets(&_mtlResourceIndexOffsets.vertexStage,
&layout->_mtlResourceCounts.vertexStage, pBinding);
}
// If this binding is used by the fragment shader, set the Metal resource index
if (_applyToFragmentStage) {
setConfigurationResult(initMetalResourceIndexOffsets(&_mtlResourceIndexOffsets.fragmentStage,
&layout->_mtlResourceCounts.fragmentStage, pBinding));
initMetalResourceIndexOffsets(&_mtlResourceIndexOffsets.fragmentStage,
&layout->_mtlResourceCounts.fragmentStage, pBinding);
}
// If this binding is used by a compute shader, set the Metal resource index
if (_applyToComputeStage) {
setConfigurationResult(initMetalResourceIndexOffsets(&_mtlResourceIndexOffsets.computeStage,
&layout->_mtlResourceCounts.computeStage, pBinding));
initMetalResourceIndexOffsets(&_mtlResourceIndexOffsets.computeStage,
&layout->_mtlResourceCounts.computeStage, pBinding);
}
// If immutable samplers are defined, copy them in
@ -446,7 +447,7 @@ MVKDescriptorSetLayoutBinding::MVKDescriptorSetLayoutBinding(MVKDescriptorSetLay
}
MVKDescriptorSetLayoutBinding::MVKDescriptorSetLayoutBinding(const MVKDescriptorSetLayoutBinding& binding) :
MVKConfigurableObject(), _info(binding._info), _immutableSamplers(binding._immutableSamplers),
MVKBaseDeviceObject(binding._device), _info(binding._info), _immutableSamplers(binding._immutableSamplers),
_mtlResourceIndexOffsets(binding._mtlResourceIndexOffsets),
_applyToVertexStage(binding._applyToVertexStage), _applyToFragmentStage(binding._applyToFragmentStage),
_applyToComputeStage(binding._applyToComputeStage) {
@ -461,17 +462,19 @@ MVKDescriptorSetLayoutBinding::~MVKDescriptorSetLayoutBinding() {
}
}
/**
* Sets the appropriate Metal resource indexes within this binding from the
* specified descriptor set binding counts, and updates those counts accordingly.
*/
VkResult MVKDescriptorSetLayoutBinding::initMetalResourceIndexOffsets(MVKShaderStageResourceBinding* pBindingIndexes,
// Sets the appropriate Metal resource indexes within this binding from the
// specified descriptor set binding counts, and updates those counts accordingly.
void MVKDescriptorSetLayoutBinding::initMetalResourceIndexOffsets(MVKShaderStageResourceBinding* pBindingIndexes,
MVKShaderStageResourceBinding* pDescSetCounts,
const VkDescriptorSetLayoutBinding* pBinding) {
switch (pBinding->descriptorType) {
case VK_DESCRIPTOR_TYPE_SAMPLER:
pBindingIndexes->samplerIndex = pDescSetCounts->samplerIndex;
pDescSetCounts->samplerIndex += pBinding->descriptorCount;
if (pBinding->descriptorCount > 1 && !_device->_pMetalFeatures->arrayOfSamplers) {
setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "Device %s does not support arrays of samplers.", _device->getName()));
}
break;
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
@ -479,6 +482,15 @@ VkResult MVKDescriptorSetLayoutBinding::initMetalResourceIndexOffsets(MVKShaderS
pDescSetCounts->textureIndex += pBinding->descriptorCount;
pBindingIndexes->samplerIndex = pDescSetCounts->samplerIndex;
pDescSetCounts->samplerIndex += pBinding->descriptorCount;
if (pBinding->descriptorCount > 1) {
if ( !_device->_pMetalFeatures->arrayOfTextures ) {
setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "Device %s does not support arrays of textures.", _device->getName()));
}
if ( !_device->_pMetalFeatures->arrayOfSamplers ) {
setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "Device %s does not support arrays of samplers.", _device->getName()));
}
}
break;
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
@ -488,6 +500,10 @@ VkResult MVKDescriptorSetLayoutBinding::initMetalResourceIndexOffsets(MVKShaderS
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
pBindingIndexes->textureIndex = pDescSetCounts->textureIndex;
pDescSetCounts->textureIndex += pBinding->descriptorCount;
if (pBinding->descriptorCount > 1 && !_device->_pMetalFeatures->arrayOfTextures) {
setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "Device %s does not support arrays of textures.", _device->getName()));
}
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
@ -501,7 +517,6 @@ VkResult MVKDescriptorSetLayoutBinding::initMetalResourceIndexOffsets(MVKShaderS
default:
break;
}
return VK_SUCCESS;
}
@ -634,7 +649,7 @@ MVKDescriptorSetLayout::MVKDescriptorSetLayout(MVKDevice* device,
// Create the descriptor bindings
_bindings.reserve(pCreateInfo->bindingCount);
for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
_bindings.emplace_back(this, &pCreateInfo->pBindings[i]);
_bindings.emplace_back(_device, this, &pCreateInfo->pBindings[i]);
_bindingToIndex[pCreateInfo->pBindings[i].binding] = i;
setConfigurationResult(_bindings.back().getConfigurationResult());
}

View File

@ -90,6 +90,9 @@ public:
/** Populates the specified structure with the properties of this device. */
void getProperties(VkPhysicalDeviceProperties2* properties);
/** Returns the name of this device. */
inline const char* getName() { return _properties.deviceName; }
/** Returns whether the specified format is supported on this device. */
bool getFormatIsSupported(VkFormat format);
@ -315,6 +318,9 @@ public:
/** Returns the physical device underlying this logical device. */
inline MVKPhysicalDevice* getPhysicalDevice() { return _physicalDevice; }
/** Returns the name of this device. */
inline const char* getName() { return _pProperties->deviceName; }
/** Returns the common resource factory for creating command resources. */
inline MVKCommandResourceFactory* getCommandResourceFactory() { return _commandResourceFactory; }

View File

@ -619,6 +619,14 @@ void MVKPhysicalDevice::initMetalFeatures() {
_metalFeatures.mtlBufferAlignment = 16; // Min float4 alignment for typical vertex buffers. MTLBuffer may go down to 4 bytes for other data.
_metalFeatures.maxTextureDimension = (16 * KIBI);
}
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily3_v2] ) {
_metalFeatures.arrayOfTextures = true;
}
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily3_v3] ) {
_metalFeatures.arrayOfSamplers = true;
}
#endif
#if MVK_MACOS
@ -644,6 +652,8 @@ void MVKPhysicalDevice::initMetalFeatures() {
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v3] ) {
_metalFeatures.mslVersion = SPIRVToMSLConverterOptions::makeMSLVersion(2);
_metalFeatures.texelBuffers = true;
_metalFeatures.arrayOfTextures = true;
_metalFeatures.arrayOfSamplers = true;
_metalFeatures.presentModeImmediate = true;
}
@ -685,6 +695,9 @@ void MVKPhysicalDevice::initFeatures() {
_features.shaderInt16 = true;
_features.multiDrawIndirect = true;
_features.shaderSampledImageArrayDynamicIndexing = _metalFeatures.arrayOfTextures;
_features.shaderStorageImageArrayDynamicIndexing = _metalFeatures.arrayOfTextures;
if (_metalFeatures.indirectDrawing && _metalFeatures.baseVertexInstanceDrawing) {
_features.drawIndirectFirstInstance = true;
}
@ -698,10 +711,6 @@ void MVKPhysicalDevice::initFeatures() {
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily3_v1] ) {
_features.occlusionQueryPrecise = true;
}
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily3_v2] ) {
_features.shaderSampledImageArrayDynamicIndexing = true;
_features.shaderStorageImageArrayDynamicIndexing = true;
}
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily2_v4] ) {
_features.depthClamp = true;
@ -722,8 +731,6 @@ void MVKPhysicalDevice::initFeatures() {
if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v3] ) {
_features.multiViewport = true;
_features.shaderSampledImageArrayDynamicIndexing = true;
_features.shaderStorageImageArrayDynamicIndexing = true;
}
#endif
@ -1874,9 +1881,13 @@ void MVKDevice::initQueues(const VkDeviceCreateInfo* pCreateInfo) {
const VkDeviceQueueCreateInfo* pQFInfo = &pCreateInfo->pQueueCreateInfos[qrIdx];
uint32_t qfIdx = pQFInfo->queueFamilyIndex;
MVKQueueFamily* qFam = qFams[qfIdx];
VkQueueFamilyProperties qfProps;
qFam->getProperties(&qfProps);
_queuesByQueueFamilyIndex.resize(qfIdx + 1); // Ensure an entry for this queue family exists
auto& queues = _queuesByQueueFamilyIndex[qfIdx];
for (uint32_t qIdx = 0; qIdx < pQFInfo->queueCount; qIdx++) {
uint32_t qCnt = min(pQFInfo->queueCount, qfProps.queueCount);
for (uint32_t qIdx = 0; qIdx < qCnt; qIdx++) {
queues.push_back(new MVKQueue(this, qFam, qIdx, pQFInfo->pQueuePriorities[qIdx]));
}
}

View File

@ -368,6 +368,8 @@ void MVKInstance::initConfig() {
MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.specializedQueueFamilies, MVK_CONFIG_SPECIALIZED_QUEUE_FAMILIES);
MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.switchSystemGPU, MVK_CONFIG_SWITCH_SYSTEM_GPU);
MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.fullImageViewSwizzle, MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE);
MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.defaultGPUCaptureScopeQueueFamilyIndex, MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_FAMILY_INDEX);
MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.defaultGPUCaptureScopeQueueIndex, MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_INDEX);
}
VkResult MVKInstance::verifyLayers(uint32_t count, const char* const* names) {

View File

@ -174,9 +174,15 @@ void MVKQueue::initMTLCommandQueue() {
// Initializes Xcode GPU capture scopes
void MVKQueue::initGPUCaptureScopes() {
const MVKConfiguration* pMVKConfig = _device->getInstance()->getMoltenVKConfiguration();
_submissionCaptureScope = new MVKGPUCaptureScope(this, "CommandBuffer-Submission");
_presentationCaptureScope = new MVKGPUCaptureScope(this, "Surface-Presentation");
if (_queueFamily->getIndex() == pMVKConfig->defaultGPUCaptureScopeQueueFamilyIndex &&
_index == pMVKConfig->defaultGPUCaptureScopeQueueIndex) {
_presentationCaptureScope->makeDefault();
}
_presentationCaptureScope->beginScope(); // Allow Xcode to capture the first frame if desired.
}

View File

@ -224,6 +224,7 @@ MVKMTLFunction MVKShaderModule::getMTLFunction(SPIRVToMSLConverterContext* pCont
const VkSpecializationInfo* pSpecializationInfo,
MVKPipelineCache* pipelineCache) {
lock_guard<mutex> lock(_accessLock);
MVKShaderLibrary* mvkLib = _defaultLibrary;
if ( !mvkLib ) {
uint64_t startTime = _device->getPerformanceTimestamp();
@ -233,7 +234,10 @@ MVKMTLFunction MVKShaderModule::getMTLFunction(SPIRVToMSLConverterContext* pCont
mvkLib = _shaderLibraryCache.getShaderLibrary(pContext, this);
}
_device->addActivityPerformance(_device->_performanceStatistics.shaderCompilation.shaderLibraryFromCache, startTime);
} else {
pContext->markAllAttributesAndResourcesUsed();
}
return mvkLib ? mvkLib->getMTLFunction(pSpecializationInfo) : MVKMTLFunctionNull;
}

View File

@ -112,6 +112,23 @@
# define MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE 0
#endif
/**
* The index of the queue family whose presentation submissions will
* be used as the default GPU Capture Scope during debugging in Xcode.
*/
#ifndef MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_FAMILY_INDEX
# define MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_FAMILY_INDEX 0
#endif
/**
* The index of the queue, within the queue family identified by the
* MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_FAMILY_INDEX setting, whose presentation
* submissions will be used as the default GPU Capture Scope during debugging in Xcode.
*/
#ifndef MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_INDEX
# define MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_INDEX 0
#endif
/**
* IOSurfaces are supported on macOS, and on iOS starting with iOS 11.

View File

@ -105,6 +105,15 @@ MVK_PUBLIC_SYMBOL bool SPIRVToMSLConverterContext::isVertexBufferUsed(uint32_t m
return false;
}
MVK_PUBLIC_SYMBOL void SPIRVToMSLConverterContext::markAllAttributesAndResourcesUsed() {
if (options.entryPointStage == spv::ExecutionModelVertex) {
for (auto& va : vertexAttributes) { va.isUsedByShader = true; }
}
for (auto& rb : resourceBindings) { rb.isUsedByShader = true; }
}
MVK_PUBLIC_SYMBOL bool SPIRVToMSLConverterContext::matches(const SPIRVToMSLConverterContext& other) const {
if ( !options.matches(other.options) ) { return false; }

View File

@ -143,6 +143,9 @@ namespace mvk {
/** Returns whether the vertex buffer at the specified Metal binding index is used by the shader. */
bool isVertexBufferUsed(uint32_t mslBuffer) const;
/** Marks all vertex attributes and resources as being used by the shader. */
void markAllAttributesAndResourcesUsed();
/**
* Returns whether this context matches the other context. It does if the respective
* options match and any vertex attributes and resource bindings used by this context