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: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0478565054==" Return-path: Received: from culpepper.freedesktop.org (culpepper.freedesktop.org [131.252.210.165]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C44D6E14C for ; Thu, 4 Jan 2018 14:45:22 +0000 (UTC) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============0478565054== Content-Type: multipart/alternative; boundary="15150771220.F3DD6f.31576"; charset="UTF-8" --15150771220.F3DD6f.31576 Date: Thu, 4 Jan 2018 14:45:22 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://bugs.freedesktop.org/ Auto-Submitted: auto-generated https://bugs.freedesktop.org/show_bug.cgi?id=3D104492 Bug ID: 104492 Summary: Compute Shader: Wrong alignment when assigning struct value to 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 --> https://bugs.freedesktop.org/attachment.cgi?id=3D136547&action=3Dedit Code to reproduce this issue. Requires SDL2. Hi, I'm trying to get the Banshee 3D engine working on my hardware (HD 78= 70) 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 "weight" = 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). --=20 You are receiving this mail because: You are the assignee for the bug.= --15150771220.F3DD6f.31576 Date: Thu, 4 Jan 2018 14:45:22 +0000 MIME-Version: 1.0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://bugs.freedesktop.org/ Auto-Submitted: auto-generated
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]
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).


You are receiving this mail because:
  • You are the assignee for the bug.
= --15150771220.F3DD6f.31576-- --===============0478565054== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVsCg== --===============0478565054==--