No longer extract MTLTextureType from SPIR-V Cross to create MTLArgumentEncoders.
MVKDescriptorSetLayoutBinding no longer uses MTLTextureType to create
MTLArgumentEncoder, which is not needed for descriptor set argument encoding.
Remove obsolete MSLResourceBinding::outMTLTextureType and
SPIRVToMSLConversionConfiguration::getMTLTextureType().
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h
index bb01090..e401e89 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h
@@ -166,15 +166,11 @@
friend class MVKInlineUniformBlockDescriptor;
void initMetalResourceIndexOffsets(const VkDescriptorSetLayoutBinding* pBinding, uint32_t stage);
- void addMTLArgumentDescriptors(NSMutableArray<MTLArgumentDescriptor*>* args,
- mvk::SPIRVToMSLConversionConfiguration& shaderConfig,
- uint32_t descSetIdx);
+ void addMTLArgumentDescriptors(NSMutableArray<MTLArgumentDescriptor*>* args);
void addMTLArgumentDescriptor(NSMutableArray<MTLArgumentDescriptor*>* args,
uint32_t argIndex,
MTLDataType dataType,
- MTLArgumentAccess access,
- mvk::SPIRVToMSLConversionConfiguration& shaderConfig,
- uint32_t descSetIdx);
+ MTLArgumentAccess access);
bool isUsingMetalArgumentBuffer();
void populateShaderConverterContext(mvk::SPIRVToMSLConversionConfiguration& context,
MVKShaderResourceBinding& dslMTLRezIdxOffsets,
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm
index 29123a6..a7f53a8 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm
@@ -444,48 +444,46 @@
bool MVKDescriptorSetLayoutBinding::isUsingMetalArgumentBuffer() { return _layout->isUsingMetalArgumentBuffer(); };
// Adds MTLArgumentDescriptors to the array, and updates resource indexes consumed.
-void MVKDescriptorSetLayoutBinding::addMTLArgumentDescriptors(NSMutableArray<MTLArgumentDescriptor*>* args,
- mvk::SPIRVToMSLConversionConfiguration& shaderConfig,
- uint32_t descSetIdx) {
+void MVKDescriptorSetLayoutBinding::addMTLArgumentDescriptors(NSMutableArray<MTLArgumentDescriptor*>* args) {
switch (getDescriptorType()) {
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().bufferIndex, MTLDataTypePointer, MTLArgumentAccessReadOnly, shaderConfig, descSetIdx);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().bufferIndex, MTLDataTypePointer, MTLArgumentAccessReadOnly);
break;
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().bufferIndex, MTLDataTypePointer, MTLArgumentAccessReadWrite, shaderConfig, descSetIdx);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().bufferIndex, MTLDataTypePointer, MTLArgumentAccessReadWrite);
break;
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadOnly, shaderConfig, descSetIdx);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadOnly);
break;
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadWrite, shaderConfig, descSetIdx);
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().bufferIndex, MTLDataTypePointer, MTLArgumentAccessReadWrite, shaderConfig, descSetIdx); // Needed for atomic operations
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadWrite);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().bufferIndex, MTLDataTypePointer, MTLArgumentAccessReadWrite); // Needed for atomic operations
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadOnly, shaderConfig, descSetIdx);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadOnly);
break;
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadWrite, shaderConfig, descSetIdx);
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().bufferIndex, MTLDataTypePointer, MTLArgumentAccessReadWrite, shaderConfig, descSetIdx); // Needed for atomic operations
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadWrite);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().bufferIndex, MTLDataTypePointer, MTLArgumentAccessReadWrite); // Needed for atomic operations
break;
case VK_DESCRIPTOR_TYPE_SAMPLER:
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().samplerIndex, MTLDataTypeSampler, MTLArgumentAccessReadOnly, shaderConfig, descSetIdx);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().samplerIndex, MTLDataTypeSampler, MTLArgumentAccessReadOnly);
break;
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadOnly, shaderConfig, descSetIdx);
- addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().samplerIndex, MTLDataTypeSampler, MTLArgumentAccessReadOnly, shaderConfig, descSetIdx);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().textureIndex, MTLDataTypeTexture, MTLArgumentAccessReadOnly);
+ addMTLArgumentDescriptor(args, getMetalResourceIndexOffsets().samplerIndex, MTLDataTypeSampler, MTLArgumentAccessReadOnly);
break;
default:
@@ -493,13 +491,10 @@
}
}
-// Adds an MTLArgumentDescriptor if the specified type to the array, and updates resource indexes consumed.
void MVKDescriptorSetLayoutBinding::addMTLArgumentDescriptor(NSMutableArray<MTLArgumentDescriptor*>* args,
uint32_t argIndex,
MTLDataType dataType,
- MTLArgumentAccess access,
- mvk::SPIRVToMSLConversionConfiguration& shaderConfig,
- uint32_t descSetIdx) {
+ MTLArgumentAccess access) {
uint32_t descCnt = getDescriptorCount();
if (descCnt == 0) { return; }
@@ -508,7 +503,7 @@
argDesc.access = access;
argDesc.index = argIndex;
argDesc.arrayLength = descCnt;
- argDesc.textureType = shaderConfig.getMTLTextureType(descSetIdx, getBinding());
+ argDesc.textureType = MTLTextureType2D;
[args addObject: argDesc];
}
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
index f181b46..0af15ca 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
@@ -116,8 +116,7 @@
uint32_t getDescriptorIndex(uint32_t binding, uint32_t elementIndex = 0) { return getBinding(binding)->getDescriptorIndex(elementIndex); }
MVKDescriptorSetLayoutBinding* getBinding(uint32_t binding) { return &_bindings[_bindingToIndex[binding]]; }
const VkDescriptorBindingFlags* getBindingFlags(const VkDescriptorSetLayoutCreateInfo* pCreateInfo);
- void initForMetalArgumentBufferUse();
- id<MTLArgumentEncoder> newMTLArgumentEncoder(mvk::SPIRVToMSLConversionConfiguration& shaderConfig, uint32_t descSetIdx);
+ void initMTLArgumentEncoder();
MVKSmallVector<MVKDescriptorSetLayoutBinding> _bindings;
std::unordered_map<uint32_t, uint32_t> _bindingToIndex;
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
index 9a9fb10..8afe563 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
@@ -183,19 +183,6 @@
}
}
-id<MTLArgumentEncoder> MVKDescriptorSetLayout::newMTLArgumentEncoder(mvk::SPIRVToMSLConversionConfiguration& shaderConfig,
- uint32_t descSetIdx) {
- if ( !(isUsingMetalArgumentBuffer() && isUsingDescriptorSetMetalArgumentBuffers()) ) { return nil; }
-
- @autoreleasepool {
- NSMutableArray<MTLArgumentDescriptor*>* args = [NSMutableArray arrayWithCapacity: _bindings.size()];
- for (auto& dslBind : _bindings) {
- dslBind.addMTLArgumentDescriptors(args, shaderConfig, descSetIdx);
- }
- return (args.count) ? [getMTLDevice() newArgumentEncoderWithArguments: args] : nil;
- }
-}
-
MVKDescriptorSetLayout::MVKDescriptorSetLayout(MVKDevice* device,
const VkDescriptorSetLayoutCreateInfo* pCreateInfo) : MVKVulkanAPIDeviceObject(device) {
@@ -229,7 +216,7 @@
_descriptorCount += _bindings.back().getDescriptorCount();
}
- initForMetalArgumentBufferUse();
+ initMTLArgumentEncoder();
}
// Find and return an array of binding flags from the pNext chain of pCreateInfo,
@@ -248,9 +235,14 @@
return nullptr;
}
-void MVKDescriptorSetLayout::initForMetalArgumentBufferUse() {
- SPIRVToMSLConversionConfiguration shaderConfig;
- _mtlArgumentEncoder.init(newMTLArgumentEncoder(shaderConfig, 0));
+void MVKDescriptorSetLayout::initMTLArgumentEncoder() {
+ if (isUsingDescriptorSetMetalArgumentBuffers() && isUsingMetalArgumentBuffer()) {
+ @autoreleasepool {
+ NSMutableArray<MTLArgumentDescriptor*>* args = [NSMutableArray arrayWithCapacity: _bindings.size()];
+ for (auto& dslBind : _bindings) { dslBind.addMTLArgumentDescriptors(args); }
+ _mtlArgumentEncoder.init(args.count ? [getMTLDevice() newArgumentEncoderWithArguments: args] : nil);
+ }
+ }
}
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
index 075cfbc..c6a2ab3 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
@@ -2202,7 +2202,6 @@
void serialize(Archive & archive, MSLResourceBinding& rb) {
archive(rb.resourceBinding,
rb.constExprSampler,
- rb.outMTLTextureType,
rb.requiresConstExprSampler,
rb.outIsUsedByShader);
}
diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVReflection.h b/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVReflection.h
index 0836578..915ef52 100644
--- a/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVReflection.h
+++ b/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVReflection.h
@@ -26,23 +26,6 @@
#include <string>
#include <vector>
-#ifdef __OBJC__
-#import <Metal/Metal.h>
-#else
-enum MTLTextureType {
- MTLTextureType1D,
- MTLTextureType1DArray,
- MTLTextureType2D,
- MTLTextureType2DArray,
- MTLTextureType2DMultisample,
- MTLTextureType2DMultisampleArray,
- MTLTextureType3D,
- MTLTextureTypeCube,
- MTLTextureTypeCubeArray,
- MTLTextureTypeTextureBuffer
-};
-#endif
-
namespace mvk {
@@ -297,51 +280,5 @@
}
}
- /** Given the compiler, returns the MTLTextureType of the descriptor set binding. */
- template<typename C>
- MTLTextureType getMTLTextureType(C* compiler, uint32_t desc_set, uint32_t binding) {
- for (auto varID : compiler->get_active_interface_variables()) {
- if (compiler->has_decoration(varID, spv::DecorationDescriptorSet) &&
- compiler->get_decoration(varID, spv::DecorationDescriptorSet) == desc_set &&
- compiler->has_decoration(varID, spv::DecorationBinding) &&
- compiler->get_decoration(varID, spv::DecorationBinding) == binding) {
-
- auto& mslOpts = compiler->get_msl_options();
- auto& imgType = compiler->get_type_from_variable(varID).image;
- bool isArray = imgType.arrayed;
- switch (imgType.dim) {
- case spv::DimBuffer:
- return mslOpts.texture_buffer_native ? MTLTextureTypeTextureBuffer : MTLTextureType2D;
-
- case spv::Dim1D:
- return (mslOpts.texture_1D_as_2D
- ? (isArray ? MTLTextureType2DArray : MTLTextureType2D)
- : (isArray ? MTLTextureType1DArray : MTLTextureType1D));
-
- case spv::Dim2D:
- case spv::DimSubpassData:
-#if MVK_MACOS_OR_IOS
- if (isArray && imgType.ms) { return MTLTextureType2DMultisampleArray; }
-#endif
- return (isArray
- ? MTLTextureType2DArray
- : (imgType.ms ? MTLTextureType2DMultisample : MTLTextureType2D));
-
- case spv::Dim3D:
- return MTLTextureType3D;
-
- case spv::DimCube:
- return (mslOpts.emulate_cube_array
- ? (isArray ? MTLTextureType2DArray : MTLTextureType2D)
- : (isArray ? MTLTextureTypeCubeArray : MTLTextureTypeCube));
-
- default:
- return MTLTextureType2D;
- }
- }
- }
- return MTLTextureType2D;
- }
-
}
#endif
diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVToMSLConverter.h b/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVToMSLConverter.h
index 1079284..0def16d 100644
--- a/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVToMSLConverter.h
+++ b/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVToMSLConverter.h
@@ -96,13 +96,10 @@
* hardcoded into the MSL as a constexpr type, instead of passed in as a runtime-bound variable.
* The content of that constexpr sampler is defined in the constExprSampler parameter.
*
- * The outIsUsedByShader and outMTLTextureType values are set by the shader converter
- * based on the content of the SPIR-V (and resulting MSL), and provide feedback to the
- * pipeline about shader content. The outIsUsedByShader value is set to true if the shader
- * makes use of this resource binding. This allows a pipeline to be optimized, and for two
- * shader conversion configurations to be compared only against the resource bindings that
- * are actually used by the shader. The outMTLTextureType value provides feedback to the
- * pipeline regarding the texture type expected by the shader.
+ * The outIsUsedByShader value is set by the shader converter based on the content of the SPIR-V
+ * (and resulting MSL), and is set to true if the shader makes use of this resource binding.
+ * This allows a pipeline to be optimized, and for two shader conversion configurations to
+ * be compared only against the resource bindings that are actually used by the shader.
*
* THIS STRUCT IS STREAMED OUT AS PART OF THE PIEPLINE CACHE.
* CHANGES TO THIS STRUCT SHOULD BE CAPTURED IN THE STREAMING LOGIC OF THE PIPELINE CACHE.
@@ -110,13 +107,12 @@
typedef struct MSLResourceBinding {
SPIRV_CROSS_NAMESPACE::MSLResourceBinding resourceBinding;
SPIRV_CROSS_NAMESPACE::MSLConstexprSampler constExprSampler;
- MTLTextureType outMTLTextureType = MTLTextureType2D;
bool requiresConstExprSampler = false;
bool outIsUsedByShader = false;
/**
* Returns whether the specified resource binding match this one.
- * It does if all corresponding elements except outMTLTextureType and outIsUsedByShader are equal.
+ * It does if all corresponding elements except outIsUsedByShader are equal.
*/
bool matches(const MSLResourceBinding& other) const;
@@ -164,9 +160,6 @@
/** Returns whether the vertex buffer at the specified Vulkan binding is used by the shader. */
bool isVertexBufferUsed(uint32_t binding) const { return countShaderInputsAt(binding) > 0; }
- /** Returns the MTLTextureType of the image resource at the descriptor set and binding. */
- MTLTextureType getMTLTextureType(uint32_t descSet, uint32_t binding) const;
-
/** Marks all input variables and resources as being used by the shader. */
void markAllInputsAndResourcesUsed();
diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVToMSLConverter.mm b/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVToMSLConverter.mm
index 2b76630..bfe0071 100644
--- a/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVToMSLConverter.mm
+++ b/MoltenVKShaderConverter/MoltenVKShaderConverter/SPIRVToMSLConverter.mm
@@ -181,16 +181,6 @@
return siCnt;
}
-MVK_PUBLIC_SYMBOL MTLTextureType SPIRVToMSLConversionConfiguration::getMTLTextureType(uint32_t descSet, uint32_t binding) const {
- for (auto& rb : resourceBindings) {
- auto& rbb = rb.resourceBinding;
- if (rb.outIsUsedByShader && rbb.desc_set == descSet && rbb.binding == binding) {
- return rb.outMTLTextureType;
- }
- }
- return MTLTextureType2D;
-}
-
MVK_PUBLIC_SYMBOL void SPIRVToMSLConversionConfiguration::markAllInputsAndResourcesUsed() {
for (auto& si : shaderInputs) { si.outIsUsedByShader = true; }
for (auto& rb : resourceBindings) { rb.outIsUsedByShader = true; }
@@ -231,10 +221,8 @@
for (auto& rb : resourceBindings) {
rb.outIsUsedByShader = false;
- rb.outMTLTextureType = MTLTextureType2D;
for (auto& srcRB : srcContext.resourceBindings) {
if (rb.matches(srcRB)) {
- rb.outMTLTextureType = srcRB.outMTLTextureType;
rb.outIsUsedByShader = srcRB.outIsUsedByShader;
}
}
@@ -376,9 +364,6 @@
}
for (auto& ctxRB : context.resourceBindings) {
if (ctxRB.resourceBinding.stage == context.options.entryPointStage) {
- ctxRB.outMTLTextureType = getMTLTextureType(pMSLCompiler,
- ctxRB.resourceBinding.desc_set,
- ctxRB.resourceBinding.binding);
ctxRB.outIsUsedByShader = pMSLCompiler->is_msl_resource_binding_used(ctxRB.resourceBinding.stage,
ctxRB.resourceBinding.desc_set,
ctxRB.resourceBinding.binding);