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

Recommended Posts

I have this code that instantiate pixel shaders. I'll call it 3 times to load 3 different pixel shaders. When rendering each scene, I call SetPixelShader with the pixel shader that I need.

HRESULT D3D9RenderImpl::InitPixelShader(CommandStruct* cmd, IScriptEnvironment* env) {
CComPtr<ID3DXBuffer> code;
DWORD* CodeBuffer = NULL;

return E_FAIL;
}
else {
CodeBuffer = (DWORD*)code->GetBufferPointer();
}

return S_OK;
}


Now here's the problem. All 3 pixel shaders are running with the last ConstantTable! Which means the 2 first ones aren't being configured right. Since the ConstantTable is directly associated with the PixelShader instance, I assumed it would automatically switch the ConstantTable when I call SetPixelShader. That's not the case.

How can I handle my various instances of Pixel Shaders to also keep their respective configurations?

Share on other sites
Constant buffers are not associated with a pixel shader instance.

Share on other sites

How can I switch between constant buffers?

Share on other sites
Sorry, I overlooked the fact that you use D3D9. Constant buffers are D3D10+ feature.

I would check the logic with which you store the constant table references. Trivially, you can check if the constant table addresses are same. If the three pixel shaders differ significantly, you should get three significantly different constant tables.

Note that if the shaders use the same constant set, the constant table contents can effectively be same, but the tables still reside in their own addresses.

Share on other sites

D3DXGetShaderConstantTable needs to be called for each pixel shader, and I checked: it returns different addresses and I keep all 3 references. You might execute any number of pixel shaders with various configurations.

I configure all constant tables one at a time, and at the end of the day, after calling SetPixelShader on the desired shader for the current pass, only the constant table that was configured last takes effect.

Share on other sites

Constant tables are merely a mechanism for setting shader constants given symbolic constant names. A constant table does not remember what constants have been set through it.

Share on other sites

That still doesn't answer the question. When I set the constants, it fills a memory buffer (container) with configuration values (content).

I need to either

A) Have several containers and switch the device to the right one when needed.

B) Have one container and set its content when needed.

Which of these 2 approaches should I look for? Right now I'm re-parsing and re-setting the values into the last constant table when processing each scene. It is not ideal but it "works".

I might be running 3 shaders over each frame of a video. In which case, there are 3 sets of configurations, and these same configurations will remain the same for every frame that needs processing.

Edited by MysteryX

Share on other sites

Question: How does DirectX9 decide which ConstantTable it is using? It doesn't have any reference to it except through the shader. The only link to the ConstantTable is by calling D3DXGetShaderConstantTable on the shader, and that function has no reference to the device. Other than that, the only reference is when setting parameter values, it requires a pointer to the device.

Another question. Where does the ConstantTable reside to begin with, and when is it created? D3DXGetShaderConstantTable doesn't take the Shader object but rather its raw memory address, which indicates that it returns a pointer to an address space within the shader code itself. Thus, the ConstantTable is created when loading the shader file, and then we just get the pointer to it.

I'm reviewing my code. All the shaders get configured properly. At this point, none is set on the device.

Then when creating the scene, I call SetPixelShader. If the ConstantTable really is contained within the shader code, I would expect it to take that constant table. Instead, it takes the last ConstantTable created. How does the device even know which one got previously created? The only way it could even know is when calling LPD3DXCONSTANTTABLE->SetVector, which takes the device as a parameter.

This is kind of screwed up. Is my logic flawed somewhere in the process? If so, how can that be solved?

Share on other sites

Constant table is just a map of shader symbols to their corresponding registers. It, by itself does not remember the values you set through it at all. When you call Set* on the interface, the implementation will call Set*ShaderConstants immediately on the associated device, by using its map to determine which constant registers correspond to the symbolic constant name you give to it.

The point is, the buffer of the constant table is not a buffer of the constant values you set through it - the buffer just holds the mapping between constant registers and constant names (and the default values).

Edited by Nik02

Share on other sites
I'm not sure I'm on the same tree here, but whenever I call device->SetPixelShader or device->SetVertexShader, I follow it with a call to SetDefaults, e.g:

void GraphicsDevice::setVertexShader(VertexShader &shader)
{
{

}
}


1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 9
• 11
• 11
• Forum Statistics

• Total Topics
631775
• Total Posts
3002278
×