3
votes

I have a texture and I need to know its dimensions within a pixel shader. This seems like a job for GetDimensions. Here's the code:

Texture2D t: register(t4);
...
float w;
float h;
t.GetDimensions(w, h);

However, this results in an error:

X4532: cannot map expression to pixel shader instruction set

This error doesn't seem to be documented anywhere. Am I using the function incorrectly? Is there a different technique that I should use?

I'm working in shader model 4.0 level 9_1, via DirectX.

1

1 Answers

2
votes

This error usually occurs if a function is not available in the calling shader stage.

Is there a different technique that I should use?

Use shader constants for texture width and height. It saves instructions in the shader, which may also be better performance-wise.