Passing an array to a shader...

… returns a cute error:

:gobj(error): created-shader: uniform in unknown array: unsupported array subclass.
:gobj(error): Shader encountered an error.

The test case for it is extremely simple… It shouldn’t do anything, but it shouldn’t raise an error either!

import panda3d.core as panda
from direct.directbase.DirectStart import *

arraytest = """//Cg
void vshader(
    in float4 vtx_position: POSITION,
    in float2 vtx_texcoord0: TEXCOORD0,
    out float4 l_position: POSITION,
    out float2 l_texcoord0: TEXCOORD0,
    uniform float4x4 mat_modelproj,
    uniform float array[32]
    )
{
    l_position = mul(mat_modelproj, vtx_position);
    l_texcoord0 = vtx_texcoord0;
}

void fshader(
    in float2 l_texcoord0: TEXCOORD0,
    out float4 o_color: COLOR,
    uniform sampler2D tex_0: TEXUNIT0
    )
{
    o_color = tex2D(tex_0, l_texcoord0);
}"""

base.render.setShader(panda.Shader.make(arraytest))
base.run()

So, what’s going on? Am I missing something? It shouldn’t be the profile… even abrvp1 supports uniform arrays.

I can reproduce the issue. I’m looking into it.

I’m a bit confused why nobody ran into this issue before. We’ve supported parameter arrays in Cg for quite a while now.

I ran into a similar problem, the array support worked well in 1.7.2.
When i changed to 1.8.1 the error was raised.

Is there a workaround?

I’ve registered this as a bug on launchpad with your code, since I’ve hit the same issue when attempting hardware instancing with CG.

bugs.launchpad.net/panda3d/+bug/1207711

rdb has checked in a fix, and its working for me in the latest devel version :slight_smile:

Hello,
I’m experiencing a similar issue to what’s been reported. I’m using the latest devel build (Panda3D-2013.08.06-78.exe).
I’m using the first (top) hardware instancing example from PandaSE here (etc.cmu.edu/projects/pandase/downloads.html).

I just replaced the PTAVecBase4’s with PTA_LVecBase4f and filled it with UnalignedLVecBase4f instead of Vec4 to try to make it work.

Error:

:gobj(error): shader.c: uniform in unknown instances_position: unsupported array
 subclass.
:gobj(error): shader.c: uniform in unknown Ly: unsupported array subclass.
:gobj(error): Shader encountered an error.

Main (snip):

        k = 1000
        input = PTA_LVecBase4f.emptyArray(k);
        count = 0
        for i in range(10):
            for j in range(k/10):
                input[count] = UnalignedLVecBase4f(i*3,j*-8,0,0)
                count += 1
               
        lvec = PTA_LVecBase4f([UnalignedLVecBase4f(-4,0,0,0),UnalignedLVecBase4f(4,0,0,0)]);
        self.ralph.setShaderInput("Ly", input)
        self.ralph.setShaderInput("instances_position", lvec)
        self.ralph.setShader(Shader.load("shader.c"))
        self.ralph.setInstanceCount(k)

Shader.c (snip):

//Cg
//Cg profile gp4vp gp4fp

struct VertexDataOUT{
  float4 o_position  :POSITION;
  float2 o_texcoord0 :TEXCOORD0;
  float3 o_normal    :TEXCOORD1;
  float3 o_objpos    :TEXCOORD2;
};

struct VertexDataIN{
  float4 vtx_position  :POSITION;
  float2 vtx_texcoord0 :TEXCOORD0;
  float3 vtx_normal    :NORMAL0;
  int l_id             :INSTANCEID;
};
//vertex shader
void vshader(VertexDataIN IN,
             out VertexDataOUT OUT,
             uniform float4 instances_position[2],
             uniform float4 Ly[1000],
             uniform float4x4 mat_modelproj)
{	
        float4 vpos = IN.vtx_position + Ly[IN.l_id]; 
	
        OUT.o_position  = mul(mat_modelproj,vpos);
        OUT.o_objpos    = IN.vtx_position;
        OUT.o_texcoord0 = IN.vtx_texcoord0;
        OUT.o_normal    = IN.vtx_normal;	
}

Also want to add: The code reported in my last post doesn’t work with the August 1st or August 2nd devel builds either. Same errors.

Hmm, thats weird.

I just grabbed the same marching ralphs example, changed the PTAVecBase4’s like you did and successfully got the program to run - no errors.

Thank you for testing it out for me.
I just redownloaded the demo and tried it again with the devel build from a few days ago.
The only changes I made are in this code:

        k = 1000
        input = PTA_LVecBase4f.emptyArray(k);
        count = 0
        for i in range(10):
            for j in range(k/10):
                input[count] = UnalignedLVecBase4f(i*3,j*-8,0,0)
                count += 1

               
        
        lvec = PTA_LVecBase4f([UnalignedLVecBase4f(-4,0,0,0),UnalignedLVecBase4f(4,0,0,0)]);

It all compiles fine, no problems. But when it runs, it crashes with the shader errors listed in this thread. Is there something else I should have done to the program?

Also, I’m getting a similar type of error when I run the “instance based flocking demo” from the same page as the other demo. I made no changes to the source and got this:

:gobj(error): /c/Panda3D-1.9.0/Advanced-Shader-Inputs/shaders/advancedInputs.cg:
 uniform in unknown p3d_modelviews: unsupported array subclass.
:gobj(error): Shader encountered an error.

I’m running Windows 7 Home, NVIDIA GeForce 570 (fully updated).

Edit: Just for kicks, I tried out the code the OP posted that seemingly works for most. I’m getting the same error he originally got:

:gobj(error): created-shader: uniform in unknown array: unsupported array subcla
ss.
:gobj(error): Shader encountered an error.

Edit2: The programs are all producing the same errors on Panda 1.7.2, Panda 1.8.1, and dev builds of Panda 1.9.0. Sigh.

Just posting some good news:
The problems I was having were on my end. They weren’t code-related, but there was some sort of conflict causing my cg programs not to run on the dev builds correctly after I ran them on Panda 1.8.1 (and received the initial errors). I simply uninstalled everything and re-installed the newest dev build to fix the issue.
Panda’s fine. Thanks for the help. :slight_smile: