microsoft / microsoft/DirectXShaderCompiler

Divide by zero in GetPartReflection when constant buffers have zero-sized arrays.

Open
#6,961 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug incorrect-code
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
There is an issue with a divide by zero when gathering reflection data. In particular, GetPartReflection() is causing a divide by zero exception.

When looking at the shader code, it looks like there was a bug in the raw shader data, with a zero sized array. The compilation was succeeding, but crashing with divide by zero when getting reflection. There was a struct that looked like this:

struct MaterialData
{
float3 diffuseColor;
...
uint4 srv_info[0];
};

ConstantBuffer s_MaterialCb : register(b0,space2);

Removing the srv_info struct fixed it. After discussion, it appears that this line was causing the divide by zero:

https://github.com/microsoft/DirectXShaderCompiler/blob/main/lib/HLSL/DxilContainerReflection.cpp#L997

Steps to Reproduce
While I don't have a full repro case, I can share the specific shader privately if it would help.

Actual Behavior
The output is a divide by zero exception in GetPartReflection().

Environment

  • DXC version: July 2024
  • Host Operating System: Windows 10, Version 22H2, OS Build 19045.5011

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/HLSL/DxilContainerReflection.cpp at the line around 997 referenced in the issue, then trace how GetPartReflection() handles constant-buffer arrays. Reproduce the reflection failure with a shader containing a zero-sized array if possible, and consider the work complete when reflection no longer divides by zero for that input.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.