cannot access a texture array in precompiled shader

Started by
4 comments, last by pnt1614 10 years, 11 months ago

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.

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?

How do you bind the textures in the program side?

Best regards!

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"

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.

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.

This topic is closed to new replies.

Advertisement