James-Jones / HLSLCrossCompiler

Other
468 stars 81 forks source link

StructuredBuffers/SSBO #35

Closed pixelnerve closed 8 years ago

pixelnerve commented 8 years ago

@James-Jones Testing a simple structured buffer with float4x4 will result in an invalid GLSL shader with this output:

layout(binding = 0) readonly buffer Block0 {
    mat4 StructuredRes0[];
};

    //LD_STRUCTURED
    Temp[0] = uintBitsToFloat(uvec4(floatBitsToUint(StructuredRes0[0x0].$Element), floatBitsToUint(StructuredRes0[0x0].$Element), floatBitsToUint(StructuredRes0[0x0].$Element), floatBitsToUint(StructuredRes0[0x0].$Element)));

Input HLSL code:

StructuredBuffer<float4x4> WorldTransformData;

VS_OUTPUT main( VS_INPUT IN )
{
    VS_OUTPUT OUT;

    float4 positionOS = float4( IN.PositionIn.xyz, 1.0f );

    float4x4 worldMatrix = WorldTransformData[0];

    float4 positionWS = mul( positionOS, worldMatrix );

    float4 positionCS = mul( positionWS, ViewProjection );

    OUT.Position = positionCS;

    return OUT;
}
James-Jones commented 8 years ago

I'll take a look on Tuesday. Might have more luck using RWStructuredBuffer or a struct with float4x4 member. Also worth looking at Amazon lumberyard source code - last time I checked they were using this project and had made some fixes and enhancements.

James-Jones commented 8 years ago

You also might want to look at the work going on to get hlsl to spirv working in the glslangValidatator. Spirv-cross can turn spirv to glsl and metal.

pixelnerve commented 8 years ago

@James-Jones

My first try was with a full struct used for transforms. Output was different but still invalid. For instance was trying to convert float bits to uint of the matrix not each matrix row or component

I'll look into those suggestions. Thanks

pixelnerve commented 8 years ago

@James-Jones I can confirm that the version of HLSLCrossCompiler from Lumberyard works well. Converts things correctly so far. They also have a version that converts HLSL to Metal. Might be worth a look.

As for glsl validator it's a no go. No compute shaders and other recent features are implemented yet