Skip to content

Segfault in CopyPropagateArrays #2869

@ehsannas

Description

@ehsannas

HLSL shader originally posted in microsoft/DirectXShaderCompiler#2423. May be related to legalization.

struct MyConstantBuffer {
    float4 myParam1[8];
};

cbuffer myCBuffer : register(b0) {
  MyConstantBuffer myConstantBuffer;
}

struct MyConstantBufferWrapper {
    MyConstantBuffer constants;

    float4 GetParam1(uint index) { return constants.myParam1[index]; }
};

MyConstantBufferWrapper CreateWrapper() {
    MyConstantBufferWrapper wrapper;
    wrapper.constants = myConstantBuffer;
    return wrapper;
};

struct VS_OUTPUT {
    float4  m_ScreenPos  : VS_OUT_POSITION;
};

struct MyStruct {
    uint myIndex;
};

static MyConstantBufferWrapper myWrapper = CreateWrapper();

float4 main(VS_OUTPUT In) : SV_Target {
    MyStruct myStruct = (MyStruct)0;

    // Causes the issue:
    float4 myParam = myWrapper.GetParam1(myStruct.myIndex);

    // Works fine:
    //float4 myParam = myConstantBuffer.myParam1[myStruct.myIndex];

    return myParam;
}

What I see is that AsIntConstant() returns nullptr:

access_chain.push_back(index_const->AsIntConstant()->GetU32());

The attached test.spv.txt is the result of -spirv -fcgl -O0 from DXC.
test.spv.txt

If I run spirv-opt.exe test.spv.txt -o test.optimized.spv, however, I get the following error rather than the segfault (not sure why):

error: line 101: OpFunctionCall Argument <id> '21[%myWrapper]'s type does not match Function <id> '52[%_ptr_Function_MyConstantBufferWrapper]'s parameter type.
  %47 = OpFunctionCall %v4float %MyConstantBufferWrapper_GetParam1 %myWrapper %param_var_index

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions