Question

I'm working on simple .NET renderer now, and keep pushing the same stone for a month already:

I'm using effects framework, compiled by SlimDX developers for DX11, and I keep having troubles with updating EffectVariables inside rendering loop (i need vector value updated after every DrawIndexed call). Code looks like (filtered):

public Vector4 wireframeColor = new Vector4();
public Vector4 gridColor = new Vector4();
wireColorVar = effect.GetVariableByName("wireframeColor").AsVector();

wireColorVar.Set(gridColor);
DrawIndexed(GridDomain);
foreach model in scene
{
  wireColorVar.Set(wireframeColor);
  DrawIndexed(modelDomain);
}

.fx file looks like:

cbuffer ColorBuffer
{
    float4 wireframeColor;
    float4 diffuseColor;
};
float4 PVertex_Wire_PShader(PVertex_PInput input) : SV_TARGET
{
    return wireframeColor;
}

The problem is that every time all those rendering passes apply, in shader they deal only with last known variable value - i.e. wireframeColor, and never with the value of gridColor. I've had this problem for a while, so can surely tell, that it applies to every type of EffectVariables, from buffers to ShaderResources (UAViews for example), and this is really frustrating. Effect variables always tend to take the value of the last invoked one. DeviceContext.Flush() gives nothing, but it really looks like some sort of enqueing of GPU commands.

Only source of info for now, and it didn't work

Looks like applying effect passes doesn't flush variable changes. When i needed compute-shader to work, i had to manually apply resourceviews to explicitly placed variables (by register index) of shader stage.

Is this Effects implementation problem? It's not inevitable, i can still use low-level constant buffer assignments, but then there is no point to use effects at all.

P.S. oh, and don't suggest using diffuseColor field, or other means of just multiplying variable count. I need to change values of one and only variable many times between swapChain.Present() call.

Thank you for attention.

Was it helpful?

Solution

Switched to native DX11 shader mechanism, Microsoft effects seem to follow strange logic while applying GPU commands.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top