Justin R.
Justin R.

Reputation: 24021

HLSL: Getting texture dimensions in a pixel shader

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.

Upvotes: 4

Views: 12384

Answers (1)

Lucius
Lucius

Reputation: 3745

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.

Upvotes: 3

Related Questions