Welcome, Guest.
Username: Password: Remember me

TOPIC: Need help with technique setup

Need help with technique setup 10 months 3 weeks ago #1

I'm trying to implement a bicubic interpolation warping shader for Elite: Dangerous, and while I have the basic effect worked out, I'm having issues with optimization. I'm trying to create a lookup texture for each channel, to avoid calculating warp each frame. I have the texture storage working (I think) but I'm unable, so far, to use it, because I'm unable to figure out how to write to the texture, then read. I'm getting internal error: invalid access of unbound variable which is, as far as I can tell, from reading and writing simultaneously. Is there any way to toggle the state of one technique off another? Or to delay the start of a technique? Or unbind the rendertarget after the first write?

Thanks,
Keeree

PS: As a side note, why would you ever want to use toggleTime? :huh:
The administrator has disabled public write access.

Need help with technique setup 10 months 3 weeks ago #2

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2451
  • Thank you received: 1391
There is no compiler error when reading and writing to the same texture. It will produce (invisible to the normal user) runtime errors, you can watch when the D3D debug runtime is active. So that internal error is something else, and not something that should happen. Could you post some context code to that error?

Anyway, here's some info on your questions:
A texture is only bound as rendertarget as long as in a pass where it was set as rendertarget. It's automatically unbound on the next pass and can be read from there again.

In the following example MyFunction1 would write its result to MyTexture (and thus cannot read from it). MyFunction2 then writes to the backbuffer again and may read the content of MyTexture, which was filled in the previous pass.
technique
{
    pass
    {
        PixelShader = MyFunction1;
        RenderTarget = MyTexture;
    }
    pass
    {
        PixelShader = MyFunction2;
    }
}

However, if I read your post right, you actually want to execute a technique only once. So to create the lookup texture at startup for later use. You could achieve that with the following. This way the technique is only executed for 100ms after compilation finished. It still runs multiple times, but after those short 100ms are over it will never run again and not bring down performance every frame. So you may do some heavy processing in here, write the result to some texture and then later use that texture.
technique < enabled = true; timeout = 100; > { ... }

A full example. Techniques are guaranteed to execute in the order they were defined in the shader file, so "PSPostProcessing" will always recieve valid data from "lookupTexture", since "PSInitLookupTexture" must have executed before at least once.
texture lookupTexture { Width = 100; Height = 100; Format = RGBA8; };
sampler lookupSampler { Texture = lookupTexture; };

void PSInitLookupTexture(float4 pos : SV_Position, float2 texcoord : TEXCOORD, out float4 color : SV_Target)
{
    ...
}
void PSPostProcessing(float4 pos : SV_Position, float2 texcoord : TEXCOORD, out float4 color : SV_Target)
{
    float4 lookup = tex2D(lookupSampler, ...);
    ...
}

technique InitLookupTexture < enabled = true; timeout = 100; >
{
    pass
    {
        VertexShader = ...;
        PixelShader = PSInitLookupTexture;
        RenderTarget = lookupTexture;
    }
}
technique PostProcessing < enabled = true; >
{
    pass
    {
        VertexShader = ...;
        PixelShader = PSPostProcessing;
    }
}

As for "toggleTime": That one was mainly added for fun. Could be used to display a warning message when it is getting late for example (like "You should go to sleep now").
Cheers, crosire =)
Last Edit: 10 months 3 weeks ago by crosire.
The administrator has disabled public write access.