Bug 107276

Summary: radv: OpBitfieldUExtract returns incorrect result when count is zero
Product: Mesa Reporter: Philip Rebohle <philip.rebohle>
Component: Drivers/Vulkan/radeonAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact: mesa-dev
Severity: normal    
Priority: medium CC: fdsfgs, ximik87
Version: git   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: One of the affected shaders (GLSL version)
Workaround that fixes the rendering issue
Final image (correct)
Final image (broken)
Demo app that does not trigger the problem

Description Philip Rebohle 2018-07-18 13:30:47 UTC
Created attachment 140691 [details]
One of the affected shaders (GLSL version)

Hello,

when building Mesa with LLVM 7.0-svn, OpBitfieldUExtract sometimes returns the original source operand instead of zero when the bit count is zero. With LLVM 6.0.1, it works as expected.

This causes the following bug in DXVK:
https://github.com/doitsujin/dxvk/issues/497

Here's a renderdoc capture (recorded on Polaris) showing the issue:
https://mega.nz/#!8W5nDTxT!P7PI4BZ_gpmZDIoh1Iziq0PHpLp448hiUqJN9iEhukg

The attached shader is a GLSL version of the vertex shader used in the bookmarked draw call. I added some comments around like 220 for observed vs. expected behaviour of the shader code.

I tried to reproduce the problem outside of DXVK, but had no luck so far: A small demo app testing the GLSL bitfieldExtract function in a compute shader always returns the correct values.

Handling the count = 0 case explicitly in the NIR->LLVM translation fixes the issue in Far Cry 5.

Regards,
- Philip
Comment 1 Philip Rebohle 2018-07-18 13:31:17 UTC
Created attachment 140692 [details] [review]
Workaround that fixes the rendering issue
Comment 2 Philip Rebohle 2018-07-18 13:32:01 UTC
Created attachment 140693 [details]
Final image (correct)
Comment 3 Philip Rebohle 2018-07-18 13:32:20 UTC
Created attachment 140694 [details]
Final image (broken)
Comment 4 Philip Rebohle 2018-07-18 13:35:23 UTC
Created attachment 140695 [details]
Demo app that does not trigger the problem

I used this small sample app in an attempt to reproduce the problem, but for me it always returns 0 for the count=0 case for some reason.

Please note that the queue family and memory type indices are hardcoded.
Comment 6 Gregor M√ľnch 2018-07-23 08:57:41 UTC
*** Bug 107156 has been marked as a duplicate of this bug. ***

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.