From mboxrd@z Thu Jan 1 00:00:00 1970
From: bugzilla-daemon@freedesktop.org
Subject: [Bug 104492] Compute Shader: Wrong alignment when assigning struct
value to structured SSBO
Date: Thu, 04 Jan 2018 14:45:22 +0000
Message-ID:
Bug ID
104492
Summary
Compute Shader: Wrong alignment when assigning struct value t=
o structured SSBO
Product
Mesa
Version
17.2
Hardware
x86-64 (AMD64)
OS
Linux (All)
Status
NEW
Severity
normal
Priority
medium
Component
Drivers/Gallium/radeonsi
Assignee
dri-devel@lists.freedesktop.org
Reporter
florian.will@googlemail.com
QA Contact
dri-devel@lists.freedesktop.org
Created attachment 136547 [details]=
a>
Code to reproduce this issue. Requires SDL2.
Hi,
I'm trying to get the Banshee 3D engine
<https://github.=
com/BearishSun/BansheeEngine> working on my hardware (HD 7870)
using Mesa radeonsi (amdgpu kernel module). I use 17.2.4-0ubuntu1~17.10.1 f=
rom
the Ubuntu artful-proposed archive.
It uses a compute shader that reads a texture cube and writes 6 sets of
coefficients into a shader storage buffer object. Details are not important=
as
I have isolated the (probably) incorrect driver behaviour and created a much
simpler program that triggers the same issue.
In short: Let's say we have a GLSL struct and access the SSBO through a
dynamically-sized array of that struct type using the std430 layout, like t=
his:
struct ResultRecord
{
float a[10];
float b[10];
float c[10];
float weight;
};
layout(std430) buffer gOutput
{
ResultRecord ssb[];
};
Then a simple assignment of a local variable of the same struct type to ssb=
[i]
writes the floats into incorrect buffer offsets, because b, c and "wei=
ght" are
placed as if the array elements in a, b and c were vec4-aligned instead of
float-aligned, tripling the size of a, b and c.
Code that triggers it is like this, which should hopefully be valid GLSL (a=
nd
makes more sense the way it is used in Banshee 3D):
ResultRecord result;
// ... populate result ...
ssb[gl_LocalInvocationIndex] =3D result;
The test program is available here and contains a (maybe too) detailed
explanation and three program variations that fix the issue:
=
https://gist.github.com/w-flo/b1a5791749eea5f36cb54628037ba2bf
But I'll also attach it to this bug report.
Looking at the RADEON_DUMP_SHADERS=3D1 output, I think that the bug is alre=
ady
visible in the TGSI dump, as explained in the comment at the top of my
reproducer program. I'll attach the output (it's possibly based on an older
version of the reproducer).