bgfx icon indicating copy to clipboard operation
bgfx copied to clipboard

Crash parsing DirectX 11 shaders

Open Ravbug opened this issue 5 years ago • 0 comments

Describe the bug BX_CHECK in shader_dxbc.cpp fails:

void parse(const DxbcShader& _src, DxbcParseFn _fn, void* _userData, bx::Error* _err)
    {
        BX_ERROR_SCOPE(_err);

        bx::MemoryReader reader(_src.byteCode.data(), uint32_t(_src.byteCode.size() ) );

        for (uint32_t token = 0, numTokens = uint32_t(_src.byteCode.size() / sizeof(uint32_t) ); token < numTokens;)
        {
            DxbcInstruction instruction;
            uint32_t size = read(&reader, instruction, _err);
            BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); //Fails HERE

Shaders to reproduce: varying.def.sc

vec3 a_position  : POSITION;
vec4 a_normal    : NORMAL;
vec3 v_normal    : NORMAL    = vec3(0.0, 0.0, 1.0);

vertex

$input a_position, a_normal
$output v_normal

#include "common.sh"

void main()
{
    v_normal = a_normal;
    gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );;
}

fragment

$input v_normal

#include "common.sh"

void main()
{
    vec3 normal = normalize(v_normal); //problematic line

    gl_FragColor = vec4(normal,1);    
}

Binary Shaders: shaders.zip

Compilation commands: shaderc.exe -f "vs_default.sc" -o "vertex.bin" -i "bgfx.cmake/bgfx/src" --type vertex --platform windows --varyingdef default_varying.def.sc" --profile vs_5_0

shaderc.exe -f "fs_default.sc" -o "fragment.bin" -i "bgfx.cmake/bgfx/src" --type fragment --platform windows --varyingdef "default_varying.def.sc" --profile ps_5_0

To Reproduce Steps to reproduce the behavior:

  1. Compile the above shaders, or use the attached precompiled versions
  2. Load as shader program in bgfx
  3. Attempt to execute shader program

Expected behavior The shader should execute without crashing, or fail to compile

Additional context OS: Windows 10, Visual Studio 2019 bgfx backend: DirectX11

Ravbug avatar Oct 31 '20 05:10 Ravbug