James-Jones / HLSLCrossCompiler

Other
468 stars 81 forks source link

ld instructions with srcResource swizzling getting compiled incorrectly #24

Closed lbavoil closed 10 years ago

lbavoil commented 10 years ago

This DXASM instruction: ld_indexable(texture2d)(float,float,float,float) r0.xyw, r3.xyzw, t1.xywz

is getting compiled incorrectly to this GLSL (ignoring the .xywz swizzling of "t1.xywz"): " Temp[0].xyw = texelFetch(g_t1, ivec2((Temp_int[3]).xy), 0).xyw;\n"

… which I think should be:

" Temp[0].xyw = texelFetch(g_t1, ivec2((Temp_int[3]).xy), 0).xyz;\n"

See http://msdn.microsoft.com/en-us/library/windows/desktop/hh447172(v=vs.85).aspx "The swizzle on srcResource determines how to swizzle the 4-component result coming back from the texture load, after which .mask on dest determines which components in dest get updated."

James-Jones commented 10 years ago

A fix has been pushed, Could you verify it fixes your problem?

lbavoil commented 10 years ago

Thanks! Would it be possible for you to also solve issue #23? Right now I am not able to test with the latest version from main because my shaders produce corruption due to issue #23.

lbavoil commented 10 years ago

I have tried the latest version (which includes your fix) and this particular DXASM instruction is now compiled differently, but still incorrectly. I am now getting this:

" Temp_int[0].xyw = floatBitsToInt(texelFetch(g_t1, ivec2((Temp_int[3]).xy), int(0x0)).xywz.xyz);\n"

But the output should be:

" Temp_int[0].xyw = floatBitsToInt(texelFetch(g_t1, ivec2((Temp_int[3]).xy), int(0x0)).xywz.xyw);\n"

FYI, here is what the instruction is in the HLSL:

"float3 N = Texture.Load(int3(IN.pos.xy, 0)).xyz;"

James-Jones commented 10 years ago

The dest mask controls which components in the dest are updated and in this case it wants to update xyw not xyz. So r0.xyw, r3.xyzw, t1.xywz means r0.xyw = vec3( sample(t1, r3.xy).xywz).xyw ) ignoring zw on r3 because this a 2D texture Fix pushed.

lbavoil commented 10 years ago

I have verified that the issue is now fixed. Closing.