0

In glsl, array = int[8]( 0, 0, 0, 0, 0, 0, 0, 0 ); works fine, but in hlsl this doesn't seem to be the case. It doesn't seem to be mentioned in any guides how you do this. What exactly am I meant to do?

Logos King
  • 121
  • 1
  • 6

1 Answers1

1

For example, like this:

int array[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

Edit:

Ah, you mean array assignment. It seems like that is not possible for now. In addition to trying every possible sensible option, I cross-compiled simple glsl code to hlsl code using glslcc (which uses spirv-cross).

GLSL code:

#version 450

layout (location = SV_Target0) out vec4 fragColor;

void main() 
{
    int array[4] = {0, 0, 0, 0}; 
    array = int[4]( 1, 0, 1, 0);
    fragColor = vec4(array[0], array[1], array[2], array[3]);
}

HLSL code:

static const int _13[4] = { 0, 0, 0, 0 };
static const int _15[4] = { 1, 0, 1, 0 };

static float4 fragColor;

struct SPIRV_Cross_Output
{
    float4 fragColor : SV_Target0;
};

void frag_main()
{
    int array[4] = _13;
    array = _15;
    fragColor = float4(float(array[0]), float(array[1]), float(array[2]), float(array[3]));
}

SPIRV_Cross_Output main()
{
    frag_main();
    SPIRV_Cross_Output stage_output;
    stage_output.fragColor = fragColor;
    return stage_output;
}

As you can see, in this case the equivalent hlsl code uses static const array and then assigns it since that kind of array assignment is allowed in HLSL (and makes a deep copy unlike in C/C++).

mateeeeeee
  • 885
  • 1
  • 6
  • 15