Skip to content

Commit

Permalink
MSL: Fix emission of bindless helper template for bindless SSBO.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKristian-Work committed Oct 14, 2024
1 parent 208adcd commit 1b97ecd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"

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

using namespace metal;

template<typename T>
struct spvDescriptor
{
T value;
};

template<typename T>
struct spvDescriptorArray
{
spvDescriptorArray(const device spvDescriptor<T>* ptr) : ptr(&ptr->value)
{
}
const device T& operator [] (size_t i) const
{
return ptr[i];
}
const device T* ptr;
};

struct SSBO
{
float4 a;
};

constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);

struct spvDescriptorSetBuffer0
{
spvDescriptor<device SSBO *> ssbos [[id(0)]][1] /* unsized array hack */;
};

kernel void main0(const device spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]])
{
spvDescriptorArray<device SSBO*> ssbos {spvDescriptorSet0.ssbos};

ssbos[gl_WorkGroupID.x]->a += float4(2.0);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 450
#extension GL_EXT_nonuniform_qualifier : require
layout(local_size_x = 1) in;

layout(set = 0, binding = 0) buffer SSBO
{
vec4 a;
} ssbos[];

void main()
{
ssbos[gl_WorkGroupID.x].a += 2.0;
}
1 change: 1 addition & 0 deletions spirv_msl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13874,6 +13874,7 @@ void CompilerMSL::entry_point_args_discrete_descriptors(string &ep_args)
}
else
{
add_spv_func_and_recompile(SPVFuncImplVariableDescriptor);
ep_args += "const device spvDescriptor<" + get_argument_address_space(var) + " " +
type_to_glsl(type) + "*>* ";
}
Expand Down

0 comments on commit 1b97ecd

Please sign in to comment.