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

Crash parsing DirectX 11 shaders #2304

Open
Ravbug opened this issue Oct 31, 2020 · 0 comments
Open

Crash parsing DirectX 11 shaders #2304

Ravbug opened this issue Oct 31, 2020 · 0 comments

Comments

@Ravbug
Copy link
Contributor

Ravbug commented Oct 31, 2020

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

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