I'm working on a parser which translates HLSL to HLSL/MSL. But valid MSL isn't compiling when passing the depth2d to a class and class ctor. The ctor use allows globals to be referenced as member variables by the MSL which typically passes it's parameters from call to call.
This reports the following which makes no sense. The code is fine with use of texture2d and references, so seems to be a metal compiler bug. It's saying the ctor input needs to be device space, but it's already decleared as such. This limits any use of depth style textures in MSL.
DepthTest.metal:31:16: error: no matching constructor for initialization of 'SamplePSNS'
SamplePSNS shader(shadowMap, sampleBorder);
^ ~~~~~~~~~~~~~~~~~~~~~~~
DepthTest.metal:18:5: note: candidate constructor not viable: address space mismatch in 1st argument ('depth2d<float>'), parameter type must be 'device depth2d<float> &'
SamplePSNS(
^
DepthTest.metal:5:8: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
struct SamplePSNS {
^
DepthTest.metal:5:8: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
#include <metal_stdlib>
using namespace metal;
struct SamplePSNS {
struct InputPS {
float4 position [[position]];
};
device depth2d<float>& shadowMap;
thread sampler& sampleBorder;
float4 SamplePS(InputPS input) {
return shadowMap.sample_compare(sampleBorder, input.position.xy, input.position.z);
};
SamplePSNS(
device depth2d<float>& shadowMap,
thread sampler& sampleBorder)
: shadowMap(shadowMap),
sampleBorder(sampleBorder)
{}
};
fragment float4 SamplePS(
SamplePSNS::InputPS input [[stage_in]],
depth2d<float> shadowMap [[texture(0)]],
sampler sampleBorder [[sampler(0)]])
{
SamplePSNS shader(shadowMap, sampleBorder);
return shader.SamplePS(input);
}