Need help with technique setup

  • Keeree
  • Topic Author
More
8 years 3 months ago #1 by Keeree Need help with technique setup was created by Keeree
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:

Please Log in or Create an account to join the conversation.

  • crosire
More
8 years 3 months ago - 8 years 3 months ago #2 by crosire Replied by crosire on topic Need help with technique setup
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").
Last edit: 8 years 3 months ago by crosire.

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.