Skip to main content
GameDev.net gamedev.net
🔒 Locked

cannot access a texture array in precompiled shader

Started by pnt1614 May 7, 2013 at 5:48 AM 4 replies 2.9k views
Original Post
pnt1614
pnt1614

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.

MJP
MJP
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?
kauna
kauna

How do you bind the textures in the program side?

Best regards!

pnt1614
pnt1614

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"
eppo
eppo

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.

pnt1614
pnt1614

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.