Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple read/write CS shader with errors when compiled to GLSL #8

Open
pixelnerve opened this issue Dec 5, 2016 · 0 comments
Open

Comments

@pixelnerve
Copy link

pixelnerve commented Dec 5, 2016

Hello there,
I'm having a weird error when compiling a simple CS shader to GLSL.
Below is the HLSL shader i'm using and what i found to be weird on the generated GLSL code.

RWBuffer<float4>   BufferOutput            : register( u0 );
RWBuffer<float4>     PositionBuffer         	: register( u1 );
RWBuffer<float4>     RotationBuffer          : register( u2 );

[numthreads(32, 32, 1)]
void main( uint3 DispatchThreadID : SV_DispatchThreadID )
{
    uint globalIndex = DispatchThreadID.y * NUM_WORK_GROUPS_X + DispatchThreadID.x;

    if( globalIndex >= NUM_INSTANCES )
        return;

    int3 outputIndex = (uint3)( globalIndex ) * (uint3)( INSTANCE_STRIDE ) + int3( 0, 1, 2 );
    
    float4 pos = PositionBuffer[ globalIndex ];
    float4 Q = RotationBuffer[ globalIndex ];

    float4 scale = float4( pos.www, 1.0f );

    // Pos, Quat, Scale, float4
    BufferOutput[ outputIndex.x ] = pos;
    BufferOutput[ outputIndex.y ] = Q;
    BufferOutput[ outputIndex.z ] = scale;
}   

It reads PositionBuffer as:

    //LD_UAV_TYPED
    u_xlati1 = floatBitsToInt(imageLoad(PositionBuffer, int(u_xlatu0.x)));

and writes as:

    //STORE_UAV_TYPED
    imageStore(BufferOutput, u_xlati0.x, intBitsToFloat(u_xlati1).yzwx);

Another thing is , scale writes looks wrong. it writes .xxxw

    //MOV
    u_xlati1.w = 0;
    //Instruction 3057
    //STORE_UAV_TYPED
    imageStore(BufferOutput, u_xlati0.w, intBitsToFloat(u_xlati1).xxxw);

This is the full generated GLSL code:

 #version 440 core
#extension GL_ARB_explicit_attrib_location : require
#extension GL_ARB_explicit_uniform_location : require
#extension GL_ARB_shading_language_420pack : require

layout(binding = 3, std140) uniform InstanceData {
    vec4 CustomInputParams0;
    vec4 InstanceDataReserved[15];
};
writeonly layout(binding=0) uniform imageBuffer BufferOutput;
readonly layout(binding=1, rgba32f) highp uniform imageBuffer PositionBuffer;
readonly layout(binding=2, rgba32f) highp uniform imageBuffer RotationBuffer;
ivec4 u_xlati0;
uvec2 u_xlatu0;
ivec4 u_xlati1;
ivec4 u_xlati2;
int u_xlati3;
bool u_xlatb3;
layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
void main()
{
    //Instruction 3044
    //FTOU
    u_xlatu0.xy = uvec2(CustomInputParams0.yx);
    //Instruction 3045
    //IMAD
    u_xlatu0.x = gl_GlobalInvocationID.y * u_xlatu0.x + gl_GlobalInvocationID.x;
    //Instruction 3046
    //UGE
    u_xlatb3 = u_xlatu0.x>=u_xlatu0.y;
    //Instruction 3047
    //IF
    if(u_xlatb3){
        //Instruction 3048
        //RET
        return;
        //Instruction 3049
    //ENDIF
    }
    //Instruction 3050
    //LD_UAV_TYPED
    u_xlati1 = floatBitsToInt(imageLoad(PositionBuffer, int(u_xlatu0.x)));
    //Instruction 3051
    //LD_UAV_TYPED
    u_xlati2 = floatBitsToInt(imageLoad(RotationBuffer, int(u_xlatu0.x)));
    //Instruction 3052
    //IMUL
    u_xlati3 = int(u_xlatu0.x) * 3;
    //Instruction 3053
    //IMAD
    u_xlati0.xzw = ivec3(u_xlatu0.xxx) * ivec3(3, 3, 3) + ivec3(0, 1, 2);
    //Instruction 3054
    //STORE_UAV_TYPED
    imageStore(BufferOutput, u_xlati0.x, intBitsToFloat(u_xlati1).yzwx);
    //Instruction 3055
    //STORE_UAV_TYPED
    imageStore(BufferOutput, u_xlati0.z, intBitsToFloat(u_xlati2));
    //Instruction 3056
    //MOV
    u_xlati1.w = 0;
    //Instruction 3057
    //STORE_UAV_TYPED
    imageStore(BufferOutput, u_xlati0.w, intBitsToFloat(u_xlati1).xxxw);
    //Instruction 3058
    //RET
    return;
}

On a final note, i was able to get proper GLSL code by wrapping the pos.www with a abs(). so:

float4 scale = float4( abs(pos.www), 1.0f );

That worked

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

No branches or pull requests

1 participant