Disabled clearing of render targets in several passes (HLSL)

- which was quite a performance overhead and not necessary because the shaders fill every texel of a target without blending
master
Jezze 2016-10-22 22:39:14 +02:00
parent fcba2195bf
commit ef16086fea
3 changed files with 40 additions and 52 deletions

View File

@ -120,6 +120,7 @@ uniform float RoundCornerAmount = 0.0f;
uniform float SmoothBorderAmount = 0.0f;
uniform float VignettingAmount = 0.0f;
uniform float ReflectionAmount = 0.0f;
uniform float3 LightReflectionColor = float3(1.0f, 0.90f, 0.80f); // color temperature 5.000 Kelvin
uniform bool SwapXY = false;
@ -280,7 +281,12 @@ float4 ps_main(PS_INPUT Input) : COLOR
float2 QuadCoord = GetQuadCoords(Input.TexCoord, BaseTargetQuadScale, distortCornerAmount, 0.0f);
// clip border
clip(BaseCoord < 0.0f - TexelDims || BaseCoord > 1.0f + TexelDims ? -1 : 1);
if (BaseCoord.x < 0.0f - TexelDims.x || BaseCoord.y < 0.0f - TexelDims.y ||
BaseCoord.x > 1.0f + TexelDims.x || BaseCoord.y > 1.0f + TexelDims.y)
{
// we don't use the clip function, because we don't clear the render target before
return float4(0.0f, 0.0f, 0.0f, 1.0f);
}
// Color
float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
@ -293,14 +299,10 @@ float4 ps_main(PS_INPUT Input) : COLOR
BaseColor.rgb *= VignetteFactor;
// Light Reflection Simulation
float3 LightColor = float3(1.0f, 0.90f, 0.80f); // color temperature 5.000 Kelvin
float2 SpotCoord = QuadCoord;
float2 NoiseCoord = QuadCoord;
float SpotAddend = GetSpotAddend(SpotCoord, ReflectionAmount);
float NoiseFactor = GetNoiseFactor(SpotAddend, random(NoiseCoord));
BaseColor.rgb += SpotAddend * NoiseFactor * LightColor;
float SpotAddend = GetSpotAddend(SpotCoord, ReflectionAmount) * LightReflectionColor;
BaseColor.rgb += SpotAddend * GetNoiseFactor(SpotAddend, random(SpotCoord));
// Round Corners Simulation
float2 RoundCornerCoord = QuadCoord;

View File

@ -49,17 +49,15 @@ struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Color : COLOR0;
float2 SourceCoord : TEXCOORD0;
float2 TexCoord : TEXCOORD1;
float2 ScreenCoord : TEXCOORD2;
float2 TexCoord : TEXCOORD0;
float2 ScreenCoord : TEXCOORD1;
};
struct PS_INPUT
{
float4 Color : COLOR0;
float2 SourceCoord : TEXCOORD0;
float2 TexCoord : TEXCOORD1;
float2 ScreenCoord : TEXCOORD2;
float2 TexCoord : TEXCOORD0;
float2 ScreenCoord : TEXCOORD1;
};
//-----------------------------------------------------------------------------
@ -104,9 +102,6 @@ VS_OUTPUT vs_main(VS_INPUT Input)
Output.ScreenCoord = Input.Position.xy / ScreenDims;
Output.SourceCoord = Input.TexCoord;
Output.SourceCoord += 0.5f / TargetDims; // fix half texel offset (DX9)
Output.Color = Input.Color;
return Output;
@ -209,19 +204,23 @@ float4 ps_main(PS_INPUT Input) : COLOR
{
float2 ScreenCoord = Input.ScreenCoord;
float2 BaseCoord = GetAdjustedCoords(Input.TexCoord);
float2 SourceCoord = GetAdjustedCoords(Input.SourceCoord);
// Color
float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
BaseColor.a = 1.0f;
// clip border
clip(BaseCoord < 0.0f || BaseCoord > 1.0f ? -1 : 1);
if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f ||
BaseCoord.x > 1.0f || BaseCoord.y > 1.0f)
{
// we don't use the clip function, because we don't clear the render target before
return float4(0.0f, 0.0f, 0.0f, 1.0f);
}
// Mask Simulation (may not affect bloom)
if (!PrepareBloom && ShadowAlpha > 0.0f)
{
float2 ShadowCoord = GetShadowCoord(ScreenCoord, SourceCoord);
float2 ShadowCoord = GetShadowCoord(ScreenCoord, BaseCoord);
float4 ShadowColor = tex2D(ShadowSampler, ShadowCoord);
float3 ShadowMaskColor = lerp(1.0f, ShadowColor.rgb, ShadowAlpha);
@ -256,7 +255,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
float ColorBrightness = 0.299f * BaseColor.r + 0.587f * BaseColor.g + 0.114 * BaseColor.b;
float ScanlineCoord = SourceCoord.y;
float ScanlineCoord = BaseCoord.y;
ScanlineCoord += SwapXY
? QuadDims.x <= SourceDims.x * 2.0f
? 0.5f / QuadDims.x // uncenter scanlines if the quad is less than twice the size of the source
@ -280,7 +279,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
if (!VectorScreen && HumBarAlpha > 0.0f)
{
float HumBarStep = frac(TimeMilliseconds * HumBarDesync);
float HumBarBrightness = 1.0 - frac(SourceCoord.y + HumBarStep) * HumBarAlpha;
float HumBarBrightness = 1.0 - frac(BaseCoord.y + HumBarStep) * HumBarAlpha;
BaseColor.rgb *= HumBarBrightness;
}
}
@ -301,4 +300,4 @@ technique DefaultTechnique
VertexShader = compile vs_3_0 vs_main();
PixelShader = compile ps_3_0 ps_main();
}
}
}

View File

@ -841,10 +841,10 @@ void shaders::begin_draw()
downsample_effect->set_technique("DefaultTechnique");
vector_effect->set_technique("DefaultTechnique");
HRESULT result = d3d->get_device()->GetRenderTarget(0, &backbuffer);
HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer);
if (FAILED(result))
{
osd_printf_verbose("Direct3D: Error %08lX during device GetRenderTarget call\n", result);
osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result);
}
}
@ -940,7 +940,7 @@ int shaders::ntsc_pass(d3d_render_target *rt, int source_index, poly_info *poly,
curr_effect->set_float("SignalOffset", signal_offset);
next_index = rt->next_index(next_index);
blit(rt->source_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->source_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
color_effect->set_texture("Diffuse", rt->source_texture[next_index]);
@ -997,7 +997,7 @@ int shaders::color_convolution_pass(d3d_render_target *rt, int source_index, pol
// initial "Diffuse" texture is set in shaders::set_texture() or the result of shaders::ntsc_pass()
next_index = rt->next_index(next_index);
blit(rt->source_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->source_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@ -1011,7 +1011,7 @@ int shaders::prescale_pass(d3d_render_target *rt, int source_index, poly_info *p
curr_effect->set_texture("Diffuse", rt->source_texture[next_index]);
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@ -1034,7 +1034,7 @@ int shaders::deconverge_pass(d3d_render_target *rt, int source_index, poly_info
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@ -1054,7 +1054,7 @@ int shaders::defocus_pass(d3d_render_target *rt, int source_index, poly_info *po
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@ -1076,7 +1076,7 @@ int shaders::phosphor_pass(d3d_render_target *rt, int source_index, poly_info *p
curr_effect->set_bool("Passthrough", false);
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
// Pass along our phosphor'd screen
curr_effect->update_uniforms();
@ -1084,8 +1084,7 @@ int shaders::phosphor_pass(d3d_render_target *rt, int source_index, poly_info *p
curr_effect->set_texture("LastPass", rt->target_texture[next_index]);
curr_effect->set_bool("Passthrough", true);
// Avoid changing targets due to page flipping
blit(rt->cache_surface, true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->cache_surface, false, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@ -1130,7 +1129,7 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly,
curr_effect->set_bool("PrepareBloom", prepare_bloom);
next_index = rt->next_index(next_index);
blit(prepare_bloom ? rt->source_surface[next_index] : rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(prepare_bloom ? rt->source_surface[next_index] : rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@ -1156,7 +1155,7 @@ int shaders::downsample_pass(d3d_render_target *rt, int source_index, poly_info
? rt->source_texture[next_index]
: rt->bloom_texture[bloom_index - 1]);
blit(rt->bloom_surface[bloom_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->bloom_surface[bloom_index], false, D3DPT_TRIANGLELIST, 0, 2);
}
return next_index;
@ -1204,7 +1203,7 @@ int shaders::bloom_pass(d3d_render_target *rt, int source_index, poly_info *poly
}
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@ -1230,7 +1229,7 @@ int shaders::distortion_pass(d3d_render_target *rt, int source_index, poly_info
curr_effect->set_texture("DiffuseTexture", rt->target_texture[next_index]);
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
blit(rt->target_surface[next_index], false, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@ -1245,6 +1244,7 @@ int shaders::vector_pass(d3d_render_target *rt, int source_index, poly_info *pol
curr_effect->set_float("LengthScale", options->vector_length_scale);
curr_effect->set_float("BeamSmooth", options->vector_beam_smooth);
// we need to clear the vector render target here
blit(rt->target_surface[next_index], true, poly->type(), vertnum, poly->count());
return next_index;
@ -1260,6 +1260,7 @@ int shaders::vector_buffer_pass(d3d_render_target *rt, int source_index, poly_in
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
// we need to clear the vector render target here
next_index = rt->next_index(next_index);
blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
@ -1276,27 +1277,19 @@ int shaders::screen_pass(d3d_render_target *rt, int source_index, poly_info *pol
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
// we do not clear the backbuffer here because multiple screens might be rendered into
blit(backbuffer, false, poly->type(), vertnum, poly->count());
if (recording_movie)
{
blit(recorder->target_surface(), false, poly->type(), vertnum, poly->count());
HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer);
if (FAILED(result))
osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result);
recorder->save_frame();
}
if (render_snap)
{
blit(snap_target, false, poly->type(), vertnum, poly->count());
HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer);
if (FAILED(result))
osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result);
// we need to clear the snap render target here
blit(snap_target, true, poly->type(), vertnum, poly->count());
render_snapshot(snap_target);
@ -1458,12 +1451,6 @@ void shaders::render_quad(poly_info *poly, int vertnum)
next_index = screen_pass(rt, next_index, poly, vertnum);
d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(curr_texture->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer);
if (FAILED(result))
{
osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result);
}
curr_screen++;
}
else