Skip to content

Commit

Permalink
Pass zero count for variable sized descriptor arrays.
Browse files Browse the repository at this point in the history
Fixes a GPU crash and doesn't introduce a validation error, unlike passing the maximum size.
  • Loading branch information
js6i committed Sep 13, 2024
1 parent 2f7ae76 commit 13bdb46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 1 addition & 3 deletions MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s
VkDescriptorType descType,
MVKSampler* immutableSampler,
bool usingNativeTextureAtomics) {
if (count == 0) { return; }

#define addResourceBinding(spvRezType) \
do { \
mvk::MSLResourceBinding rb; \
Expand Down Expand Up @@ -533,7 +531,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s
uint32_t dslIndex) {
// For argument buffers, set variable length arrays to length 1 in shader.
bool isUsingMtlArgBuff = _layout->isUsingMetalArgumentBuffers();
uint32_t descCnt = isUsingMtlArgBuff ? getDescriptorCount(1) : getDescriptorCount();
uint32_t descCnt = isUsingMtlArgBuff ? getDescriptorCount(0) : getDescriptorCount();

// Establish the resource indices to use, by combining the offsets of the DSL and this DSL binding.
MVKShaderResourceBinding mtlIdxs = _mtlResourceIndexOffsets + dslMTLRezIdxOffsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ MVK_PUBLIC_SYMBOL bool SPIRVToMSLConverter::convert(SPIRVToMSLConversionConfigur
auto& rbb = rb.resourceBinding;
if (rbb.stage == shaderConfig.options.entryPointStage) {
pMSLCompiler->add_msl_resource_binding(rbb);
if (rbb.count == 0) {
pMSLCompiler->set_argument_buffer_device_address_space(rbb.desc_set, true);
}
if (rb.requiresConstExprSampler) {
pMSLCompiler->remap_constexpr_sampler_by_binding(rbb.desc_set, rbb.binding, rb.constExprSampler);
}
Expand Down

0 comments on commit 13bdb46

Please sign in to comment.