Thread overview
D is trying to parse C and C++ inside strings
Mar 18
Hipreme
Mar 18
Johan
Mar 18
Dennis
March 18

I'm writing Metal shaders right now on my engine and I got the following warning (I use warn as errors so this is giving me nuts as I'll need to refactor my code to hide that string)

string getCoolString()
{
    return q{
        #include <metal_stdlib>
        #include <simd/simd.h>
        using namespace metal;
    };
}

void main()
{
    writeln(getCoolString);
}

In the run.dlang, I get the following error:

Error: d++ cannot find file path for header 'metal_stdlib'
Error Program exited with code 1

In my code, I'm getting the following error:

override string getFrameBufferVertex()
    {
        return q{
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct VertexInput
{
    float2 vPosition;
    float2 vTexST;
};
struct FragmentInput
{
    ///Unused
    float4 position [[position]];
    float2 inTexST;
};

vertex FragmentInput vertex_main(
    uint vertexID [[vertex_id]],
    VertexInput* input [[buffer(1)]]
)
{
    FragmentInput out;
    out.position = float4(input[vertexID].vPosition, 0.0, 1.0);
    out.inTexST = input[vertexID].vTexST;
    return out;
}
};
    }

modules/renderer/source/hip/hiprenderer/backend/metal/mtlshader.d(104,9): Warning: C preprocessor directive #include is not supported

This looks like related to use token string.

March 18

On Saturday, 18 March 2023 at 03:00:46 UTC, Hipreme wrote:

>

I'm writing Metal shaders right now on my engine and I got the following warning (I use warn as errors so this is giving me nuts as I'll need to refactor my code to hide that string)

string getCoolString()
{
    return q{
        #include <metal_stdlib>
        #include <simd/simd.h>
        using namespace metal;
    };
}

void main()
{
    writeln(getCoolString);
}

In the run.dlang, I get the following error:

Error: d++ cannot find file path for header 'metal_stdlib'
Error Program exited with code 1

In my code, I'm getting the following error:

override string getFrameBufferVertex()
    {
        return q{
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct VertexInput
{
    float2 vPosition;
    float2 vTexST;
};
struct FragmentInput
{
    ///Unused
    float4 position [[position]];
    float2 inTexST;
};

vertex FragmentInput vertex_main(
    uint vertexID [[vertex_id]],
    VertexInput* input [[buffer(1)]]
)
{
    FragmentInput out;
    out.position = float4(input[vertexID].vPosition, 0.0, 1.0);
    out.inTexST = input[vertexID].vTexST;
    return out;
}
};
    }

modules/renderer/source/hip/hiprenderer/backend/metal/mtlshader.d(104,9): Warning: C preprocessor directive #include is not supported

This looks like related to use token string.

It's parsing (lexing, even), not trying to parse, D inside the q string literal and the D lexer spits out a warning when it sees #include.

This arguably could be considered a bug inside a q string these days given that their original reason for existing has gone away quite significantly as far as I know.

March 18

On Saturday, 18 March 2023 at 03:00:46 UTC, Hipreme wrote:

>

I'm writing Metal shaders right now on my engine and I got the following warning (I use warn as errors so this is giving me nuts as I'll need to refactor my code to hide that string)

string getCoolString()
{
    return q{
        #include <metal_stdlib>
        #include <simd/simd.h>
        using namespace metal;
    };
}

void main()
{
    writeln(getCoolString);
}

In the run.dlang, I get the following error:

Error: d++ cannot find file path for header 'metal_stdlib'
Error Program exited with code 1

Workaround: put the #include stuff in a normal string:

string getCoolString()
{
    return
    "#include <metal_stdlib>
     #include <simd/simd.h>"
    ~ q{
        using namespace metal;
    };
}

void main()
{
    import std.stdio;
    writeln(getCoolString);
}
March 18

On Saturday, 18 March 2023 at 03:00:46 UTC, Hipreme wrote:

>

This looks like related to use token string.

Filed as https://issues.dlang.org/show_bug.cgi?id=23792

March 21

On Saturday, 18 March 2023 at 03:00:46 UTC, Hipreme wrote:

>

modules/renderer/source/hip/hiprenderer/backend/metal/mtlshader.d(104,9): Warning: C preprocessor directive #include is not supported

This looks like related to use token string.

While the compiler shouldn't do that, token strings are intended to be used for D code. AFAIR the idea is that the syntax highlighter treats them as D, so you can do mixin(format!q{int a = %s;}(5));, and have D syntax coloring for the code inside the string. So putting another language in there is at least dubious.