Discussion:
Array reference can not be used as an l-value???
(too old to reply)
Scythen
2005-03-24 19:05:04 UTC
Permalink
This is what I tried to do:

weights[numWeights-1] = 1;

Which results in the error "Array reference can not be used as an l-value"

However, this works fine:

weights[1] = 1;

Why, and is there a way around this?
Robert Dunlop [MS MVP]
2005-03-25 12:52:10 UTC
Permalink
Post by Scythen
weights[numWeights-1] = 1;
Which results in the error "Array reference can not be used as an l-value"
weights[1] = 1;
Why, and is there a way around this?
HLSL is limited by the limitations of the underlying capabilities provided
by the assembly language that they must compile to. The operation you
specify requires relative addressing of registers, which is very limited:

1. Constant registers can be relatively addressed with the a0 register in
all vertex shader versions.
2. Constant registers can be relatively addressed with either the a0 or aL
loop counter in VS2.x and VS3.0
3. Color input registers can be relatively addressed with the aL loop
counter in PS3.0

Note that all of the above operations apply to read-only registers, none of
which could be l-values.

As for why weights[1] works, since the index is a constant it really
references a specific value, and can be mapped to a specific register at
compile time.

Assuming numWeights is an constant input to the shader, then you might be
able to do this by declaring it as a parameter to the shader function with
the "uniform" usage, and specify the appropriate number of weights when
specifying your shaders in the technique - this would likely require you to
use a separate technique for each possible value of numWeights. This could
allow the compiler to convert the array reference to a static value
reference, creating shader functions for each configuration specified by
your techniques.
--
Robert Dunlop
The X-Zone
http://www.directxzone.org/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not
reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation
with Microsoft.
Armigus
2009-07-02 19:21:02 UTC
Permalink
That's not good news as I want to do this:

texture mapAtlas;
sampler atlasSampler = sampler_state
{
Texture = <mapAtlas>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};

struct VS_INPUT {
float4 position : POSITION;
float4 uv : TEXCOORD0;
float tile : COLOR0;
};

struct VS_OUTPUT
{
float4 position : POSITION;
float4 uv : TEXCOORD0;
float4x4 blend : COLOR0;
};

VS_OUTPUT Transform(VS_INPUT In)
{
VS_OUTPUT Out = (VS_OUTPUT)0;

Out.position = mul( In.position , wvp);
Out.uv = In.uv;
float4x4 weights = 0;
float row = floor(In.tile*0.25);
float col = fmod(In.tile,4);
weights[col][row] = 1; // *error*

Out.blend = weights;

return Out;
}

Put more simply I want to pass in an index as part of the vertex data and
set a specific blend weight in a float4x4 based on its value. Is this
feasible?
Post by Robert Dunlop [MS MVP]
Post by Scythen
weights[numWeights-1] = 1;
Which results in the error "Array reference can not be used as an l-value"
weights[1] = 1;
Why, and is there a way around this?
HLSL is limited by the limitations of the underlying capabilities provided
by the assembly language that they must compile to. The operation you
1. Constant registers can be relatively addressed with the a0 register in
all vertex shader versions.
2. Constant registers can be relatively addressed with either the a0 or aL
loop counter in VS2.x and VS3.0
3. Color input registers can be relatively addressed with the aL loop
counter in PS3.0
Note that all of the above operations apply to read-only registers, none of
which could be l-values.
As for why weights[1] works, since the index is a constant it really
references a specific value, and can be mapped to a specific register at
compile time.
Assuming numWeights is an constant input to the shader, then you might be
able to do this by declaring it as a parameter to the shader function with
the "uniform" usage, and specify the appropriate number of weights when
specifying your shaders in the technique - this would likely require you to
use a separate technique for each possible value of numWeights. This could
allow the compiler to convert the array reference to a static value
reference, creating shader functions for each configuration specified by
your techniques.
--
Robert Dunlop
The X-Zone
http://www.directxzone.org/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not
reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation
with Microsoft.
legalize+ (Richard [Microsoft Direct3D MVP])
2009-07-02 19:44:25 UTC
Permalink
[Please do not mail me a copy of your followup]
[...]
Have you tried it on a modern version of HLSL? Robert Dunlop hasn't
been an MVP for several years. That post doesn't even show up on the
MS news server.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
Loading...