I have 3 different xna effects, one called initialise, one called iterate and one called finalise.
Initialise takes no texture inputs, and renders to 3 targets. Iterate takes those 3 as texture inputs, and renders to 3 targets, iterate runs multiple times. Finalise takes 1 texture input and renders to one target.
I've got a few helper classes, but it should be obvious what's going on from my render loop below:
int i = 0;
FractalInitRenderer.DefineOutputs(IterationsAndControl[i], Variables1And2[i], Variables3And4[i]);
FractalInitRenderer.Draw();
for (; i < 50; i++)
{
FractalIterateRenderer.ClearInputTextures();
FractalIterateRenderer.AddInput("IterationsAndControl", IterationsAndControl[i % 2]);
FractalIterateRenderer.AddInput("Variables1And2", Variables1And2[i % 2]);
FractalIterateRenderer.AddInput("Variables3And4", Variables3And4[i % 2]);
FractalIterateRenderer.DefineOutputs(IterationsAndControl[(i + 1) % 2], Variables1And2[(i + 1) % 2], Variables3And4[(i + 1) % 2]);
FractalIterateRenderer.Draw();
}
FractalFinaliseRenderer.ClearInputTextures();
FractalFinaliseRenderer.AddInput("IterationsAndControl", IterationsAndControl[i % 2]);
FractalFinaliseRenderer.Draw();
My texture declarations are using the following macro, and are defined as follows, along with my output struct:
#define DECLARE_TEXTURE(Name, index) \
Texture2D<float4> Name : register(t##index); \
sampler Name##Sampler : register(s##index);
struct FRACTAL_OUTPUT
{
float4 IterationsAndControl : COLOR0;
float4 Variables1And2 : COLOR1;
float4 Variables3And4 : COLOR2;
};
What i'm wondering is, can i put input and output render targets in different texture registers, then maybe run 2 iteration pixel shaders alternately one of them reading from the first 3 registers, writing to the last 3, and the other reading from the last 3 and writing to the first 3?
I'm guessing there's a cost associated with setting render targets and input textures many times, which i'd no longer have to do. Would this avoid it, and would it be worth it?
Note, i can optimise code within the shaders seperately, and if needed i'll ask a seperate question.