Re: [Algorithms] How do people use shader effect "compile" parameters?
Brought to you by:
vexxed72
|
From: rumzeus <ru...@gm...> - 2008-10-30 10:47:40
|
Ian Thomson wrote:
> I've used static pipeline control structures to manage combinations of shaders.
>
> struct ShaderConfig
> {
> bool bLighting;
> bool bScattering;
> bool bShadowing;
> };
> ShaderConfig StdConfig_2_0 =
> {
> true,
> false,
> true,
> };
> technique t
> {
> pass p
> {
> VertexShader = compile vs_2_0 Standard_v( NoShadows( StdConfig_2_0 ) );
> ...
> }
> }
> We generated large technique files (1000s of techniques, duplicate shaders shared) due to our need/desire to toggle settings and have them compile down optimally.
I'm trying to get this to "compile down optimally", but I seem to be
missing something. Shouldn't the two techniques below both compile down
to the same single instruction?
----- shader.fx
struct Config { bool Enabled; };
Config std = { false };
float4 PS_DirectBoolParam(float4 inTexCoord : TEXCOORD0,
uniform bool configEnabled) : COLOR0 {
if(configEnabled) return pow(inTexCoord,pow(inTexCoord,3));
else return inTexCoord;
}
float4 PS_ViaStruct(float4 inTexCoord : TEXCOORD0,
uniform Config config) : COLOR0 {
if(config.Enabled) return pow(inTexCoord,pow(inTexCoord,3));
else return inTexCoord;
}
technique T_DirectBoolParam {
pass Pass0 {
PixelShader = compile ps_2_0 PS_DirectBoolParam(false);
}
}
technique T_ViaStruct {
pass Pass0 {
PixelShader = compile ps_2_0 PS_ViaStruct(std);
}
}
----- end shader.fx
> fxc /Tfx_2_0 shader.fx
Microsoft (R) D3D10 Shader Compiler 9.24.949.2307
Copyright (C) Microsoft Corporation 2002-2007. All rights reserved.
//listing of all techniques and passes with embedded asm listings
technique T_DirectBoolParam
{
pass Pass0
{
//No embedded vertex shader
pixelshader =
asm {
//
// Generated by Microsoft (R) HLSL Shader Compiler
9.24.949.2307
ps_2_0
dcl t0
mov oC0, t0
// approximately 1 instruction slot used
};
}
}
technique T_ViaStruct
{
pass Pass0
{
//No embedded vertex shader
pixelshader =
asm {
//
// Generated by Microsoft (R) HLSL Shader Compiler
9.24.949.2307
//
// Parameters:
//
// struct
// {
// bool Enabled;
//
// } std;
//
//
// Registers:
//
// Name Reg Size
// ------------ ----- ----
// std c0 1
//
ps_2_0
dcl t0
mul r0, t0, t0
mul r0, r0, t0
log r1.x, t0.x
log r1.y, t0.y
log r1.z, t0.z
log r1.w, t0.w
mul r0, r0, r1
exp r1.x, r0.x
exp r1.y, r0.y
exp r1.z, r0.z
exp r1.w, r0.w
cmp r0, -c0.x, t0, r1
mov oC0, r0
// approximately 13 instruction slots used
};
}
}
|