diff options
-rw-r--r-- | .gitattributes | 2 | ||||
-rw-r--r-- | hlsl/color.fx | 90 | ||||
-rw-r--r-- | hlsl/yiq_decode.fx | 173 | ||||
-rw-r--r-- | hlsl/yiq_encode.fx | 169 | ||||
-rw-r--r-- | src/osd/windows/drawd3d.c | 302 | ||||
-rw-r--r-- | src/osd/windows/winmain.c | 28 | ||||
-rw-r--r-- | src/osd/windows/winmain.h | 48 |
7 files changed, 591 insertions, 221 deletions
diff --git a/.gitattributes b/.gitattributes index 29894327687..754c9fbb3b9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18,6 +18,8 @@ hlsl/phosphor.fx svneol=native#text/plain hlsl/pincushion.fx svneol=native#text/plain hlsl/post.fx svneol=native#text/plain hlsl/primary.fx svneol=native#text/plain +hlsl/yiq_decode.fx svneol=native#text/plain +hlsl/yiq_encode.fx svneol=native#text/plain /makefile svneol=native#text/plain src/build/build.mak svneol=native#text/plain src/build/file2str.c svneol=native#text/plain diff --git a/hlsl/color.fx b/hlsl/color.fx index f2f3b907a83..639066b2794 100644 --- a/hlsl/color.fx +++ b/hlsl/color.fx @@ -55,6 +55,8 @@ uniform float RawHeight; uniform float WidthRatio; uniform float HeightRatio; +uniform float YIQEnable; + VS_OUTPUT vs_main(VS_INPUT Input) { VS_OUTPUT Output = (VS_OUTPUT)0; @@ -67,7 +69,9 @@ VS_OUTPUT vs_main(VS_INPUT Input) Output.Position.y -= 0.5f; Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f); Output.Color = Input.Color; - Output.TexCoord = Input.TexCoord;//(Input.TexCoord - float2(0.5f, 0.5f)) / 8.0f + float2(0.25f, 0.25f); + float2 InvTexSize = float2(1.0f / TargetWidth, 1.0f / TargetHeight); + float2 TexCoord = (Input.Position.xy * InvTexSize) / float2(WidthRatio, HeightRatio); + Output.TexCoord = lerp(Input.TexCoord, TexCoord, YIQEnable); Output.ExtraInfo = Input.ExtraInfo; return Output; @@ -87,16 +91,6 @@ uniform float BluFromRed = 0.0f; uniform float BluFromGrn = 0.0f; uniform float BluFromBlu = 1.0f; -uniform float YfromY = 1.0f; -uniform float YfromI = 0.0f; -uniform float YfromQ = 0.0f; -uniform float IfromY = 0.0f; -uniform float IfromI = 1.0f; -uniform float IfromQ = 0.0f; -uniform float QfromY = 0.0f; -uniform float QfromI = 0.0f; -uniform float QfromQ = 1.0f; - uniform float RedOffset = 0.0f; uniform float GrnOffset = 0.0f; uniform float BluOffset = 0.0f; @@ -111,87 +105,35 @@ uniform float BluFloor = 0.0f; uniform float Saturation = 1.0f; -uniform float YScale = 1.0f; -uniform float IScale = 1.0f; -uniform float QScale = 1.0f; -uniform float YOffset = 0.0f; -uniform float IOffset = 0.0f; -uniform float QOffset = 0.0f; - uniform float RedPower = 2.2f; uniform float GrnPower = 2.2f; uniform float BluPower = 2.2f; -uniform float YSubsampleLength = 3.0f; -uniform float ISubsampleLength = 3.0f; -uniform float QSubsampleLength = 3.0f; - float4 ps_main(PS_INPUT Input) : COLOR { - // -- Bandwidth Subsampling -- - float3 SubsampleWidth = float3(YSubsampleLength, ISubsampleLength, QSubsampleLength); - SubsampleWidth = (RawWidth * 2.0f) / SubsampleWidth; - float3 SubsampleCoord = Input.TexCoord.x; - float3 SubsampleFrac = frac(SubsampleCoord * SubsampleWidth); // Fraction is in subsample width units! - SubsampleCoord = (SubsampleCoord * SubsampleWidth - SubsampleFrac) / SubsampleWidth; - float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); - float3 YTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.x, Input.TexCoord.y)).rgb; - float3 ITexel = tex2D(DiffuseSampler, float2(SubsampleCoord.y, Input.TexCoord.y)).rgb; - float3 QTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.z, Input.TexCoord.y)).rgb; - - float3 LastYTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.x + YSubsampleLength / (RawWidth * 2.0f), Input.TexCoord.y)).rgb; - float3 LastITexel = tex2D(DiffuseSampler, float2(SubsampleCoord.y + ISubsampleLength / (RawWidth * 2.0f), Input.TexCoord.y)).rgb; - float3 LastQTexel = tex2D(DiffuseSampler, float2(SubsampleCoord.z + QSubsampleLength / (RawWidth * 2.0f), Input.TexCoord.y)).rgb; - - YTexel = lerp(YTexel, LastYTexel, SubsampleFrac.x); - ITexel = lerp(ITexel, LastITexel, SubsampleFrac.y); - QTexel = lerp(QTexel, LastQTexel, SubsampleFrac.z); + float3 OutRGB = BaseTexel.rgb; // -- RGB Tint & Shift -- - float ShiftedRedY = dot(YTexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); - float ShiftedGrnY = dot(YTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); - float ShiftedBluY = dot(YTexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); - float ShiftedRedI = dot(ITexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); - float ShiftedGrnI = dot(ITexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); - float ShiftedBluI = dot(ITexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); - float ShiftedRedQ = dot(QTexel, float3(RedFromRed, RedFromGrn, RedFromBlu)); - float ShiftedGrnQ = dot(QTexel, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); - float ShiftedBluQ = dot(QTexel, float3(BluFromRed, BluFromGrn, BluFromBlu)); + float ShiftedRed = dot(OutRGB, float3(RedFromRed, RedFromGrn, RedFromBlu)); + float ShiftedGrn = dot(OutRGB, float3(GrnFromRed, GrnFromGrn, GrnFromBlu)); + float ShiftedBlu = dot(OutRGB, float3(BluFromRed, BluFromGrn, BluFromBlu)); // -- RGB Offset & Scale -- float3 RGBScale = float3(RedScale, GrnScale, BluScale); float3 RGBShift = float3(RedOffset, GrnOffset, BluOffset); - float3 OutTexelY = float3(ShiftedRedY, ShiftedGrnY, ShiftedBluY) * RGBScale + RGBShift; - float3 OutTexelI = float3(ShiftedRedI, ShiftedGrnI, ShiftedBluI) * RGBScale + RGBShift; - float3 OutTexelQ = float3(ShiftedRedQ, ShiftedGrnQ, ShiftedBluQ) * RGBScale + RGBShift; + float3 OutTexel = float3(ShiftedRed, ShiftedGrn, ShiftedBlu) * RGBScale + RGBShift; // -- Saturation -- float3 Gray = float3(0.3f, 0.59f, 0.11f); - float OutLumaY = dot(OutTexelY, Gray); - float OutLumaI = dot(OutTexelI, Gray); - float OutLumaQ = dot(OutTexelQ, Gray); - float3 OutChromaY = OutTexelY - OutLumaY; - float3 OutChromaI = OutTexelI - OutLumaI; - float3 OutChromaQ = OutTexelQ - OutLumaQ; - float3 SaturatedY = OutLumaY + OutChromaY * Saturation; - float3 SaturatedI = OutLumaI + OutChromaI * Saturation; - float3 SaturatedQ = OutLumaQ + OutChromaQ * Saturation; + float OutLuma = dot(OutTexel, Gray); + float3 OutChroma = OutTexel - OutLuma; + float3 Saturated = OutLuma + OutChroma * Saturation; - // -- YIQ Convolution -- - float Y = dot(SaturatedY, float3(0.299f, 0.587f, 0.114f)); - float I = dot(SaturatedI, float3(0.595716f, -0.274453f, -0.321263f)); - float Q = dot(SaturatedQ, float3(0.211456f, -0.522591f, 0.311135f)); - Y = dot(float3(Y, I, Q), float3(YfromY, YfromI, YfromQ)); - I = dot(float3(Y, I, Q), float3(IfromY, IfromI, IfromQ)); - Q = dot(float3(Y, I, Q), float3(QfromY, QfromI, QfromQ)); - float3 OutYIQ = float3(Y, I, Q) * float3(YScale, IScale, QScale) + float3(YOffset, IOffset, QOffset); - float3 OutRGB = float3(dot(OutYIQ, float3(1.0f, 0.9563f, 0.6210f)), dot(OutYIQ, float3(1.0f, -0.2721f, -0.6474f)), dot(OutYIQ, float3(1.0f, -1.1070f, 1.7046f))); - - OutRGB.r = pow(OutRGB.r, RedPower); - OutRGB.g = pow(OutRGB.g, GrnPower); - OutRGB.b = pow(OutRGB.b, BluPower); + OutRGB.r = pow(Saturated.r, RedPower); + OutRGB.g = pow(Saturated.g, GrnPower); + OutRGB.b = pow(Saturated.b, BluPower); // -- Color Compression (increasing the floor of the signal without affecting the ceiling) -- OutRGB = float3(RedFloor + (1.0f - RedFloor) * OutRGB.r, GrnFloor + (1.0f - GrnFloor) * OutRGB.g, BluFloor + (1.0f - BluFloor) * OutRGB.b); diff --git a/hlsl/yiq_decode.fx b/hlsl/yiq_decode.fx new file mode 100644 index 00000000000..ee5d37bfa36 --- /dev/null +++ b/hlsl/yiq_decode.fx @@ -0,0 +1,173 @@ +//----------------------------------------------------------------------------- +// YIQ Decode Effect +//----------------------------------------------------------------------------- + +texture Diffuse; + +sampler DiffuseSampler = sampler_state +{ + Texture = <Diffuse>; + MipFilter = LINEAR; + MinFilter = LINEAR; + MagFilter = LINEAR; + AddressU = CLAMP; + AddressV = CLAMP; + AddressW = CLAMP; +}; + +//----------------------------------------------------------------------------- +// Vertex Definitions +//----------------------------------------------------------------------------- + +struct VS_OUTPUT +{ + float4 Position : POSITION; + float4 Color : COLOR0; + float2 Coord0 : TEXCOORD0; + float2 Coord1 : TEXCOORD1; + float2 Coord2 : TEXCOORD2; + float2 Coord3 : TEXCOORD3; + float2 Coord4 : TEXCOORD4; + float2 Coord5 : TEXCOORD5; +}; + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 Color : COLOR0; + float2 TexCoord : TEXCOORD0; + float2 ExtraInfo : TEXCOORD1; +}; + +struct PS_INPUT +{ + float4 Color : COLOR0; + float2 Coord0 : TEXCOORD0; + float2 Coord1 : TEXCOORD1; + float2 Coord2 : TEXCOORD2; + float2 Coord3 : TEXCOORD3; + float2 Coord4 : TEXCOORD4; + float2 Coord5 : TEXCOORD5; +}; + +//----------------------------------------------------------------------------- +// YIQ Decode Vertex Shader +//----------------------------------------------------------------------------- + +uniform float TargetWidth; +uniform float TargetHeight; + +uniform float RawWidth; +uniform float RawHeight; + +uniform float WidthRatio; +uniform float HeightRatio; + +VS_OUTPUT vs_main(VS_INPUT Input) +{ + VS_OUTPUT Output = (VS_OUTPUT)0; + + Output.Position = float4(Input.Position.xyz, 1.0f); + Output.Position.x /= TargetWidth; + Output.Position.y /= TargetHeight; + Output.Position.y = 1.0f - Output.Position.y; + Output.Position.x -= 0.5f; + Output.Position.y -= 0.5f; + Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f); + Output.Color = Input.Color; + float2 InvTexSize = float2(1.0f / TargetWidth, 1.0f / TargetHeight); + float2 Ratios = float2(WidthRatio, HeightRatio); + float2 TexCoord = (Input.Position.xy * InvTexSize) / Ratios; + Output.Coord0 = TexCoord + float2(0.0f / RawWidth, 0.0f); + Output.Coord1 = TexCoord + float2(0.25f / RawWidth, 0.0f); + Output.Coord2 = TexCoord + float2(0.5f / RawWidth, 0.0f); + Output.Coord3 = TexCoord + float2(0.75f / RawWidth, 0.0f); + Output.Coord4 = TexCoord + float2(1.0f / RawWidth, 0.0f); + Output.Coord5 = TexCoord + float2(1.25f / RawWidth, 0.0f); + + return Output; +} + +//----------------------------------------------------------------------------- +// YIQ Decode Pixel Shader +//----------------------------------------------------------------------------- + +uniform float YSubsampleLength = 3.0f; +uniform float ISubsampleLength = 3.0f; +uniform float QSubsampleLength = 3.0f; + +uniform float WValue; +uniform float AValue; +uniform float BValue; + +float4 ps_main(PS_INPUT Input) : COLOR +{ + float4 OrigC = tex2D(DiffuseSampler, Input.Coord0.xy); + float4 OrigC2 = tex2D(DiffuseSampler, Input.Coord4.xy); + float4 C = OrigC; + float4 C2 = OrigC2; + + float MaxC = 2.1183f; + float MinC = -1.1183f; + float CRange = MaxC - MinC; + + C = C * CRange + MinC; + C2 = C2 * CRange + MinC; + + float PI = 3.14159265f; + + float2 InvRatios = float2(1.0f / WidthRatio, 1.0f / HeightRatio); + float2 Scaler = float2(RawWidth, RawHeight) * InvRatios; + float2 Coord0 = Input.Coord0.xy * Scaler; + float2 Coord1 = Input.Coord1.xy * Scaler; + float2 Coord2 = Input.Coord2.xy * Scaler; + float2 Coord3 = Input.Coord3.xy * Scaler; + float2 Coord4 = Input.Coord4.xy * Scaler; + float2 Coord5 = Input.Coord5.xy * Scaler; + + float W = WValue * 2.0f; + float YRatio = 0.5333f; + float T0 = Coord0.x + AValue * YRatio * Coord0.y + BValue; + float T1 = Coord1.x + AValue * YRatio * Coord1.y + BValue; + float T2 = Coord2.x + AValue * YRatio * Coord2.y + BValue; + float T3 = Coord3.x + AValue * YRatio * Coord3.y + BValue; + float T4 = Coord4.x + AValue * YRatio * Coord4.y + BValue; + float T5 = Coord5.x + AValue * YRatio * Coord5.y + BValue; + float4 Tc = float4(T0, T1, T2, T3); + float2 Tc2 = float2(T4, T5); + + float Y = (C.r + C.g + C.b + C.a + C2.r + C2.g) / 6.0f; + + float4 IQ = C; + float4 I = IQ * sin(W * Tc); + float4 Q = IQ * cos(W * Tc); + float2 IQ2 = C2; + float2 I2 = IQ2 * sin(W * Tc2); + float2 Q2 = IQ2 * cos(W * Tc2); + + float Iavg = (I.r + I.g + I.b + I.a + I2.r + I2.g) / 3.0f; + float Qavg = (Q.r + Q.g + Q.b + Q.a + Q2.r + Q2.g) / 3.0f; + + float3 YIQ = float3(Y, Iavg, Qavg); + + float3 OutRGB = float3(dot(YIQ, float3(1.0f, 0.9563f, 0.6210f)), dot(YIQ, float3(1.0f, -0.2721f, -0.6474f)), dot(YIQ, float3(1.0f, -1.1070f, 1.7046f))); + + // Debugging: return sin(W * Tc) * 0.5f + 0.5f; + // Debugging: return float4(0.5f + 0.5f * sin(W * float3(T0, T2, T4)), 1.0f); + return float4(OutRGB, 1.0f); +} + +//----------------------------------------------------------------------------- +// YIQ Decode Technique +//----------------------------------------------------------------------------- + +technique DecodeTechnique +{ + pass Pass0 + { + Lighting = FALSE; + + VertexShader = compile vs_3_0 vs_main(); + PixelShader = compile ps_3_0 ps_main(); + } +} diff --git a/hlsl/yiq_encode.fx b/hlsl/yiq_encode.fx new file mode 100644 index 00000000000..da7e095b257 --- /dev/null +++ b/hlsl/yiq_encode.fx @@ -0,0 +1,169 @@ +//----------------------------------------------------------------------------- +// YIQ Encode Effect +//----------------------------------------------------------------------------- + +texture Diffuse; + +sampler DiffuseSampler = sampler_state +{ + Texture = <Diffuse>; + MipFilter = LINEAR; + MinFilter = LINEAR; + MagFilter = LINEAR; + AddressU = CLAMP; + AddressV = CLAMP; + AddressW = CLAMP; +}; + +//----------------------------------------------------------------------------- +// Vertex Definitions +//----------------------------------------------------------------------------- + +struct VS_OUTPUT +{ + float4 Position : POSITION; + float4 Color : COLOR0; + float2 Coord0 : TEXCOORD0; + float2 Coord1 : TEXCOORD1; + float2 Coord2 : TEXCOORD2; + float2 Coord3 : TEXCOORD3; +}; + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 Color : COLOR0; + float2 TexCoord : TEXCOORD0; + float2 ExtraInfo : TEXCOORD1; +}; + +struct PS_INPUT +{ + float4 Color : COLOR0; + float2 Coord0 : TEXCOORD0; + float2 Coord1 : TEXCOORD1; + float2 Coord2 : TEXCOORD2; + float2 Coord3 : TEXCOORD3; +}; + +//----------------------------------------------------------------------------- +// YIQ Encode Vertex Shader +//----------------------------------------------------------------------------- + +uniform float TargetWidth; +uniform float TargetHeight; + +uniform float RawWidth; +uniform float RawHeight; + +uniform float WidthRatio; +uniform float HeightRatio; + +VS_OUTPUT vs_main(VS_INPUT Input) +{ + VS_OUTPUT Output = (VS_OUTPUT)0; + + Output.Position = float4(Input.Position.xyz, 1.0f); + Output.Position.x /= TargetWidth; + Output.Position.y /= TargetHeight; + Output.Position.y /= HeightRatio; + Output.Position.y = 1.0f - Output.Position.y; + Output.Position.x /= WidthRatio; + Output.Position.x -= 0.5f; + Output.Position.y -= 0.5f; + Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f); + Output.Color = Input.Color; + float2 InvTexSize = float2(1.0f / TargetWidth, 1.0f / TargetHeight); + Output.Coord0 = Input.TexCoord + float2(0.00f / RawWidth, 0.0f); + Output.Coord1 = Input.TexCoord + float2(0.25f / RawWidth, 0.0f); + Output.Coord2 = Input.TexCoord + float2(0.50f / RawWidth, 0.0f); + Output.Coord3 = Input.TexCoord + float2(0.75f / RawWidth, 0.0f); + + return Output; +} + +//----------------------------------------------------------------------------- +// YIQ Encode Pixel Shader +//----------------------------------------------------------------------------- + +uniform float YSubsampleLength = 3.0f; +uniform float ISubsampleLength = 3.0f; +uniform float QSubsampleLength = 3.0f; + +uniform float WValue; +uniform float AValue; +uniform float BValue; + +float4 ps_main(PS_INPUT Input) : COLOR +{ + float3 Texel0 = tex2D(DiffuseSampler, Input.Coord0).rgb; + float3 Texel1 = tex2D(DiffuseSampler, Input.Coord1).rgb; + float3 Texel2 = tex2D(DiffuseSampler, Input.Coord2).rgb; + float3 Texel3 = tex2D(DiffuseSampler, Input.Coord3).rgb; + + // Cos goes from 1 to 0 to 1 over the course of 2PI + // Sin goes from 0 to 1 to 0 over the course of 2PI + // WValue is 4PI / 3 + // That is, 3 cycles through WValue will reuslt in 4PI being traversed, or cos() to go from 1 to 0 to 1 to 0 to 1 + // WValue appears to be the chroma carrier rate + // 1 Pixel -> 1 cycle + // WValue will cycle from 1 to 0 to 1 to 0 to 1 over 3 pixels + + + float PI = 3.14159265f; + float W = WValue; + + float T0 = Input.Coord0.x * (RawWidth / WidthRatio) * 2.0f + AValue * 0.5333f * Input.Coord0.y * (RawHeight / HeightRatio) * 2.0f + BValue * 2.0f + 2.0f; + float T1 = Input.Coord1.x * (RawWidth / WidthRatio) * 2.0f + AValue * 0.5333f * Input.Coord1.y * (RawHeight / HeightRatio) * 2.0f + BValue * 2.0f + 2.0f; + float T2 = Input.Coord2.x * (RawWidth / WidthRatio) * 2.0f + AValue * 0.5333f * Input.Coord2.y * (RawHeight / HeightRatio) * 2.0f + BValue * 2.0f + 2.0f; + float T3 = Input.Coord3.x * (RawWidth / WidthRatio) * 2.0f + AValue * 0.5333f * Input.Coord3.y * (RawHeight / HeightRatio) * 2.0f + BValue * 2.0f + 2.0f; + + float Y0 = dot(Texel0, float3(0.299f, 0.587f, 0.114f)); + float I0 = dot(Texel0, float3(0.595716f, -0.274453f, -0.321263f)); + float Q0 = dot(Texel0, float3(0.211456f, -0.522591f, 0.311135f)); + + float Y1 = dot(Texel1, float3(0.299f, 0.587f, 0.114f)); + float I1 = dot(Texel1, float3(0.595716f, -0.274453f, -0.321263f)); + float Q1 = dot(Texel1, float3(0.211456f, -0.522591f, 0.311135f)); + + float Y2 = dot(Texel2, float3(0.299f, 0.587f, 0.114f)); + float I2 = dot(Texel2, float3(0.595716f, -0.274453f, -0.321263f)); + float Q2 = dot(Texel2, float3(0.211456f, -0.522591f, 0.311135f)); + + float Y3 = dot(Texel3, float3(0.299f, 0.587f, 0.114f)); + float I3 = dot(Texel3, float3(0.595716f, -0.274453f, -0.321263f)); + float Q3 = dot(Texel3, float3(0.211456f, -0.522591f, 0.311135f)); + + //float MaxC = 1.5957f; + //float MinC = -0.5957f; + float MaxC = 2.1183f; + float MinC = -1.1183f; + float CRange = MaxC - MinC; + + float C0 = Y0 + I0 * sin(T0 * W) + Q0 * cos(T0 * W); + float C1 = Y1 + I1 * sin(T1 * W) + Q1 * cos(T1 * W); + float C2 = Y2 + I2 * sin(T2 * W) + Q2 * cos(T2 * W); + float C3 = Y3 + I3 * sin(T3 * W) + Q3 * cos(T3 * W); + C0 = (C0 - MinC) / CRange; + C1 = (C1 - MinC) / CRange; + C2 = (C2 - MinC) / CRange; + C3 = (C3 - MinC) / CRange; + + float4 Tc = float4(T0, T1, T2, T3); + return float4(C0, C1, C2, C3); +} + +//----------------------------------------------------------------------------- +// YIQ Encode Technique +//----------------------------------------------------------------------------- + +technique EncodeTechnique +{ + pass Pass0 + { + Lighting = FALSE; + + VertexShader = compile vs_3_0 vs_main(); + PixelShader = compile ps_3_0 ps_main(); + } +} diff --git a/src/osd/windows/drawd3d.c b/src/osd/windows/drawd3d.c index d336a2f3703..192b1baa6a3 100644 --- a/src/osd/windows/drawd3d.c +++ b/src/osd/windows/drawd3d.c @@ -132,13 +132,15 @@ struct _texture_info d3d_surface * d3dtarget0; // Direct3D render target surface pointer (pass 0, if necessary) d3d_surface * d3dtarget1; // Direct3D render target surface pointer (pass 1, if necessary) d3d_surface * d3dtarget2; // Direct3D render target surface pointer (pass 2, if necessary) + d3d_surface * d3dtarget3; // Direct3D render target surface pointer (pass 3, if necessary) + d3d_surface * d3dtarget4; // Direct3D render target surface pointer (pass 4, if necessary) d3d_surface * d3dsmalltarget0; // Direct3D render target surface pointer (small pass 0, if necessary) - d3d_surface * d3dsmalltarget1; // Direct3D render target surface pointer (small pass 1, if necessary) d3d_texture * d3dtexture0; // Direct3D render target texture pointer (pass 0, if necessary) d3d_texture * d3dtexture1; // Direct3D render target texture pointer (pass 1, if necessary) d3d_texture * d3dtexture2; // Direct3D render target texture pointer (pass 2, if necessary) + d3d_texture * d3dtexture3; // Direct3D render target texture pointer (pass 3, if necessary) + d3d_texture * d3dtexture4; // Direct3D render target texture pointer (pass 4, if necessary) d3d_texture * d3dsmalltexture0; // Direct3D render target texture pointer (small pass 0, if necessary) - d3d_texture * d3dsmalltexture1; // Direct3D render target texture pointer (small pass 1, if necessary) d3d_texture * d3dfinaltex; // Direct3D final (post-scaled) texture }; @@ -196,6 +198,8 @@ struct _d3d_info d3d_effect * phosphor_effect; // pointer to the current phosphor-effect object d3d_effect * deconverge_effect; // pointer to the current deconvergence-effect object d3d_effect * color_effect; // pointer to the current color-effect object + d3d_effect * yiq_encode_effect; // pointer to the current YIQ encoder effect object + d3d_effect * yiq_decode_effect; // pointer to the current YIQ decoder effect object poly_info poly[VERTEX_BUFFER_SIZE / 3];// array to hold polygons as they are created int numpolys; // number of accumulated polygons @@ -230,6 +234,7 @@ struct _d3d_info texture_info * default_texture; // experimental: default texture bool hlsl_enable; // experimental: HLSL enable flag + bool yiq_enable; // experimental: HLSL YIQ-convolution flag d3d_surface * last_d3dtarget[9]; // Direct3D render target surface pointer for each screen's previous frame d3d_texture * last_d3dtexture[9]; // Direct3D render target texture pointer for each screen's previous frame float oversample_x; // experimental: render target oversampling factor (width) for shader prettification @@ -363,7 +368,14 @@ INLINE void set_texture(d3d_info *d3d, texture_info *texture) if(d3d->hlsl_enable && d3d->effect != NULL) { (*d3dintf->effect.set_texture)(d3d->effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); - (*d3dintf->effect.set_texture)(d3d->color_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); + if(d3d->yiq_enable) + { + (*d3dintf->effect.set_texture)(d3d->yiq_encode_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); + } + else + { + (*d3dintf->effect.set_texture)(d3d->color_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); + } (*d3dintf->effect.set_texture)(d3d->pincushion_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex); } if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result); @@ -916,6 +928,8 @@ try_again: char focus_name_cstr[1024]; char deconverge_name_cstr[1024]; char color_name_cstr[1024]; + char yiq_encode_name_cstr[1024]; + char yiq_decode_name_cstr[1024]; sprintf(primary_name_cstr, "%s\\primary.fx", fx_dir); TCHAR *primary_name = tstring_from_utf8(primary_name_cstr); @@ -938,6 +952,12 @@ try_again: sprintf(color_name_cstr, "%s\\color.fx", fx_dir); TCHAR *color_name = tstring_from_utf8(color_name_cstr); + sprintf(yiq_encode_name_cstr, "%s\\yiq_encode.fx", fx_dir); + TCHAR *yiq_encode_name = tstring_from_utf8(yiq_encode_name_cstr); + + sprintf(yiq_decode_name_cstr, "%s\\yiq_decode.fx", fx_dir); + TCHAR *yiq_decode_name = tstring_from_utf8(yiq_decode_name_cstr); + // create the regular shader result = (*d3dintf->device.create_effect)(d3d->device, primary_name, &d3d->effect); @@ -959,6 +979,12 @@ try_again: // create the color convolution shader result = (*d3dintf->device.create_effect)(d3d->device, color_name, &d3d->color_effect); + // create the YIQ modulation shader + result = (*d3dintf->device.create_effect)(d3d->device, yiq_encode_name, &d3d->yiq_encode_effect); + + // create the YIQ demodulation shader + result = (*d3dintf->device.create_effect)(d3d->device, yiq_decode_name, &d3d->yiq_decode_effect); + if (primary_name) osd_free(primary_name); if (post_name) @@ -973,6 +999,10 @@ try_again: osd_free(deconverge_name); if (color_name) osd_free(color_name); + if (yiq_encode_name) + osd_free(yiq_encode_name); + if (yiq_decode_name) + osd_free(yiq_decode_name); } return device_create_resources(d3d); @@ -1144,20 +1174,24 @@ static void device_delete_resources(d3d_info *d3d) (*d3dintf->texture.release)(tex->d3dtexture1); if (tex->d3dtexture2 != NULL) (*d3dintf->texture.release)(tex->d3dtexture2); + if (tex->d3dtexture3 != NULL) + (*d3dintf->texture.release)(tex->d3dtexture3); + if (tex->d3dtexture4 != NULL) + (*d3dintf->texture.release)(tex->d3dtexture4); if (tex->d3dsmalltexture0 != NULL) (*d3dintf->texture.release)(tex->d3dsmalltexture0); - if (tex->d3dsmalltexture1 != NULL) - (*d3dintf->texture.release)(tex->d3dsmalltexture1); if (tex->d3dtarget0 != NULL) (*d3dintf->surface.release)(tex->d3dtarget0); if (tex->d3dtarget1 != NULL) (*d3dintf->surface.release)(tex->d3dtarget1); if (tex->d3dtarget2 != NULL) (*d3dintf->surface.release)(tex->d3dtarget2); + if (tex->d3dtarget3 != NULL) + (*d3dintf->surface.release)(tex->d3dtarget3); + if (tex->d3dtarget4 != NULL) + (*d3dintf->surface.release)(tex->d3dtarget4); if (tex->d3dsmalltarget0 != NULL) (*d3dintf->surface.release)(tex->d3dsmalltarget0); - if (tex->d3dsmalltarget1 != NULL) - (*d3dintf->surface.release)(tex->d3dsmalltarget1); global_free(tex); } @@ -1204,6 +1238,16 @@ static void device_delete_resources(d3d_info *d3d) (*d3dintf->effect.release)(d3d->color_effect); d3d->color_effect = NULL; } + if(d3d->yiq_encode_effect != NULL) + { + (*d3dintf->effect.release)(d3d->yiq_encode_effect); + d3d->yiq_encode_effect = NULL; + } + if(d3d->yiq_decode_effect != NULL) + { + (*d3dintf->effect.release)(d3d->yiq_decode_effect); + d3d->yiq_decode_effect = NULL; + } for(int index = 0; index < 9; index++) { @@ -1251,6 +1295,7 @@ static int device_verify_caps(d3d_info *d3d, win_window_info *window) if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result); d3d->hlsl_enable = downcast<windows_options &>(window->machine().options()).d3d_hlsl_enable() && d3dintf->post_fx_available; + d3d->yiq_enable = downcast<windows_options &>(window->machine().options()).screen_yiq_enable(); result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps); if (result != D3D_OK) mame_printf_verbose("Direct3D Error %08X during get_caps_dword call\n", (int)result); if(tempcaps < 512 && d3d->hlsl_enable) @@ -1994,6 +2039,8 @@ static void primitive_flush_pending(d3d_info *d3d) (*d3dintf->effect.set_technique)(d3d->focus_effect, "TestTechnique"); (*d3dintf->effect.set_technique)(d3d->deconverge_effect, "DeconvergeTechnique"); (*d3dintf->effect.set_technique)(d3d->color_effect, "ColorTechnique"); + (*d3dintf->effect.set_technique)(d3d->yiq_encode_effect, "EncodeTechnique"); + (*d3dintf->effect.set_technique)(d3d->yiq_decode_effect, "DecodeTechnique"); } d3d_surface *backbuffer; @@ -2085,15 +2132,91 @@ static void primitive_flush_pending(d3d_info *d3d) if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL) { + bool yiq_enable = options.screen_yiq_enable(); + if(yiq_enable) + { + /* Convert our signal into YIQ */ + curr_effect = d3d->yiq_encode_effect; + + (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); + (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f); + (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); + (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); + (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); + (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); + (*d3dintf->effect.set_float)(curr_effect, "WValue", options.screen_yiq_w()); + (*d3dintf->effect.set_float)(curr_effect, "AValue", options.screen_yiq_a()); + (*d3dintf->effect.set_float)(curr_effect, "BValue", (float)poly->texture->cur_frame * options.screen_yiq_b()); + + result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget4); + + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); + result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 0, 0); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); + + (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); + + for (UINT pass = 0; pass < num_passes; pass++) + { + (*d3dintf->effect.begin_pass)(curr_effect, pass); + // add the primitives + result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); + (*d3dintf->effect.end_pass)(curr_effect); + } + + (*d3dintf->effect.end)(curr_effect); + + /* Convert our signal from YIQ */ + curr_effect = d3d->yiq_decode_effect; + + (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture4); + (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); + (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f); + (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); + (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); + (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); + (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); + (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); + (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); + (*d3dintf->effect.set_float)(curr_effect, "WValue", options.screen_yiq_w()); + (*d3dintf->effect.set_float)(curr_effect, "AValue", options.screen_yiq_a()); + (*d3dintf->effect.set_float)(curr_effect, "BValue", (float)poly->texture->cur_frame * options.screen_yiq_b()); + + result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget3); + + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); + result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 0, 0); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); + + (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); + + for (UINT pass = 0; pass < num_passes; pass++) + { + (*d3dintf->effect.begin_pass)(curr_effect, pass); + // add the primitives + result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); + (*d3dintf->effect.end_pass)(curr_effect); + } + + (*d3dintf->effect.end)(curr_effect); + + curr_effect = d3d->color_effect; + + (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture3); + } + curr_effect = d3d->color_effect; /* Render the initial color-convolution pass */ (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); (*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f); - (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); - (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); + (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", yiq_enable ? 1.0f : (poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f)); + (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", yiq_enable ? 1.0f : (poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f)); (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); + (*d3dintf->effect.set_float)(curr_effect, "YIQEnable", yiq_enable ? 1.0f : 0.0f); (*d3dintf->effect.set_float)(curr_effect, "RedFromRed", (float)options.screen_red_from_red()); (*d3dintf->effect.set_float)(curr_effect, "RedFromGrn", (float)options.screen_red_from_green()); (*d3dintf->effect.set_float)(curr_effect, "RedFromBlu", (float)options.screen_red_from_blue()); @@ -2103,15 +2226,6 @@ static void primitive_flush_pending(d3d_info *d3d) (*d3dintf->effect.set_float)(curr_effect, "BluFromRed", (float)options.screen_blue_from_red()); (*d3dintf->effect.set_float)(curr_effect, "BluFromGrn", (float)options.screen_blue_from_green()); (*d3dintf->effect.set_float)(curr_effect, "BluFromBlu", (float)options.screen_blue_from_blue()); - (*d3dintf->effect.set_float)(curr_effect, "YfromY", (float)options.screen_y_from_y()); - (*d3dintf->effect.set_float)(curr_effect, "YfromI", (float)options.screen_y_from_i()); - (*d3dintf->effect.set_float)(curr_effect, "YfromQ", (float)options.screen_y_from_q()); - (*d3dintf->effect.set_float)(curr_effect, "IfromY", (float)options.screen_i_from_y()); - (*d3dintf->effect.set_float)(curr_effect, "IfromI", (float)options.screen_i_from_i()); - (*d3dintf->effect.set_float)(curr_effect, "IfromQ", (float)options.screen_i_from_q()); - (*d3dintf->effect.set_float)(curr_effect, "QfromY", (float)options.screen_q_from_y()); - (*d3dintf->effect.set_float)(curr_effect, "QfromI", (float)options.screen_q_from_i()); - (*d3dintf->effect.set_float)(curr_effect, "QfromQ", (float)options.screen_q_from_q()); (*d3dintf->effect.set_float)(curr_effect, "RedOffset", (float)options.screen_red_offset()); (*d3dintf->effect.set_float)(curr_effect, "GrnOffset", (float)options.screen_green_offset()); (*d3dintf->effect.set_float)(curr_effect, "BluOffset", (float)options.screen_blue_offset()); @@ -2125,15 +2239,6 @@ static void primitive_flush_pending(d3d_info *d3d) (*d3dintf->effect.set_float)(curr_effect, "GrnFloor", (float)options.screen_green_floor()); (*d3dintf->effect.set_float)(curr_effect, "BluFloor", (float)options.screen_blue_floor()); (*d3dintf->effect.set_float)(curr_effect, "Saturation", (float)options.screen_saturation()); - (*d3dintf->effect.set_float)(curr_effect, "YScale", (float)options.screen_y_scale()); - (*d3dintf->effect.set_float)(curr_effect, "IScale", (float)options.screen_i_scale()); - (*d3dintf->effect.set_float)(curr_effect, "QScale", (float)options.screen_q_scale()); - (*d3dintf->effect.set_float)(curr_effect, "YOffset", (float)options.screen_y_offset()); - (*d3dintf->effect.set_float)(curr_effect, "IOffset", (float)options.screen_i_offset()); - (*d3dintf->effect.set_float)(curr_effect, "QOffset", (float)options.screen_q_offset()); - (*d3dintf->effect.set_float)(curr_effect, "YSubsampleLength", (float)options.screen_y_subsample_length()); - (*d3dintf->effect.set_float)(curr_effect, "ISubsampleLength", (float)options.screen_i_subsample_length()); - (*d3dintf->effect.set_float)(curr_effect, "QSubsampleLength", (float)options.screen_q_subsample_length()); result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dsmalltarget0); @@ -2195,71 +2300,75 @@ static void primitive_flush_pending(d3d_info *d3d) (*d3dintf->effect.end)(curr_effect); - /* Defocus pass 1 */ - curr_effect = d3d->focus_effect; - - (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture2); - float defocus_x = (float)options.screen_defocus_x(); float defocus_y = (float)options.screen_defocus_y(); - (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); - (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); - (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); - (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); - (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); - (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); - (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x); - (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y); - (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f); + bool focus_enable = defocus_x != 0.0f || defocus_y != 0.0f; + if(focus_enable) + { + /* Defocus pass 1 */ + curr_effect = d3d->focus_effect; - (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); + (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture2); - result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget0); - if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); - result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); - if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); + (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); + (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); + (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); + (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); + (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f); + (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f); + (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x); + (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y); + (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f); - for (UINT pass = 0; pass < num_passes; pass++) - { - (*d3dintf->effect.begin_pass)(curr_effect, pass); - // add the primitives - result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); - if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); - (*d3dintf->effect.end_pass)(curr_effect); - } + (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); - (*d3dintf->effect.end)(curr_effect); + result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget0); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 6\n", (int)result); + result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); - /* Defocus pass 2 */ + for (UINT pass = 0; pass < num_passes; pass++) + { + (*d3dintf->effect.begin_pass)(curr_effect, pass); + // add the primitives + result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); + (*d3dintf->effect.end_pass)(curr_effect); + } - (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture0); + (*d3dintf->effect.end)(curr_effect); - (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); - (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); - (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); - (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); - (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f); - (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f); - (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x); - (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y); - (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f); + /* Defocus pass 2 */ - (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); + (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture0); - result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget1); - if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7\n", (int)result); - - for (UINT pass = 0; pass < num_passes; pass++) - { - (*d3dintf->effect.begin_pass)(curr_effect, pass); - // add the primitives - result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); - if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); - (*d3dintf->effect.end_pass)(curr_effect); + (*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width); + (*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height); + (*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth); + (*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight); + (*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f); + (*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f); + (*d3dintf->effect.set_float)(curr_effect, "DefocusX", defocus_x); + (*d3dintf->effect.set_float)(curr_effect, "DefocusY", defocus_y); + (*d3dintf->effect.set_float)(curr_effect, "FocusEnable", (defocus_x == 0.0f && defocus_y == 0.0f) ? 0.0f : 1.0f); + + (*d3dintf->effect.begin)(curr_effect, &num_passes, 0); + + result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget1); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 7\n", (int)result); + + for (UINT pass = 0; pass < num_passes; pass++) + { + (*d3dintf->effect.begin_pass)(curr_effect, pass); + // add the primitives + result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count); + if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result); + (*d3dintf->effect.end_pass)(curr_effect); + } + + (*d3dintf->effect.end)(curr_effect); } - (*d3dintf->effect.end)(curr_effect); - // Simulate phosphorescence. This should happen after the shadow/scanline pass, but since // the phosphors are a direct result of the incoming texture, might as well just change the // input texture. @@ -2273,7 +2382,7 @@ static void primitive_flush_pending(d3d_info *d3d) (*d3dintf->effect.set_float)(curr_effect, "GreenPhosphor", (float)options.screen_green_phosphor()); (*d3dintf->effect.set_float)(curr_effect, "BluePhosphor", (float)options.screen_blue_phosphor()); - (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture1); + (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", focus_enable ? poly->texture->d3dtexture1 : poly->texture->d3dtexture2); (*d3dintf->effect.set_texture)(curr_effect, "LastPass", d3d->last_d3dtexture[cur_render_screen]); result = (*d3dintf->device.set_render_target)(d3d->device, 0, poly->texture->d3dtarget0); @@ -2299,8 +2408,8 @@ static void primitive_flush_pending(d3d_info *d3d) (*d3dintf->effect.set_float)(curr_effect, "FixedAlpha", 1.0f); - (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dtexture1); - (*d3dintf->effect.set_texture)(curr_effect, "LastPass", poly->texture->d3dtexture1); + (*d3dintf->effect.set_texture)(curr_effect, "Diffuse", focus_enable ? poly->texture->d3dtexture1 : poly->texture->d3dtexture2); + (*d3dintf->effect.set_texture)(curr_effect, "LastPass", focus_enable ? poly->texture->d3dtexture1 : poly->texture->d3dtexture2); result = (*d3dintf->device.set_render_target)(d3d->device, 0, d3d->last_d3dtarget[cur_render_screen++]); if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 5\n", (int)result); @@ -2344,7 +2453,7 @@ static void primitive_flush_pending(d3d_info *d3d) (*d3dintf->effect.end)(curr_effect); poly->texture->cur_frame++; - poly->texture->cur_frame %= 2; + poly->texture->cur_frame %= options.screen_yiq_phase_count(); } else { @@ -2496,15 +2605,20 @@ static texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsour goto error; (*d3dintf->texture.get_surface_level)(texture->d3dtexture2, 0, &texture->d3dtarget2); - result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture0); + result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture3); if (result != D3D_OK) goto error; - (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture0, 0, &texture->d3dsmalltarget0); + (*d3dintf->texture.get_surface_level)(texture->d3dtexture3, 0, &texture->d3dtarget3); - result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture1); + result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture4); if (result != D3D_OK) goto error; - (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture1, 0, &texture->d3dsmalltarget1); + (*d3dintf->texture.get_surface_level)(texture->d3dtexture4, 0, &texture->d3dtarget4); + + result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture0); + if (result != D3D_OK) + goto error; + (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture0, 0, &texture->d3dsmalltarget0); d3d->registered_targets++; @@ -2567,15 +2681,21 @@ static texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsour goto error; (*d3dintf->texture.get_surface_level)(texture->d3dtexture2, 0, &texture->d3dtarget2); - result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture0); + result = (*d3dintf->device.create_texture)(d3d->device, (int)(scwidth * d3d->oversample_x), (int)(scheight * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture3); if (result != D3D_OK) goto error; - (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture0, 0, &texture->d3dsmalltarget0); + (*d3dintf->texture.get_surface_level)(texture->d3dtexture3, 0, &texture->d3dtarget3); + + printf("Boo\n"); + result = (*d3dintf->device.create_texture)(d3d->device, (int)(scwidth * d3d->oversample_x), (int)(scheight * d3d->oversample_y), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dtexture4); + if (result != D3D_OK) + goto error; + (*d3dintf->texture.get_surface_level)(texture->d3dtexture4, 0, &texture->d3dtarget4); - result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture1); + result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture->d3dsmalltexture0); if (result != D3D_OK) goto error; - (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture0, 1, &texture->d3dsmalltarget1); + (*d3dintf->texture.get_surface_level)(texture->d3dsmalltexture0, 0, &texture->d3dsmalltarget0); break; } diff --git a/src/osd/windows/winmain.c b/src/osd/windows/winmain.c index b7d5b756a9e..71f46c8b3cd 100644 --- a/src/osd/windows/winmain.c +++ b/src/osd/windows/winmain.c @@ -395,24 +395,11 @@ const options_entry windows_options::s_option_entries[] = { WINOPTION_GREEN_PHOSPHOR";fs_grnpho(0.0-1.0)", "0.0", OPTION_FLOAT, "green phosphorescence decay rate (0.0 is instant, 1.0 is forever)" }, { WINOPTION_BLUE_PHOSPHOR";fs_grnpho(0.0-1.0)", "0.0", OPTION_FLOAT, "blue phosphorescence decay rate (0.0 is instant, 1.0 is forever)" }, /* NTSC simulation below this line */ - { WINOPTION_Y_MATRIX_Y";fs_matyy(-2.0-2.0)", "1.0", OPTION_FLOAT, "Y output signal generated by Y input signal" }, - { WINOPTION_Y_MATRIX_I";fs_matyi(-2.0-2.0)", "0.0", OPTION_FLOAT, "Y output signal generated by I input signal" }, - { WINOPTION_Y_MATRIX_Q";fs_matyq(-2.0-2.0)", "0.0", OPTION_FLOAT, "Y output signal generated by Q input signal" }, - { WINOPTION_I_MATRIX_Y";fs_matiy(-2.0-2.0)", "0.0", OPTION_FLOAT, "I output signal generated by Y input signal" }, - { WINOPTION_I_MATRIX_I";fs_matii(-2.0-2.0)", "1.0", OPTION_FLOAT, "I output signal generated by I input signal" }, - { WINOPTION_I_MATRIX_Q";fs_matiq(-2.0-2.0)", "0.0", OPTION_FLOAT, "I output signal generated by Q input signal" }, - { WINOPTION_Q_MATRIX_Y";fs_matqy(-2.0-2.0)", "0.0", OPTION_FLOAT, "Q output signal generated by Y input signal" }, - { WINOPTION_Q_MATRIX_I";fs_matqi(-2.0-2.0)", "0.0", OPTION_FLOAT, "Q output signal generated by I input signal" }, - { WINOPTION_Q_MATRIX_Q";fs_matqq(-2.0-2.0)", "1.0", OPTION_FLOAT, "Q output signal generated by Q input signal" }, - { WINOPTION_Y_SCALE";fs_yscale(-2.0-2.0)", "1.0", OPTION_FLOAT, "Y signal scaling value for NTSC colorspace convolution (multiplicative)" }, - { WINOPTION_I_SCALE";fs_iscale(-2.0-2.0)", "1.0", OPTION_FLOAT, "I signal scaling value for NTSC colorspace convolution (multiplicative)" }, - { WINOPTION_Q_SCALE";fs_qscale(-2.0-2.0)", "1.0", OPTION_FLOAT, "Q signal scaling value for NTSC colorspace convolution (multiplicative)" }, - { WINOPTION_Y_OFFSET";fs_yoffs(-1.0-1.0)", "0.0", OPTION_FLOAT, "Y signal offset value for NTSC colorspace convolution (additive)" }, - { WINOPTION_I_OFFSET";fs_ioffs(-1.0-1.0)", "0.0", OPTION_FLOAT, "I signal offset value for NTSC colorspace convolution (additive)" }, - { WINOPTION_Q_OFFSET";fs_qoffs(-1.0-1.0)", "0.0", OPTION_FLOAT, "Q signal offset value for NTSC colorspace convolution (additive)" }, - { WINOPTION_Y_SUBSAMPLE_LENGTH";fs_ysub(0.5+)", "0.5", OPTION_FLOAT, "Y signal subsampling value, in pixels" }, - { WINOPTION_I_SUBSAMPLE_LENGTH";fs_isub(0.5+)", "0.5", OPTION_FLOAT, "I signal subsampling value, in pixels" }, - { WINOPTION_Q_SUBSAMPLE_LENGTH";fs_qsub(0.5+)", "0.5", OPTION_FLOAT, "Q signal subsampling value, in pixels" }, + { WINOPTION_YIQ_ENABLE";yiq", "0", OPTION_BOOLEAN, "enable YIQ-space HLSL post-processing" }, + { WINOPTION_YIQ_WVALUE";yiqw", "4.1187867", OPTION_FLOAT, "W value for YIQ signal processing" }, + { WINOPTION_YIQ_AVALUE";yiqa", "0.5", OPTION_FLOAT, "A value for YIQ signal processing (usually 0.5)" }, + { WINOPTION_YIQ_BVALUE";yiqb", "0.5", OPTION_FLOAT, "B value for YIQ signal processing (usually 0.5)" }, + { WINOPTION_YIQ_PHASE_COUNT";yiqp", "3", OPTION_INTEGER, "Phase Count value for YIQ signal processing (usually 2)" }, // per-window options { NULL, NULL, OPTION_HEADER, "PER-WINDOW VIDEO OPTIONS" }, @@ -1171,7 +1158,10 @@ static LONG WINAPI exception_filter(struct _EXCEPTION_POINTERS *info) // walk the stack while (walker.unwind()) fprintf(stderr, " %p: %p%s\n", (void *)walker.frame(), (void *)walker.ip(), (symbols == NULL) ? "" : symbols->symbol_for_address(walker.ip())); - + + // flush stderr, so the data is actually written when output is being redirected + fflush(stderr); + // flush stderr, so the data is actually written when output is being redirected fflush(stderr); diff --git a/src/osd/windows/winmain.h b/src/osd/windows/winmain.h index 96e71a468d5..a255ce86772 100644 --- a/src/osd/windows/winmain.h +++ b/src/osd/windows/winmain.h @@ -121,15 +121,6 @@ #define WINOPTION_BLUE_MATRIX_R "blue_from_r" #define WINOPTION_BLUE_MATRIX_G "blue_from_g" #define WINOPTION_BLUE_MATRIX_B "blue_from_b" -#define WINOPTION_Y_MATRIX_Y "y_from_y" -#define WINOPTION_Y_MATRIX_I "y_from_i" -#define WINOPTION_Y_MATRIX_Q "y_from_q" -#define WINOPTION_I_MATRIX_Y "i_from_y" -#define WINOPTION_I_MATRIX_I "i_from_i" -#define WINOPTION_I_MATRIX_Q "i_from_q" -#define WINOPTION_Q_MATRIX_Y "q_from_y" -#define WINOPTION_Q_MATRIX_I "q_from_i" -#define WINOPTION_Q_MATRIX_Q "q_from_q" #define WINOPTION_RED_OFFSET "red_offset" #define WINOPTION_GREEN_OFFSET "green_offset" #define WINOPTION_BLUE_OFFSET "blue_offset" @@ -142,19 +133,15 @@ #define WINOPTION_RED_FLOOR "red_floor" #define WINOPTION_GREEN_FLOOR "green_floor" #define WINOPTION_BLUE_FLOOR "blue_floor" -#define WINOPTION_SATURATION "saturation" -#define WINOPTION_Y_SCALE "y_scale" -#define WINOPTION_I_SCALE "i_scale" -#define WINOPTION_Q_SCALE "q_scale" -#define WINOPTION_Y_OFFSET "y_offset" -#define WINOPTION_I_OFFSET "i_offset" -#define WINOPTION_Q_OFFSET "q_offset" -#define WINOPTION_Y_SUBSAMPLE_LENGTH "y_subsample_length" -#define WINOPTION_I_SUBSAMPLE_LENGTH "i_subsample_length" -#define WINOPTION_Q_SUBSAMPLE_LENGTH "q_subsample_length" #define WINOPTION_RED_PHOSPHOR "red_phosphor_life" #define WINOPTION_GREEN_PHOSPHOR "green_phosphor_life" #define WINOPTION_BLUE_PHOSPHOR "blue_phosphor_life" +#define WINOPTION_SATURATION "saturation" +#define WINOPTION_YIQ_ENABLE "yiq_enable" +#define WINOPTION_YIQ_WVALUE "yiq_w" +#define WINOPTION_YIQ_AVALUE "yiq_a" +#define WINOPTION_YIQ_BVALUE "yiq_b" +#define WINOPTION_YIQ_PHASE_COUNT "yiq_phase_count" // per-window options #define WINOPTION_SCREEN "screen" @@ -261,15 +248,11 @@ public: float screen_blue_from_red() const { return float_value(WINOPTION_BLUE_MATRIX_R); } float screen_blue_from_green() const { return float_value(WINOPTION_BLUE_MATRIX_G); } float screen_blue_from_blue() const { return float_value(WINOPTION_BLUE_MATRIX_B); } - float screen_y_from_y() const { return float_value(WINOPTION_Y_MATRIX_Y); } - float screen_y_from_i() const { return float_value(WINOPTION_Y_MATRIX_I); } - float screen_y_from_q() const { return float_value(WINOPTION_Y_MATRIX_Q); } - float screen_i_from_y() const { return float_value(WINOPTION_I_MATRIX_Y); } - float screen_i_from_i() const { return float_value(WINOPTION_I_MATRIX_I); } - float screen_i_from_q() const { return float_value(WINOPTION_I_MATRIX_Q); } - float screen_q_from_y() const { return float_value(WINOPTION_Q_MATRIX_Y); } - float screen_q_from_i() const { return float_value(WINOPTION_Q_MATRIX_I); } - float screen_q_from_q() const { return float_value(WINOPTION_Q_MATRIX_Q); } + bool screen_yiq_enable() const { return bool_value(WINOPTION_YIQ_ENABLE); } + float screen_yiq_w() const { return float_value(WINOPTION_YIQ_WVALUE); } + float screen_yiq_a() const { return float_value(WINOPTION_YIQ_AVALUE); } + float screen_yiq_b() const { return float_value(WINOPTION_YIQ_BVALUE); } + int screen_yiq_phase_count() const { return int_value(WINOPTION_YIQ_PHASE_COUNT); } float screen_red_offset() const { return float_value(WINOPTION_RED_OFFSET); } float screen_green_offset() const { return float_value(WINOPTION_GREEN_OFFSET); } float screen_blue_offset() const { return float_value(WINOPTION_BLUE_OFFSET); } @@ -283,15 +266,6 @@ public: float screen_green_floor() const { return float_value(WINOPTION_GREEN_FLOOR); } float screen_blue_floor() const { return float_value(WINOPTION_BLUE_FLOOR); } float screen_saturation() const { return float_value(WINOPTION_SATURATION); } - float screen_y_scale() const { return float_value(WINOPTION_Y_SCALE); } - float screen_i_scale() const { return float_value(WINOPTION_I_SCALE); } - float screen_q_scale() const { return float_value(WINOPTION_Q_SCALE); } - float screen_y_offset() const { return float_value(WINOPTION_Y_OFFSET); } - float screen_i_offset() const { return float_value(WINOPTION_I_OFFSET); } - float screen_q_offset() const { return float_value(WINOPTION_Q_OFFSET); } - float screen_y_subsample_length() const { return float_value(WINOPTION_Y_SUBSAMPLE_LENGTH); } - float screen_i_subsample_length() const { return float_value(WINOPTION_I_SUBSAMPLE_LENGTH); } - float screen_q_subsample_length() const { return float_value(WINOPTION_Q_SUBSAMPLE_LENGTH); } float screen_red_phosphor() const { return float_value(WINOPTION_RED_PHOSPHOR); } float screen_green_phosphor() const { return float_value(WINOPTION_GREEN_PHOSPHOR); } float screen_blue_phosphor() const { return float_value(WINOPTION_BLUE_PHOSPHOR); } |