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

MoltenVK : VK_ERROR_INITIALIZATION_FAILED: Shader library compile failed (Error code 3): #2230

Open
metarutaiga opened this issue May 5, 2024 · 7 comments
Labels
Answered A question was answered Not our bug Please re-submit to other project Question

Comments

@metarutaiga
Copy link

[Vulkan] MoltenVK : VK_ERROR_INITIALIZATION_FAILED: Shader library compile failed (Error code 3):
program_source:37:25: error: no member named 'sample' in 'metal::sampler'
    color *= samDiffuse.sample(samDiffuseSmplr, float2(vary.UV0.x, 0.5));
             ~~~~~~~~~~ ^
program_source:37:32: error: use of undeclared identifier 'samDiffuseSmplr'
    color *= samDiffuse.sample(samDiffuseSmplr, float2(vary.UV0.x, 0.5));
                               ^
.
[Vulkan] MoltenVK : VK_ERROR_INVALID_SHADER_NV: Fragment shader function could not be compiled into pipeline. See previous logged error.

How to check what code generated ?
I used glslang to compile HLSL into my project.

Here is my repo : https://github.com/metarutaiga/Minamoto
To select xxGraphic and Vulkan

@billhollings
Copy link
Contributor

How to check what code generated ?

If you set the MoltenVK configuration parameters:

MVK_CONFIG_LOG_LEVEL=3
MVK_CONFIG_DEBUG=1

MoltenVK will log the incoming SPIR-V and outgoing MSL.

The Configuring MoltenVK section of the Docs/MoltenVK_Runtime_UserGuide.md document explains how to set MoltenVK configuration parameters.

@billhollings billhollings added Question Answered A question was answered labels May 5, 2024
@metarutaiga
Copy link
Author

It seems be not supported for DX9 HLSL style.

Converted MSL:
#pragma clang diagnostic ignored "-Wmissing-prototypes"

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct Varying
{
    float4 Position;
    float4 Color;
    float2 UV0;
};

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

struct main0_in
{
    float4 vary_Color [[user(locn0)]];
    float2 vary_UV0 [[user(locn1)]];
};

static inline __attribute__((always_inline))
float4 _main(thread const Varying& vary, sampler samDiffuse)
{
    float4 varyColor = vary.Color;
    float4 color = float4(1.0);
    color = varyColor;
    color *= samDiffuse.sample(samDiffuseSmplr, float2(vary.UV0.x, 0.5));
    return color;
}

fragment main0_out main0(main0_in in [[stage_in]], sampler samDiffuse [[sampler(0)]], float4 gl_FragCoord [[position]])
{
    main0_out out = {};
    Varying vary;
    vary.Position = gl_FragCoord;
    vary.Color = in.vary_Color;
    vary.UV0 = in.vary_UV0;
    Varying param = vary;
    out._entryPointOutput = _main(param, samDiffuse);
    return out;
}


End MSL
Estimated original GLSL:
#version 450

struct Varying
{
    vec4 Position;
    vec4 Color;
    vec2 UV0;
};

layout(set = 0, binding = 0) uniform sampler samDiffuse;

layout(location = 0) in vec4 vary_Color;
layout(location = 1) in vec2 vary_UV0;
layout(location = 0) out vec4 _entryPointOutput;

vec4 _main(Varying vary)
{
    vec4 varyColor = vary.Color;
    vec4 color = vec4(1.0);
    color = varyColor;
    color *= texture(samDiffuse, vary.UV0.x);
    return color;
}

void main()
{
    Varying vary;
    vary.Position = gl_FragCoord;
    vary.Color = vary_Color;
    vary.UV0 = vary_UV0;
    Varying param = vary;
    _entryPointOutput = _main(param);
}


End GLSL

@cdavis5e
Copy link
Collaborator

cdavis5e commented May 6, 2024

Based on the shaders you posted, it looks like you're using a standalone sampler, which in SPIR-V must be combined with an image to be able to sample a texture, but you're using it as though it were a combined image-sampler. Your SPIR-V is likely invalid.

@cdavis5e
Copy link
Collaborator

cdavis5e commented May 6, 2024

Based on your initial post, this may be a bug in glslang's HLSL support.

@cdavis5e
Copy link
Collaborator

cdavis5e commented May 6, 2024

What does the original HLSL look like?

@metarutaiga
Copy link
Author

@cdavis5e
Copy link
Collaborator

cdavis5e commented May 6, 2024

Yeah, that's almost certainly a bug in glslang. You should file a bug with them.

@cdavis5e cdavis5e added the Not our bug Please re-submit to other project label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Answered A question was answered Not our bug Please re-submit to other project Question
Projects
None yet
Development

No branches or pull requests

3 participants