1

I have few textures that I want to set in my HLSL shader as array. Each texture is represented as ID3D11ShaderResourceView*. Each texture may be DIFFERENT size.

Now, If I set them in D3D as array:

ID3D11ShaderResourceView* m_array[3];

    m_array[0] = ...;
    m_array[1] = ...;
    m_array[2] = ...;

    m_deviceContext->PSSetShaderResources(
        0,  // Start slot
        3,  // Nb of textures
        m_array); // Array

And in my HLSL shader I declared:

Texture2D       g_textures[3];

Will it be mapped correctly?

2
  • Is there a reason you cannot try and see the result? Commented Apr 6, 2015 at 9:49
  • We are rebuilding our engine and we want to know if our assumptions are correct. Commented Apr 6, 2015 at 9:59

1 Answer 1

1

This is in general a method you can use to map texture arrays from runtime to shader execution. It does not matter that the texture dimensions in the array match, however, you may need to account for this within your shader code, depending on exactly how you are sampling the textures.

Also, in your HLSL, you making the assumption that the g_textures array is assigned to slot 0, so if for some reason it doesn't actually go there (eg. there is another texture resource that comes before it in the shader source), then you won't be setting the intended resource to the correct slot. I find it's better to map them explicitly, eg:

Texture2D g_textures[3] : register(t0);

If there is a collision, it will be found at (shader) compile time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.