Bug 27403 - GLSL struct causing "Invalid src register file ..." error
GLSL struct causing "Invalid src register file ..." error
Status: RESOLVED FIXED
Product: Mesa
Classification: Unclassified
Component: Mesa core
7.6
x86-64 (AMD64) Linux (All)
: medium normal
Assigned To: Eric Anholt
:
Depends on:
Blocks: 29044
  Show dependency treegraph
 
Reported: 2010-03-31 15:56 UTC by Brian Hall
Modified: 2010-08-25 23:43 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Hall 2010-03-31 15:56:06 UTC
GLSL fragment shader is producing this error:

Mesa 7.7.1 implementation error: Invalid src register file 12 in get_src_register_pointer()
Please report at bugzilla.freedesktop.org

I've reduced the code down as much as I could while still reproducing the bug:



--- shader.frag --------------

uniform sampler3D volShadSampler0;

struct VolShad
{
    sampler3D texture;
    int       samples;
    int       channels;
    mat4      worldToScreen;
};

vec3 testfunc(VolShad vs, vec3 p)
{
    return vec3(1.0, 1.0, 1.0);
}

void main()
{
    // (Initializing the VolShad struct this way also causes the error)
    //VolShad volShad0 = VolShad(volShadSampler0, 8, 3, mat4(0.987538, 0.911446, 0.626908, 0.626908, 0, 2.20361, -0.496881, -0.49688, 1.03169, -0.872442, -0.600081, -0.600081, -47.4917, 35.4831, 75.2649, 75.3648));

    VolShad volShad0;
    volShad0.texture = volShadSampler0;
    volShad0.texture = 8;
    volShad0.channels = 3;
    volShad0.worldToScreen = mat4(0.987538, 0.911446, 0.626908, 0.626908, 0, 2.20361, -0.496881, -0.49688, 1.03169, -0.872442, -0.600081, -0.600081, -47.4917, 35.4831, 75.2649, 75.3648);

    vec3 outputColor = testfunc(volShad0, vec3(1, 1, 1));
    gl_FragColor = vec4(1, 1, 1, 1);
}
Comment 1 Ian Romanick 2010-04-01 21:18:05 UTC
(In reply to comment #0)
> uniform sampler3D volShadSampler0;
> 
> struct VolShad
> {
>     sampler3D texture;
>     int       samples;
>     int       channels;
>     mat4      worldToScreen;
> };

[snip]

>     VolShad volShad0;
>     volShad0.texture = volShadSampler0;
>     volShad0.texture = 8;

This shouldn't compile.  It is invalid to assign 8 to a sampler3D.
Comment 2 Brian Hall 2010-04-01 21:43:20 UTC
Oops, I'm sorry.  That's a typo as I was cleaning it up for submission.  It should read:

VolShad volShad0;
volShad0.texture = volShadSampler0;
volShad0.samples = 8;

It seems that having the sampler3D as a member of the struct is causing the problem.  I was able to workaround it for now by removing the "texture" field from the struct and carrying it along as a separate argument to my function.
Comment 3 Eric Anholt 2010-08-17 09:49:25 UTC
There is a piglit testcase for this now: glsl-fs-uniform-sampler-struct
Comment 4 Ian Romanick 2010-08-25 18:06:24 UTC
(In reply to comment #2)
> Oops, I'm sorry.  That's a typo as I was cleaning it up for submission.  It
> should read:
> 
> VolShad volShad0;
> volShad0.texture = volShadSampler0;
> volShad0.samples = 8;

Which is still invalid.  From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:

    "Samplers cannot be treated as l-values; hence cannot be used as
     out or inout function parameters, nor can they be assigned into."

I notice that Nvidia's driver accepts this shader, but their compiler is clearly wrong here.

I'm leaving the bug open because:

1. glsl-fs-uniform-sampler-struct tests legal behavior and fails.

2. The glsl2 compiler accepts this invalid shader.

I've added two tests to piglit, sampler-01.frag and sampler-02.frag, for this issue.
Comment 5 Eric Anholt 2010-08-25 23:43:53 UTC
commit c735d85395f8f0c0a71b04ebc728390970271fe2
Author: Eric Anholt <eric@anholt.net>
Date:   Wed Aug 25 23:27:56 2010 -0700

    glsl: Don't consider things with a type containing a sampler as an lvalue.
    
    We had ad-hoc handled some common cases by flagging sampler-typed
    variables as read_only, and rejected initializers of samplers.
    However, people could sneak them in in all sorts of surprising ways,
    like using whole-array or structure assignment.
    
    Fixes:
    glslparsertest/glsl2/sampler-01.frag
    glslparsertest/glsl2/sampler-03.frag
    glslparsertest/glsl2/sampler-04.frag
    glslparsertest/glsl2/sampler-06.frag
    
    Bug #27403.