Jump to content
  • Advertisement
Sign in to follow this  
ogracian

Shader Fragments and D3DXGetShaderConstantTable not working...

This topic is 4951 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

Hello, I am writing a simple code to learn about vertex fragments but I am having trouble using it WITHOUT effect files, the main trouble I am having is that the D3DXGetShaderConstantTable keeps returning a NULL constant table so I cant setup my fragments vars. Here I post the code I am using:
//
// Compile fragments
DWORD compileFlags              = 0;
LPD3DXBUFFER  compileErrors     = NULL;
LPD3DXBUFFER  compiledFragments = NULL;
D3DXGatherFragmentsFromFile"vsFragments.fx", NULL, NULL, compileFlags, &compiledFragments, &compileErrors);	

//
// Create the fragment linker interface
LPD3DXFRAGMENTLINKER fragmentLinker = NULL;
D3DXCreateFragmentLinker(pD3D->GetDevice(), 0, &fragmentLinker);

//
// Add the compiled fragments to fragmentLinker
fragmentLinker->AddFragments((DWORD*)compiledFragments->GetBufferPointer());

//
// Get a handle to each fragment
D3DXHANDLE fragmentHandle[2];
fragmentHandle[0] = (D3DXHANDLE)fragmentLinker->GetFragmentHandleByName("simpleTransformFragment");
fragmentHandle[1] = (D3DXHANDLE)fragmentLinker->GetFragmentHandleByName("rgbSrcConstantFragment");

//
// Link the needed fragments together to form a vertex shader	
LPDIRECT3DVERTEXSHADER9 vertexShader = NULL;
fragmentLinker->LinkVertexShader("vs_1_1", compileFlags, fragmentHandle, 2, &vertexShader, NULL);

//
// Get a pointer to the constant table from the compiled shader
LPD3DXCONSTANTTABLE constantTable;
D3DXGetShaderConstantTable((DWORD *)compiledFragments->GetBufferPointer(), &constantTable); //--------> Here is the TROUBLE, the constant table ALWAYS is NULL.

Thanks in advance, Oscar Edited by Coder: Added source tags [Edited by - Coder on November 29, 2004 3:37:41 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Well as no response yet I will try to ask in a different way :),
Is there a reason why D3DXGetShaderConstantTable return success but the constant table is NULL (maybe compile flags?), or if someone know the correct usage for D3DXGetShaderConstantTable I really appreciate it.

Here is how I am calling D3DXGetShaderConstantTable, it return success but table keeps null.

LPD3DXCONSTANTTABLE constantTable = NULL;
hr = D3DXGetShaderConstantTable((DWORD *)compiledFragments->GetBufferPointer(), &constantTable);

Share this post


Link to post
Share on other sites
Hey, sorry, I did read your question earlier today but I couldn't figure out why it's doing it either. Perhaps there is something amiss in the fragments.fx file, d'ya want to post that source in here so we can have a look?

-Mezz

Share this post


Link to post
Share on other sites
Hi Mezz, dont worry about it.

Well my fragments code are really simply, here I post it:


///////////////////////////////////////////////////////////////////////////////////////////////
// Global vars //
///////////////////////////////////////////////////////////////////////////////////////////////

//
// Constant color (RGB Source : Constant)
float4 g_RGBColor;

//
// Shaders Mtx
float4x4 g_WorldMtx;
float4x4 g_WorldViewMtx;
float4x4 g_WorldViewProjMtx;

//
// App vertex shader
VertexShader g_VS;

///////////////////////////////////////////////////////////////////////////////////////////////
// Helper Fragments //
///////////////////////////////////////////////////////////////////////////////////////////////
void simpleTransformVS( in float3 iPos : POSITION,
out float4 oPos : POSITION)
{
oPos = mul(float4(iPos, 1.0f), g_WorldViewProjMtx);
}

///////////////////////////////////////////////////////////////////////////////////////////////
// RGB Src fragments //
///////////////////////////////////////////////////////////////////////////////////////////////
void rgbSrcWhiteVS(out float4 oColor : COLOR0)
{
oColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
}

void rgbSrcConstantVS(out float4 oColor: COLOR0)
{
oColor = g_RGBColor;
}

///////////////////////////////////////////////////////////////////////////////////////////////
// Fragment declarations //
///////////////////////////////////////////////////////////////////////////////////////////////
vertexfragment rgbSrcWhiteFragment = compile_fragment vs_1_1 rgbSrcWhiteVS();
vertexfragment rgbSrcConstantFragment = compile_fragment vs_1_1 rgbSrcConstantVS();

vertexfragment simpleTransformFragment = compile_fragment vs_1_1 simpleTransformVS();

///////////////////////////////////////////////////////////////////////////////////////////////
// Effect declaration //
///////////////////////////////////////////////////////////////////////////////////////////////

technique doRender
{
pass p0
{
VertexShader = <g_VS>;
PixelShader = NULL;
}
}





The "strange" thing, is if I use the same code with a effect file to access the constants all work fine, so the only thing is
stopping me to use the fragmensts without the effect file support is that the contant table is never filled.

Regards,
Oscar

Share this post


Link to post
Share on other sites
Hi, well finally got it working for some strange reason using the ID3DXFragmentLinker::LinkVertexShader method keep returning the constants table NULL.

The solution is use the ID3DXFragmentLinker::LinkShader Method wich instead of create a LPDIRECT3DVERTEXSHADER9 object, it return a LPD3DXBUFFER object then from this buffer I CAN get the constants table without any trouble.

For last is just needed to create the vertex shader using the
IDirect3DDevice9::CreateVertexShader method.

Here I post the solution in code:



//
// Compile fragments
LPD3DXBUFFER compileErrors = 0;
LPD3DXBUFFER compiledFragments = 0;
DWORD compileFlags = 0;
compileFlags |= D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION;

D3DXGatherFragmentsFromFile("vsFragments.fx", NULL, NULL, compileFlags, &compiledFragments, &compileErrors);

//
// Create the fragment linker interface
LPD3DXFRAGMENTLINKER fragmentLinker = NULL;
D3DXCreateFragmentLinker(pD3D->GetDevice(), 0, &fragmentLinker);

//
// Add the compiled fragments to fragmentLinker
fragmentLinker->AddFragments((DWORD*)compiledFragments->GetBufferPointer());

//
// Get a handle to each fragment
D3DXHANDLE fragmentHandle[2];
fragmentHandle[0] = fragmentLinker->GetFragmentHandleByName("simpleTransformFragment");
fragmentHandle[1] = fragmentLinker->GetFragmentHandleByName("rgbSrcWhiteFragment");

//
// Link shader into vsBuffer
LPD3DXBUFFER vsBuffer = NULL;
fragmentLinker->LinkShader("vs_1_1", compileFlags, fragmentHandle, 2, &vsBuffer, NULL);

//
// Get a pointer to the constant table from the linked shader buffer
LPD3DXCONSTANTTABLE constantTable = NULL;
D3DXGetShaderConstantTable((DWORD *)vsBuffer->GetBufferPointer(), &constantTable);

//
// Create the vertex shader from linked shader buffer
LPDIRECT3DVERTEXSHADER9 vertexShader = NULL;
hr = pD3D->GetDevice()->CreateVertexShader((DWORD*)vsBuffer->GetBufferPointer(), &vertexShader);




PS: The only drawback I see using this method instead the one suggested by DX docs (the one which is no working [:)]) is that this method return a constant table for each linked shader istead of one constant table used by all the fragment in same file.

Thanks for all your help,
Oscar

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!