Skip to content

Fixed array arguments during conversion from HLSL to GLSL#790

Open
Majrusz wants to merge 1 commit intoDiligentGraphics:masterfrom
Majrusz:master
Open

Fixed array arguments during conversion from HLSL to GLSL#790
Majrusz wants to merge 1 commit intoDiligentGraphics:masterfrom
Majrusz:master

Conversation

@Majrusz
Copy link
Copy Markdown

@Majrusz Majrusz commented May 6, 2026

Hello, I think I found a bug in HLSL2GLSLConverterLib where array members within an HLSL shader output structure are incorrectly translated into scalar (non-array) out variables in GLSL. This mismatch results in compilation error: error C1035: assignment of incompatible types.

Minimal Example

Vertex shader

struct VSInput {
    float3 pos : ATTRIB0;
};

struct PSInput {
    float4 pos : SV_POSITION;
    float4 offsets[2] : OFFSET; // here is the problematic array
};

void main(in VSInput VSIn, out PSInput PSIn) {
    PSIn.pos = float4(VSIn.pos, 1.0) + PSIn.offsets[0] + PSIn.offsets[1];
}

Code

    Diligent::IRenderDevice* RenderDevice = ...;
    std::string Source = ...;
    
    Diligent::ShaderCreateInfo ShaderCI;
    ShaderCI.SourceLanguage = Diligent::SHADER_SOURCE_LANGUAGE_HLSL;
    ShaderCI.CompileFlags = Diligent::SHADER_COMPILE_FLAG_PACK_MATRIX_ROW_MAJOR;
    ShaderCI.Desc.UseCombinedTextureSamplers = true;
    ShaderCI.Desc.ShaderType = Diligent::SHADER_TYPE_VERTEX;
    ShaderCI.Source = Source.c_str();

    Diligent::RefCntAutoPtr<Diligent::IShader> Shader;
    RenderDevice->CreateShader(ShaderCI, &Shader);

HLSL2GLSLConverterLib Output

// ...
struct VSInput {
    float3 pos;
};

struct PSInput {
    float4 pos;
    float4 offsets[2];
};

layout(location = 0) in float3 _vsin_VSIn_pos;
out float4 _PSIn_offsets; // <-------------------------- missing [2]

#define _RETURN_ {\
_SET_GL_POSITION(PSIn.pos);\
_PSIn_offsets = PSIn.offsets;\
return;}

void main() {
    VSInput VSIn;
    VSIn.pos = _vsin_VSIn_pos;
    PSInput PSIn;

    PSIn.pos = float4(VSIn.pos, 1.0) + PSIn.offsets[0] + PSIn.offsets[1];
_RETURN_
}

Error message 0(1209) : error C1035: assignment of incompatible types points to _RETURN_ (_PSIn_offsets = PSIn.offsets;)

@Majrusz Majrusz requested a review from TheMostDiligent as a code owner May 6, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant