Jump to content
  • Advertisement
Sign in to follow this  
pnt1614

cannot access a texture array in precompiled shader

This topic is 1965 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I use fxc compiler tool to compile a hlsl file, then load those binary file into memory and create shaders. But the problem is I cannot access to other textures in an array of texture (Texture2D arr[10]) except the first one, in the sense that the color I get as sampling is black. However, everything is fine if the hlsl file is compiled at runtime.

 

The shader source code: 

Texture2D g_pTextures[10] : register(t4);

if (Texture_ID == 0)
{
	result = g_pTextures[0].SampleLevel(g_samLinear, uv_temp, 0.0f);
	color1 = g_pTextures[0].SampleLevel(g_samLinear, uv1, 0.0f);
	color2 = g_pTextures[0].SampleLevel(g_samLinear, uv2, 0.0f);
}
else
{
	result = g_pTextures[1].SampleLevel(g_samLinear, uv_temp, 0.0f);
	color1 = g_pTextures[1].SampleLevel(g_samLinear, uv1, 0.0f);
	color2 = g_pTextures[1].SampleLevel(g_samLinear, uv2, 0.0f);
}

 

Is there anybody helps me, please? Thank in advanced.

Edited by steven166

Share this post


Link to post
Share on other sites
Advertisement
There's no difference between compiling a shader offline and compiling at runtime, assuming that you use the same compiler version and the same compilation settings. Can you provide more information about your code and your problem?

Share this post


Link to post
Share on other sites

Thank everybody for the reply,

 

For binding the textures:

pd3dImmediateContext->PSSetSamplers( 0, 1, &g_pSamLinear );

//g_sFileNames stores list of texture names
//g_pTextures is two dimensional array of shader resource view
pd3dImmediateContext->PSSetShaderResources(4, g_sFileNames.size(), g_pTextures);

As I sampling at the current pixel, everything is fine if the current pixel use the first texture in the array, otherwise the color is black :(. 

 

For pre-compiling using fxc, I used

fxc simple.hlsl /T vs_5_0 /EVS /Fo "VSCompile.cso"

and 

fxc simple.hlsl /T ps_5_0 /EPS /Fo "PSCompile.cso"

Share this post


Link to post
Share on other sites
Texture2D g_pTextures[10] : register(t4); 

I've never seen this syntax before. Only a single texture object can be bound to a texture register, so are the remaining textures consecutively mapped to the registers #5, #6 etc. by the compiler? Otherwise I'd say you need to use a Texture2DArray object. 

Share this post


Link to post
Share on other sites

Thank eppo for reply, the syntax you see is right. The first texture will be bound to the 4th slot, and the second texture at the 5th slot...etc. About Texture2DArray, I have tried to use it, but there is a problem with texture's resolution if there are many textures.

Edited by steven166

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!