Code Monkey home page Code Monkey logo

Comments (2)

afd avatar afd commented on June 1, 2024

I wonder if this is a spirv-cross issue.

"mvk-error" means that MoltenVk - an implementation of Vulkan on top of Apple's Metal, is going wrong.

I believe MoltenVk uses spirv-cross to compile SPIR-V into the Metal shading language (msl).

It looks to me like perhaps spirv-cross has generated:

kernel main0_out main0()

and that the Metal compiler isn't happy with this. (I don't know msl syntax.)

I suggest you try the following:

  • Build spirv-cross
  • Apply spirv-cross to the SPIR-V from your Amber, asking it to be converted into msl (you probably need to assemble the SPIR-V first - I don't recall whether spirv-cross works on assembly text)
  • Use Apple's shader validator (some details here) to validate the generated msl.

If this indeed turns out to look like a spirv-cross problem then find a minimal example that exposes the problem (you could use spirv-reduce to help you), and report it to spirv-cross (but always make sure the SPIR-V is definitely valid before reporting any SPIR-V-related bug!)

from amber.

rayanht avatar rayanht commented on June 1, 2024

Thanks @afd, this seems to be a spirv-cross error indeed. spirv-cross generates correct-ish GLSL which can be run with Amber but seems to have issues translating to MSL. The generated MSL is as follows:

#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"

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

using namespace metal;

template<typename T, size_t Num>
struct spvUnsafeArray
{
    T elements[Num ? Num : 1];
    
    thread T& operator [] (size_t pos) thread
    {
        return elements[pos];
    }
    constexpr const thread T& operator [] (size_t pos) const thread
    {
        return elements[pos];
    }
    
    device T& operator [] (size_t pos) device
    {
        return elements[pos];
    }
    constexpr const device T& operator [] (size_t pos) const device
    {
        return elements[pos];
    }
    
    constexpr const constant T& operator [] (size_t pos) const constant
    {
        return elements[pos];
    }
    
    threadgroup T& operator [] (size_t pos) threadgroup
    {
        return elements[pos];
    }
    constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
    {
        return elements[pos];
    }
};

struct _13
{
    int _m0;
    float _m1;
    spvUnsafeArray<uint, 1> _m2;
    uint _m3;
};

struct _16
{
    float3 _m0;
    float _m1;
    spvUnsafeArray<bool, 1> _m2;
    bool _m3;
};

struct _20
{
    bool _m0;
    bool _m1;
};

struct _23
{
    float _m0;
    thread bool* _m1;
    _20 _m2;
    spvUnsafeArray<float, 25> _m3;
};

struct _24
{
    float _m0;
    uint _m1;
    _23 _m2;
};

struct _29
{
    int _m0;
    uint _m1;
    float _m2;
};

struct _30
{
    _29 _m0;
};

struct _31
{
    spvUnsafeArray<uint, 1> _m0;
    int _m1;
    spvUnsafeArray<float, 1> _m2;
    bool _m3;
    _30 _m4;
};

struct _34
{
    bool _m0;
    uint _m1;
};

struct main0_out
{
    float m_3;
};

kernel main0_out main0()
{
    main0_out out = {};
    return out;
}

The MSL spec Section 5.1.3. states that kernel functions should return void in MSL but here the return type is a struct containing a float, even though the original spirv assembly specifies a void return type on the function.

The output buffer in that spirv program is however a float so I'm guessing spirv-cross thinks that it should be the return type of the kernel in MSL.

Closing this as it is not an issue in Amber per se.

from amber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.