Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mvk-error] SPIR-V to MSL conversion error: Argument buffer resource base type could not be determined. #2198

Open
pjako opened this issue Sep 13, 2023 · 9 comments
Assignees
Labels
bug Feature which should work in SPIRV-Cross does not for some reason.

Comments

@pjako
Copy link

pjako commented Sep 13, 2023

I was told to repost this
After I updated to the latest version of MVK I git the following error:

[mvk-error] SPIR-V to MSL conversion error: Argument buffer resource base type could not be determined. When padding argument buffer elements, all descriptor set resources must be supplied with a base type by the app.
[mvk-error] VK_ERROR_INVALID_SHADER_NV: Fragment shader function could not be compiled into pipeline. See previous logged error.`

The shader is written in hlsl, here are the relevent inputs:
[[vk::push_constant]]
struct rx_pushConstants {
uint instanceRefIndicies[6];
} rx_pushConstants;

[[vk::binding(0, 0)]] ByteAddressBuffer rx_staticResBlocks;
[[vk::binding(1, 0)]] ByteAddressBuffer rx_dynamicResBlocks;
[[vk::binding(2, 0)]] Texture2D rx_textures[];
[[vk::binding(3, 0)]] SamplerState rx_samplers[];

I use dxc to compile hlsl to spirv and MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS = 1

SpirvCross may does not like the ByteAddressBuffer? Is there a way around this problem without breaking my code?

Thanks for your help!

@tkchanat
Copy link

I am having a similar problem with StructuredBuffer. Could it be related to CompilerMSL::add_msl_resource_binding failing to recognize their base type?

@pjako
Copy link
Author

pjako commented Sep 29, 2023

I am having a similar problem with StructuredBuffer. Could it be related to CompilerMSL::add_msl_resource_binding failing to recognize their base type?

Looks like it

@rcoreilly
Copy link
Contributor

I'm experiencing the same problem, specifically for use of a StructuredBuffer -- other tests without that work fine. The sdk release version 261.1 works fine, but 268.1 breaks, so hopefully that helps to identify what changed to cause the problem?

@rcoreilly
Copy link
Contributor

Is this perhaps the source of the problem? 255ff2b @HansKristian-Work ? I don't know anything about this particular extension but the error message references "tier 2" -- and there is some info about buffer sizing errors in the description here: https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_buffer_reference2.txt

@HansKristian-Work
Copy link
Contributor

Not seeing repro SPIR-V here.

@rcoreilly
Copy link
Contributor

I'm happy to report that the latest 1.3.275.0 version of the SDK works for me!

@SRSaunders
Copy link

SRSaunders commented May 5, 2024

I get the same error when running Sasha Willems' descriptorindexing example (see Vulkan) using the most recent SDK 1.3.280/MVK 1.2.8 as well as current head for the upcoming SDK 1.3.283/MoltenVK 1.2.9. This example last worked when using SDK 1.3.250/MoltenVK 1.2.4.

[mvk-error] SPIR-V to MSL conversion error: Argument buffer resource base type could not be determined. When padding argument buffer elements, all descriptor set resources must be supplied with a base type by the app.

Specifically, the SPIRVCross compiler fails when processing the descriptorindexing.frag.spv fragment shader from Sascha Willems' Vulkan repository.

I have verified that using the old SPIRVCross compiler from SDK 1.3.250 with the most recent MoltenVK does not show the error, and works properly for the descriptorindexing example, i.e. the issue is not likely due to MoltenVK's msl compiler settings.

Here is the log output of the failure using the current SPRIVCross master:

[mvk-info] Compiling Metal shader with FastMath enabled.
[mvk-error] SPIR-V to MSL conversion error: Argument buffer resource base type could not be determined. When padding argument buffer elements, all descriptor set resources must be supplied with a base type by the app.
[mvk-info] Converting SPIR-V:
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 28
; Schema: 0
               OpCapability Shader
               OpCapability ShaderNonUniform
               OpCapability RuntimeDescriptorArray
               OpCapability SampledImageArrayNonUniformIndexing
               OpExtension "SPV_EXT_descriptor_indexing"
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %4 "main" %9 %17 %25
               OpExecutionMode %4 OriginUpperLeft
               OpSource GLSL 450
               OpSourceExtension "GL_EXT_nonuniform_qualifier"
               OpName %4 "main"
               OpName %9 "outFragColor"
               OpName %14 "textures"
               OpName %17 "inTexIndex"
               OpName %25 "inUV"
               OpDecorate %9 Location 0
               OpDecorate %14 DescriptorSet 0
               OpDecorate %14 Binding 1
               OpDecorate %17 Flat
               OpDecorate %17 Location 1
               OpDecorate %19 NonUniform
               OpDecorate %21 NonUniform
               OpDecorate %22 NonUniform
               OpDecorate %25 Location 0
          %2 = OpTypeVoid
          %3 = OpTypeFunction %2
          %6 = OpTypeFloat 32
          %7 = OpTypeVector %6 4
          %8 = OpTypePointer Output %7
          %9 = OpVariable %8 Output
         %10 = OpTypeImage %6 2D 0 0 0 1 Unknown
         %11 = OpTypeSampledImage %10
         %12 = OpTypeRuntimeArray %11
         %13 = OpTypePointer UniformConstant %12
         %14 = OpVariable %13 UniformConstant
         %15 = OpTypeInt 32 1
         %16 = OpTypePointer Input %15
         %17 = OpVariable %16 Input
         %20 = OpTypePointer UniformConstant %11
         %23 = OpTypeVector %6 2
         %24 = OpTypePointer Input %23
         %25 = OpVariable %24 Input
          %4 = OpFunction %2 None %3
          %5 = OpLabel
         %18 = OpLoad %15 %17
         %19 = OpCopyObject %15 %18
         %21 = OpAccessChain %20 %14 %19
         %22 = OpLoad %11 %21
         %26 = OpLoad %23 %25
         %27 = OpImageSampleImplicitLod %7 %22 %26
               OpStore %9 %27
               OpReturn
               OpFunctionEnd

End SPIR-V

SPIR-V to MSL conversion error: Argument buffer resource base type could not be determined. When padding argument buffer elements, all descriptor set resources must be supplied with a base type by the app.

Partially converted MSL:

End MSL

Estimated original GLSL:
#version 450
#extension GL_EXT_nonuniform_qualifier : require

layout(set = 0, binding = 1) uniform sampler2D textures[];

layout(location = 0) out vec4 outFragColor;
layout(location = 1) flat in int inTexIndex;
layout(location = 0) in vec2 inUV;

void main()
{
    int _19 = inTexIndex;
    outFragColor = texture(textures[nonuniformEXT(_19)], inUV);
}


End GLSL


[mvk-info] Compiling Metal shader with FastMath enabled.
[mvk-error] VK_ERROR_INVALID_SHADER_NV: Fragment shader function could not be compiled into pipeline. See previous logged error.
Fatal : VkResult is "ERROR_INVALID_SHADER_NV" in /Users/steve/XcodeProjects/Vulkan/apple/../examples/descriptorindexing/descriptorindexing.cpp at line 346
Assertion failed: (res == VK_SUCCESS), function preparePipelines, file descriptorindexing.cpp, line 346.
Message from debugger: killed

And now, here is the working version from SDK 1.3.250 (at SPIRVCross commit 12542fc):

[mvk-info] Compiling Metal shader with FastMath enabled.
[mvk-info] Converting SPIR-V:
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 28
; Schema: 0
               OpCapability Shader
               OpCapability ShaderNonUniform
               OpCapability RuntimeDescriptorArray
               OpCapability SampledImageArrayNonUniformIndexing
               OpExtension "SPV_EXT_descriptor_indexing"
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %4 "main" %9 %17 %25
               OpExecutionMode %4 OriginUpperLeft
               OpSource GLSL 450
               OpSourceExtension "GL_EXT_nonuniform_qualifier"
               OpName %4 "main"
               OpName %9 "outFragColor"
               OpName %14 "textures"
               OpName %17 "inTexIndex"
               OpName %25 "inUV"
               OpDecorate %9 Location 0
               OpDecorate %14 DescriptorSet 0
               OpDecorate %14 Binding 1
               OpDecorate %17 Flat
               OpDecorate %17 Location 1
               OpDecorate %19 NonUniform
               OpDecorate %21 NonUniform
               OpDecorate %22 NonUniform
               OpDecorate %25 Location 0
          %2 = OpTypeVoid
          %3 = OpTypeFunction %2
          %6 = OpTypeFloat 32
          %7 = OpTypeVector %6 4
          %8 = OpTypePointer Output %7
          %9 = OpVariable %8 Output
         %10 = OpTypeImage %6 2D 0 0 0 1 Unknown
         %11 = OpTypeSampledImage %10
         %12 = OpTypeRuntimeArray %11
         %13 = OpTypePointer UniformConstant %12
         %14 = OpVariable %13 UniformConstant
         %15 = OpTypeInt 32 1
         %16 = OpTypePointer Input %15
         %17 = OpVariable %16 Input
         %20 = OpTypePointer UniformConstant %11
         %23 = OpTypeVector %6 2
         %24 = OpTypePointer Input %23
         %25 = OpVariable %24 Input
          %4 = OpFunction %2 None %3
          %5 = OpLabel
         %18 = OpLoad %15 %17
         %19 = OpCopyObject %15 %18
         %21 = OpAccessChain %20 %14 %19
         %22 = OpLoad %11 %21
         %26 = OpLoad %23 %25
         %27 = OpImageSampleImplicitLod %7 %22 %26
               OpStore %9 %27
               OpReturn
               OpFunctionEnd

End SPIR-V

Converted MSL:
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct spvDescriptorSetBuffer0
{
    constant void* _m0_pad [[id(0)]];
    array<texture2d<float>, 32> textures [[id(1)]];
    array<sampler, 32> texturesSmplr [[id(33)]];
};

struct main0_out
{
    float4 outFragColor [[color(0)]];
};

struct main0_in
{
    float2 inUV [[user(locn0)]];
    int inTexIndex [[user(locn1)]];
};

fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
    main0_out out = {};
    int _19 = in.inTexIndex;
    out.outFragColor = spvDescriptorSet0.textures[_19].sample(spvDescriptorSet0.texturesSmplr[_19], in.inUV);
    return out;
}


End MSL

Estimated original GLSL:
#version 450
#extension GL_EXT_nonuniform_qualifier : require

layout(set = 0, binding = 1) uniform sampler2D textures[];

layout(location = 0) out vec4 outFragColor;
layout(location = 1) flat in int inTexIndex;
layout(location = 0) in vec2 inUV;

void main()
{
    int _19 = inTexIndex;
    outFragColor = texture(textures[nonuniformEXT(_19)], inUV);
}


End GLSL


[mvk-info] Compiling Metal shader with FastMath enabled.

@billhollings billhollings self-assigned this May 6, 2024
@billhollings billhollings added the bug Feature which should work in SPIRV-Cross does not for some reason. label May 6, 2024
@billhollings
Copy link
Contributor

PR #2320 should fix this.

Please pull from SPIRV-Cross branch vulkan-sdk-1.3.283-moltenvk and retest. If it fixes the problem, please close this issue.

@SRSaunders
Copy link

This solves the issue for Sascha Willems' descriptorindexing example (see Vulkan). Thanks for fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Feature which should work in SPIRV-Cross does not for some reason.
Projects
None yet
Development

No branches or pull requests

6 participants