AntTweakbar related question & Compilation related question

share shaders here
  • Author
  • Message
Offline
*sensei*
Posts: 372
Joined: 28 Jul 2013, 23:26

AntTweakbar related question & Compilation related question

Pretty simple..

for AntTweakbar GUI controls I'm trying to find a way to bring all variables into neat sets of float3/4's.. for example I have now;

Code: Select all

float HueShiftD <			string UIName="Day HSL: Hue Shift";							string UIWidget="Spinner";	float UIMin=0.0;	float UIMax=1.0;	float UIStep=0.001;	> = {0.0};
float SaturationD <			string UIName="Day HSL: Saturation";						string UIWidget="Spinner";	float UIMin=0.0;	float UIMax=1.0;	float UIStep=0.001;	> = {0.0};
float LightnessD <			string UIName="Day HSL: Highlights";						string UIWidget="Spinner";	float UIMin=0.0;	float UIMax=1.0;	float UIStep=0.001;	> = {0.0};
float ShadowsD <			string UIName="Day HSL: Shadows";							string UIWidget="Spinner";	float UIMin=0.0;	float UIMax=1.0;	float UIStep=0.001;	> = {0.0};
I'm trying to do something like

Code: Select all

float4 HSL_D;
HSL_D.x <			string UIName="Day HSL: Hue Shift";							string UIWidget="Spinner";	float UIMin=0.0;	float UIMax=1.0;	float UIStep=0.001;	> = {0.0};
HSL_D.y <			string UIName="Day HSL: Saturation";						string UIWidget="Spinner";	float UIMin=0.0;	float UIMax=1.0;	float UIStep=0.001;	> = {0.0};
HSL_D.z <			string UIName="Day HSL: Highlights";						string UIWidget="Spinner";	float UIMin=0.0;	float UIMax=1.0;	float UIStep=0.001;	> = {0.0};
HSL_D.w <			string UIName="Day HSL: Shadows";							string UIWidget="Spinner";	float UIMin=0.0;	float UIMax=1.0;	float UIStep=0.001;	> = {0.0};
But this fails to compile.

Is it only able to compile with GUI when you actually declare the variable? I remember seeing something online where people were using AntTweakbar on variables that were declared earlier, but for the life of me I can't find that page...


--- another question related to compilation

I'm having various if statements and ASM clearly shows both sides of the statement are evaluated and later compared. Now I tried using static (ie. static bool blabla) which works, but doesn't work in GUI. I can use [branch] if to kind of control the flow to some extend, but I wonder if there is a way through GUI to actually skip parts of the shader in compilation, similar to #define directives. I can't use the techniques section for this... So far my poor attempts have failed.

Edit: and I realized now I am in the wrong part of the forum posting this, sry.

Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: AntTweakbar related question & Compilation related quest

something I've read about if, is that gpu reads a group of pixels to executed at once, and if a single pixel doesn't take the same side as the others, the whole group will be forced to execute both side.
and if all the pixels in the execution are taking the same side, it will skip the non taken path completely hence gaining some performance.

If you are trying to switch between shaders, this will do the trick.

Code: Select all


PixelShader pixelShaders[5] = 
{
    compile ps_3_0 PS_ProcessPass2(),
	compile ps_3_0 PS_ProcessPass2P3(),
	compile ps_3_0 PS_ProcessPass2P4(),
    compile ps_3_0 PS_ProcessPass2P5(),
	compile ps_3_0 PS_ProcessPass2P6()
};

technique PostProcess2
{
pass P0
{

VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = pixelShaders[INDEX];

DitherEnable=FALSE;
ZEnable=FALSE;
CullMode=NONE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
StencilEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}

btw, if you just set

float4 POS <string UIName="POS"; > = {0};

what you get is POSX, POSY, POSZ, POSW ingame.
probably require some modification to the tweakbarmod so that it will read the extra annotations and add them after UIName instead of plain XYZW.
Last edited by kingeric1992 on 10 Jan 2015, 23:47, edited 2 times in total.
_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube

Offline
*sensei*
Posts: 372
Joined: 28 Jul 2013, 23:26

Re: AntTweakbar related question & Compilation related quest

yes, but I'm trying to get rid of all if statements among other things...
Most can be killed using lerp() but then code still runs regardless. So I'm trying to find a working way to disable color effects from GUI then recompile from within game and gain the little performance it may give.

Using Techniques section isn't good for this purpose... I'll try and fiddle a bit more.
Last edited by prod80 on 11 Jan 2015, 00:07, edited 2 times in total.

Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: AntTweakbar related question & Compilation related quest

or pack the variations into different shaders than choose them in gui whether by shader array or TECHNIQUE.
at least that is how I did to select different polygon for GP's dof at first.
_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube

Offline
*sensei*
Posts: 373
Joined: 07 Mar 2013, 10:14

Re: AntTweakbar related question & Compilation related quest

Why not simply have your color effects in separate files, and then call them as needed using #include?

If they are commented out at compilation then the code is never evaluated, and will never cost anything. Removing the comment´s will restore them again upon next compilation, which you can do ingame... as long as you can successfully alt+tab or be in windowed mode you can do this on the fly.

Other then that, the only way I see is using if statements or lerps... but then it quickly gets rather messy imo. Also as long as all non used color effect GUI elements are loaded they will display and clutter up the list with non functional entries. By having them in their own files they wont when commented out, which is another added bonus!

Hope I did not fail to comprehend what you are trying to do entirely! :D

Also thanks for that nice trick with the shader compilation index kingeric! Gotta have to write that down somewhere!

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17427
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: AntTweakbar related question & Compilation related quest

In declarations, vector variables are single named only, you can't assing individual names to each component.
Compilation process is happening without any input variables, which are set only for compiled shader, so there is no way to make preprocessor controls similar to #ifdef/#endif. But you can make several passes and draw them all, but in vertex shader move quad outside of screen (or set it size to 0) for all passes, but the one you need. Of course control this process by variable declared for GUI.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
*sensei*
Posts: 372
Joined: 28 Jul 2013, 23:26

Re: AntTweakbar related question & Compilation related quest

Aiyen;
No need for external functions, you can also just place the GUI between #ifdef/#endif :) You can remove a lot of if statements with lerp, but if you look at ASM you see the compiled shader isn't any different for most of the code... ie.

Code: Select all

float4 PS_SerenityENB(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR {

float4 c0=tex2D(_s0, IN.txcoord0.xy);

if(bla==true)
	c0.xyz=lerp(c0.xyz, dot(c0.xyz, 0.33333333), str);
	
return c0;
}
in ASM

Code: Select all

    ps_3_0
    def c1, -1, 0.333333343, 0, 0
    dcl_texcoord v0.xy
    dcl_2d s0
    mov r0.x, c1.x
    add r0.x, r0.x, c0.x
    texld r1, v0, s0
    dp3 r0.y, r1, c1.y
    lrp r2.xyz, c6.x, r0.y, r1
    cmp oC0.xyz, r0.x, r2, r1 //no if statement... so no branching. Both true and false are evaluated and then compared to see what to do
    mov oC0.w, r1.w
Now with lerp

Code: Select all

float4 PS_SerenityENB(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR {

float4 c0=tex2D(_s0, IN.txcoord0.xy);

float3 r0=lerp(c0.xyz, dot(c0.xyz, 0.33333333), str);
c0.xyz=lerp(c0.xyz, r0.xyz, bla);

return c0;
}
in ASM

Code: Select all

    ps_3_0
    def c1, 0.333333343, 0, 0, 0
    dcl_texcoord v0.xy
    dcl_2d s0
    texld r0, v0, s0
    dp3 r1.x, r0, c1.x
    lrp r2.xyz, c6.x, r1.x, r0
    cmp oC0.xyz, -c0.x, r0, r2
    mov oC0.w, r0.w
Its a bit more efficient and it is 0.127% faster then using if... but that is with this example. I tried this logic on my entire shader and eventually it turned out that sometimes the compiled code is faster with an if statement then running the whole thing then using a lerp at the end... and then there's also the difference in how NVidia and AMD handle compilation... but performance wise we aren't talking anything past 0.5% over the whole shader here anyway.

You have to make it really crazy to have branches as drivers optimize your code. Using a ton of if statements doesn't equal inefficient code... having tons of branches does though :p have a look at the latest enbeffect.fx file I uploaded on Nexus...

the old file has;
33 registers, 1355 cycles, 136 Mpix/s

the new file has
34 registers, 971 cycles, 204 Mpix/s

...weirdest thing is that it didn't even gain me 1 FPS :D I guess I know shit about optimizing stuff.

Boris;
Yea I figured... couldn't get it to work with GUI, so in the end just added directives in the fx file. Is there any performance benefit to drawing all options then move what you don't need out of screen? I thought enbeffect.fx can't have multiple passes. But tbh I never tried adding more passes into it. Havent gotten to prepass/bloom/effect files yet.
Last edited by prod80 on 11 Jan 2015, 21:35, edited 1 time in total.

Offline
*sensei*
Posts: 373
Joined: 07 Mar 2013, 10:14

Re: AntTweakbar related question & Compilation related quest

Interesting prod! :)

However yeah... ASM is probably not going to provide much in this case anyways, but nice to see you going that way, then I know who to ask if I ever get over my ASM fobia!

Also you know me... I have mostly avoided if statements, since I do not really have any redundant code I do not use.
All the various debugging code etc. is left for development files, and not the final releases. Simply no reason to waste perfectly fine performance on code that is not used.

Offline
User avatar
*master*
Posts: 229
Joined: 21 Feb 2013, 03:21
Location: Los Angeles, CA

Re: AntTweakbar related question & Compilation related quest

kingeric1992, where does INDEX come from in your code? In the line:

Code: Select all

PixelShader = pixelShaders[INDEX];
Thanks
_________________
i7-4970K 4.8ghz, 16gb ram, Geforce Titan X 12gb vram, win7

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17427
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: AntTweakbar related question & Compilation related quest

prod80
Any hlsl support multiple passes, but inside single technique only. So you right, enbseries.fx is single pass from the point of the mod. Performance for the described trick is fine, just don't draw 100 passes as it will be greater loss than fps measurement errors.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
Post Reply