Kinc icon indicating copy to clipboard operation
Kinc copied to clipboard

DirectX 11 render bug when not using all vertex input

Open juakob opened this issue 5 years ago • 6 comments

how to reproduce: don't use all vertex info in your code in a vertex shader in directx 11 bug result: it mixes the inputs, example: Lubos tutorial 7 http://kodegarden.org/#c9fd447c82cc95428d974ecddd487bdcff2a2564 it has a nor in the vertex shader that is not use in the code, if you use all inputs by adding to simple.vert.glsl the line vec2 norm=nor+vec2(1.0); the shader works as expected.

juakob avatar Aug 16 '19 07:08 juakob

there is a typo in the shader code, it should be in vec3 nor; instead of in vec2 nor; but its irrelevant to the bug if you fix it

juakob avatar Aug 16 '19 07:08 juakob

decompile generated shader (using normal as a vec3)

// // Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384 // // // Buffer Definitions: // // cbuffer $Globals // { // // float4x4 mvp; // Offset: 0 Size: 64 // // } // // // Resource Bindings: // // Name Type Format Dim HLSL Bind Count // ------------------------------ ---------- ------- ----------- -------------- ------ // $Globals cbuffer NA NA cb0 1 // // // // Input signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // TEXCOORD 0 xyz 0 NONE float
// TEXCOORD 1 xyz 1 NONE float xyz // TEXCOORD 2 xy 2 NONE float xy
// // // Output signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // TEXCOORD 0 xy 0 NONE float xy
// SV_Position 0 xyzw 1 POS float xyzw // 0x00000000: vs_4_0 0x00000008: dcl_constantbuffer CB0[4], immediateIndexed 0x00000018: dcl_input v1.xyz 0x00000024: dcl_input v2.xy 0x00000030: dcl_output o0.xy 0x0000003C: dcl_output_siv o1.xyzw, position 0x0000004C: dcl_temps 2 0x00000054: mov o0.xy, v2.xyxx 0x00000068: mov r0.xyz, v1.xyzx 0x0000007C: mov r0.w, l(1.000000) 0x00000090: dp4 r1.x, r0.xyzw, cb0[2].xyzw 0x000000B0: dp4 r1.y, r0.xyzw, cb0[3].xyzw 0x000000D0: add r1.x, r1.y, r1.x 0x000000EC: mov o1.w, r1.y 0x00000100: mul o1.z, r1.x, l(0.500000) 0x0000011C: dp4 o1.x, r0.xyzw, cb0[0].xyzw 0x0000013C: dp4 o1.y, r0.xyzw, cb0[1].xyzw 0x0000015C: ret // Approximately 11 instruction slots used

imagen

juakob avatar Aug 16 '19 16:08 juakob

drawing fine imagen drawing with normals as pos imagen drawing with normals as pos shader with the typo imagen

juakob avatar Aug 16 '19 17:08 juakob

I think the problem is not in kinc, but in the shader compiler, because the index are set wrong here https://github.com/Kode/Kinc/blob/master/Backends/Graphics4/Direct3D11/Sources/Kore/ShaderImpl.cpp#L60

juakob avatar Aug 16 '19 18:08 juakob

Hey, it's ok, I have enough information here ;) Also no need to decompile the shaders, just have a look at the hlsl files in the build dir.

RobDangerous avatar Aug 16 '19 18:08 RobDangerous

hahah I was just trying to narrow the problem cool didn't know you could see the hlsl files have fun =)

juakob avatar Aug 16 '19 19:08 juakob