From 5bb6b074f09afdfdd16ba52e9a7a804cd9c9f980 Mon Sep 17 00:00:00 2001 From: elasota Date: Sat, 25 Apr 2020 16:35:34 -0400 Subject: [PATCH] Scale quads after rendering to a screen texture instead of scaling directly. Fixes discontinuities in room editor and menu edges. --- CompileShadersD3D11/CompileShadersD3D11.cpp | 8 + .../DrawQuadPaletteP_D3D11.cpp | 104 +++--------- .../CompiledShaders/DrawQuadRGBP_D3D11.cpp | 75 +++++---- .../CompiledShaders/ScaleQuadP_D3D11.cpp | 93 +++++++++++ .../GpDisplayDriverD3D11.cpp | 149 ++++++++++++++++-- GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h | 10 +- .../GpDisplayDriver_D3D11.vcxproj | 1 + .../GpDisplayDriver_D3D11.vcxproj.filters | 3 + ShaderSrc/DrawQuadPaletteP.hlsl | 22 +-- ShaderSrc/DrawQuadRGBP.hlsl | 6 +- ShaderSrc/ScaleQuadP.hlsl | 41 +++++ 11 files changed, 358 insertions(+), 154 deletions(-) create mode 100644 GpDisplayDriver_D3D11/CompiledShaders/ScaleQuadP_D3D11.cpp create mode 100644 ShaderSrc/ScaleQuadP.hlsl diff --git a/CompileShadersD3D11/CompileShadersD3D11.cpp b/CompileShadersD3D11/CompileShadersD3D11.cpp index 943b0f5..6ba430b 100644 --- a/CompileShadersD3D11/CompileShadersD3D11.cpp +++ b/CompileShadersD3D11/CompileShadersD3D11.cpp @@ -52,6 +52,14 @@ const CompileJob kCompileJobs[] = drawQuadDefs, "PSMain", "ps_4_0" + }, + { + L"ShaderSrc\\ScaleQuadP.hlsl", + L"GpDisplayDriver_D3D11\\CompiledShaders\\ScaleQuadP_D3D11.cpp", + "g_scaleQuadP_D3D11", + drawQuadDefs, + "PSMain", + "ps_4_0" } }; diff --git a/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp b/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp index 2384706..7585d83 100644 --- a/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp +++ b/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp @@ -1,8 +1,8 @@ static unsigned char gs_shaderData[] = { - 68, 88, 66, 67, 231, 194, 75, 38, 6, 25, 110, 45, 187, 225, 136, - 211, 34, 239, 174, 118, 1, 0, 0, 0, 44, 6, 0, 0, 5, 0, + 68, 88, 66, 67, 75, 29, 59, 91, 67, 226, 130, 211, 218, 1, 246, + 35, 4, 77, 147, 90, 1, 0, 0, 0, 4, 3, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0, 224, 0, 0, 0, 56, 1, 0, 0, 108, - 1, 0, 0, 176, 5, 0, 0, 82, 68, 69, 70, 164, 0, 0, 0, + 1, 0, 0, 136, 2, 0, 0, 82, 68, 69, 70, 164, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 28, 0, 0, 0, 0, 4, 255, 255, 0, 137, 0, 0, 122, 0, 0, 0, 92, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 255, @@ -23,88 +23,34 @@ static unsigned char gs_shaderData[] = { 78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69, - 84, 0, 171, 171, 83, 72, 68, 82, 60, 4, 0, 0, 64, 0, 0, - 0, 15, 1, 0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, + 84, 0, 171, 171, 83, 72, 68, 82, 20, 1, 0, 0, 64, 0, 0, + 0, 69, 0, 0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 68, 68, 0, 0, 88, 16, 0, 4, 0, 112, 16, 0, 1, 0, 0, 0, 85, 85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, 101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, - 0, 104, 0, 0, 2, 5, 0, 0, 0, 11, 0, 0, 5, 18, 0, - 16, 0, 0, 0, 0, 0, 10, 16, 16, 0, 1, 0, 0, 0, 12, - 0, 0, 5, 34, 0, 16, 0, 0, 0, 0, 0, 26, 16, 16, 0, - 1, 0, 0, 0, 50, 0, 0, 13, 194, 0, 16, 0, 0, 0, 0, - 0, 6, 4, 16, 128, 65, 0, 0, 0, 0, 0, 0, 0, 2, 64, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 0, - 0, 0, 63, 6, 20, 16, 0, 1, 0, 0, 0, 52, 0, 0, 10, - 194, 0, 16, 0, 0, 0, 0, 0, 166, 14, 16, 0, 0, 0, 0, + 0, 104, 0, 0, 2, 1, 0, 0, 0, 65, 0, 0, 5, 50, 0, + 16, 0, 0, 0, 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 27, + 0, 0, 5, 50, 0, 16, 0, 0, 0, 0, 0, 70, 0, 16, 0, + 0, 0, 0, 0, 54, 0, 0, 8, 194, 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 51, 0, 0, 10, 50, 0, 16, 0, 1, - 0, 0, 0, 70, 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, - 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 7, 50, 0, 16, 0, 1, 0, 0, 0, 230, 10, - 16, 0, 0, 0, 0, 0, 70, 0, 16, 0, 1, 0, 0, 0, 65, - 0, 0, 5, 194, 0, 16, 0, 0, 0, 0, 0, 166, 14, 16, 0, - 0, 0, 0, 0, 27, 0, 0, 5, 50, 0, 16, 0, 2, 0, 0, - 0, 230, 10, 16, 0, 0, 0, 0, 0, 65, 0, 0, 5, 194, 0, - 16, 0, 0, 0, 0, 0, 6, 4, 16, 0, 1, 0, 0, 0, 0, - 0, 0, 8, 50, 0, 16, 0, 1, 0, 0, 0, 230, 10, 16, 128, - 65, 0, 0, 0, 0, 0, 0, 0, 70, 0, 16, 0, 1, 0, 0, - 0, 27, 0, 0, 5, 50, 0, 16, 0, 3, 0, 0, 0, 230, 10, - 16, 0, 0, 0, 0, 0, 14, 32, 0, 7, 50, 0, 16, 0, 0, - 0, 0, 0, 70, 0, 16, 0, 1, 0, 0, 0, 70, 0, 16, 0, - 0, 0, 0, 0, 54, 0, 0, 5, 66, 0, 16, 0, 2, 0, 0, - 0, 1, 64, 0, 0, 0, 0, 0, 0, 54, 0, 0, 5, 194, 0, - 16, 0, 3, 0, 0, 0, 86, 9, 16, 0, 2, 0, 0, 0, 45, - 0, 0, 7, 242, 0, 16, 0, 1, 0, 0, 0, 70, 15, 16, 0, - 3, 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 45, 0, 0, - 7, 242, 0, 16, 0, 4, 0, 0, 0, 134, 15, 16, 0, 3, 0, - 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 130, - 0, 16, 0, 2, 0, 0, 0, 26, 0, 16, 0, 3, 0, 0, 0, - 45, 0, 0, 7, 242, 0, 16, 0, 3, 0, 0, 0, 198, 10, 16, - 0, 2, 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 45, 0, - 0, 7, 242, 0, 16, 0, 2, 0, 0, 0, 70, 10, 16, 0, 2, - 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 54, 0, 0, 8, - 226, 0, 16, 0, 1, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, - 0, 7, 242, 0, 16, 0, 1, 0, 0, 0, 70, 14, 16, 0, 1, - 0, 0, 0, 70, 126, 16, 0, 1, 0, 0, 0, 56, 0, 0, 7, - 114, 0, 16, 0, 1, 0, 0, 0, 6, 0, 16, 0, 0, 0, 0, - 0, 70, 2, 16, 0, 1, 0, 0, 0, 54, 0, 0, 8, 226, 0, - 16, 0, 3, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 7, - 242, 0, 16, 0, 3, 0, 0, 0, 70, 14, 16, 0, 3, 0, 0, - 0, 70, 126, 16, 0, 1, 0, 0, 0, 0, 0, 0, 11, 194, 0, - 16, 0, 0, 0, 0, 0, 6, 4, 16, 128, 65, 0, 0, 0, 0, - 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 128, 63, 0, 0, 128, 63, 50, 0, 0, 9, 114, 0, 16, - 0, 1, 0, 0, 0, 166, 10, 16, 0, 0, 0, 0, 0, 70, 2, - 16, 0, 3, 0, 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, 56, - 0, 0, 7, 114, 0, 16, 0, 1, 0, 0, 0, 86, 5, 16, 0, - 0, 0, 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, 54, 0, 0, - 8, 226, 0, 16, 0, 4, 0, 0, 0, 2, 64, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, - 0, 0, 7, 242, 0, 16, 0, 3, 0, 0, 0, 70, 14, 16, 0, - 4, 0, 0, 0, 70, 126, 16, 0, 1, 0, 0, 0, 56, 0, 0, - 7, 114, 0, 16, 0, 3, 0, 0, 0, 6, 0, 16, 0, 0, 0, - 0, 0, 70, 2, 16, 0, 3, 0, 0, 0, 54, 0, 0, 8, 226, - 0, 16, 0, 2, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, - 7, 242, 0, 16, 0, 2, 0, 0, 0, 70, 14, 16, 0, 2, 0, - 0, 0, 70, 126, 16, 0, 1, 0, 0, 0, 50, 0, 0, 9, 114, - 0, 16, 0, 0, 0, 0, 0, 166, 10, 16, 0, 0, 0, 0, 0, - 70, 2, 16, 0, 2, 0, 0, 0, 70, 2, 16, 0, 3, 0, 0, - 0, 50, 0, 0, 9, 114, 32, 16, 0, 0, 0, 0, 0, 246, 15, - 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, - 2, 16, 0, 1, 0, 0, 0, 54, 0, 0, 5, 130, 32, 16, 0, - 0, 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 62, 0, 0, - 1, 83, 84, 65, 84, 116, 0, 0, 0, 36, 0, 0, 0, 5, 0, - 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 17, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 45, 0, 0, 7, 242, 0, 16, 0, 0, + 0, 0, 0, 70, 14, 16, 0, 0, 0, 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 54, 0, 0, 8, 226, 0, 16, 0, 0, 0, 0, + 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 45, 0, 0, 7, 242, 0, 16, 0, 0, + 0, 0, 0, 70, 14, 16, 0, 0, 0, 0, 0, 70, 126, 16, 0, + 1, 0, 0, 0, 54, 0, 0, 5, 114, 32, 16, 0, 0, 0, 0, + 0, 70, 2, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 62, + 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 9, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, - 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, + 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, }; namespace GpBinarizedShaders diff --git a/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadRGBP_D3D11.cpp b/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadRGBP_D3D11.cpp index a4a04a0..6f435e8 100644 --- a/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadRGBP_D3D11.cpp +++ b/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadRGBP_D3D11.cpp @@ -1,49 +1,46 @@ static unsigned char gs_shaderData[] = { - 68, 88, 66, 67, 181, 133, 124, 121, 179, 141, 64, 216, 166, 21, 153, - 10, 33, 21, 80, 169, 1, 0, 0, 0, 152, 2, 0, 0, 5, 0, - 0, 0, 52, 0, 0, 0, 224, 0, 0, 0, 56, 1, 0, 0, 108, - 1, 0, 0, 28, 2, 0, 0, 82, 68, 69, 70, 164, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 28, 0, 0, - 0, 0, 4, 255, 255, 0, 137, 0, 0, 122, 0, 0, 0, 92, 0, - 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, - 107, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0, - 0, 255, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, - 0, 0, 115, 117, 114, 102, 97, 99, 101, 83, 97, 109, 112, 108, 101, - 114, 0, 115, 117, 114, 102, 97, 99, 101, 84, 101, 120, 116, 117, 114, - 101, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, - 32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, - 109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 171, 73, - 83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, - 56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, - 0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, - 3, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, - 84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71, - 78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69, - 84, 0, 171, 171, 83, 72, 68, 82, 168, 0, 0, 0, 64, 0, 0, - 0, 42, 0, 0, 0, 90, 0, 0, 3, 0, 96, 16, 0, 0, 0, + 68, 88, 66, 67, 196, 70, 6, 103, 19, 68, 64, 241, 205, 255, 73, + 188, 120, 217, 29, 231, 1, 0, 0, 0, 116, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, 176, 0, 0, 0, 8, 1, 0, 0, 60, + 1, 0, 0, 248, 1, 0, 0, 82, 68, 69, 70, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, + 0, 0, 4, 255, 255, 0, 137, 0, 0, 75, 0, 0, 0, 60, 0, + 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0, 0, 255, + 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 9, 0, 0, 0, + 115, 117, 114, 102, 97, 99, 101, 84, 101, 120, 116, 117, 114, 101, 0, + 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, + 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, + 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 73, 83, 71, 78, + 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, + 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69, 84, 0, 171, + 171, 83, 72, 68, 82, 180, 0, 0, 0, 64, 0, 0, 0, 45, 0, 0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 85, 85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, 101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 104, 0, 0, - 2, 1, 0, 0, 0, 69, 0, 0, 9, 242, 0, 16, 0, 0, 0, - 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 70, 126, 16, 0, 0, - 0, 0, 0, 0, 96, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, - 18, 32, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 0, 0, 0, - 0, 54, 0, 0, 5, 98, 32, 16, 0, 0, 0, 0, 0, 6, 17, - 16, 0, 1, 0, 0, 0, 54, 0, 0, 5, 130, 32, 16, 0, 0, - 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 62, 0, 0, 1, - 83, 84, 65, 84, 116, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 1, 0, 0, 0, 27, 0, 0, 5, 50, 0, 16, 0, 0, 0, + 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 54, 0, 0, 8, 194, + 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, + 7, 242, 0, 16, 0, 0, 0, 0, 0, 70, 14, 16, 0, 0, 0, + 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 114, + 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, 16, 0, 0, 0, 0, 0, 1, 64, 0, + 0, 0, 0, 128, 63, 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, + 0, 0, 6, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; namespace GpBinarizedShaders diff --git a/GpDisplayDriver_D3D11/CompiledShaders/ScaleQuadP_D3D11.cpp b/GpDisplayDriver_D3D11/CompiledShaders/ScaleQuadP_D3D11.cpp new file mode 100644 index 0000000..df926e0 --- /dev/null +++ b/GpDisplayDriver_D3D11/CompiledShaders/ScaleQuadP_D3D11.cpp @@ -0,0 +1,93 @@ +static unsigned char gs_shaderData[] = { + 68, 88, 66, 67, 25, 9, 182, 224, 194, 109, 11, 128, 6, 99, 38, + 219, 209, 198, 219, 152, 1, 0, 0, 0, 252, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, 176, 0, 0, 0, 8, 1, 0, 0, 60, + 1, 0, 0, 128, 4, 0, 0, 82, 68, 69, 70, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, + 0, 0, 4, 255, 255, 0, 137, 0, 0, 75, 0, 0, 0, 60, 0, + 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0, 0, 255, + 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 9, 0, 0, 0, + 115, 117, 114, 102, 97, 99, 101, 84, 101, 120, 116, 117, 114, 101, 0, + 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, + 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, + 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 73, 83, 71, 78, + 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, + 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69, 84, 0, 171, + 171, 83, 72, 68, 82, 60, 3, 0, 0, 64, 0, 0, 0, 207, 0, + 0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 85, + 85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 104, 0, 0, + 2, 5, 0, 0, 0, 11, 0, 0, 5, 18, 0, 16, 0, 0, 0, + 0, 0, 10, 16, 16, 0, 1, 0, 0, 0, 12, 0, 0, 5, 34, + 0, 16, 0, 0, 0, 0, 0, 26, 16, 16, 0, 1, 0, 0, 0, + 50, 0, 0, 13, 194, 0, 16, 0, 0, 0, 0, 0, 6, 4, 16, + 128, 65, 0, 0, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 0, 63, 6, + 20, 16, 0, 1, 0, 0, 0, 52, 0, 0, 10, 194, 0, 16, 0, + 0, 0, 0, 0, 166, 14, 16, 0, 0, 0, 0, 0, 2, 64, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 51, 0, 0, 10, 50, 0, 16, 0, 1, 0, 0, 0, 70, + 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 128, 63, + 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 50, 0, 16, 0, 1, 0, 0, 0, 230, 10, 16, 0, 0, 0, + 0, 0, 70, 0, 16, 0, 1, 0, 0, 0, 65, 0, 0, 5, 194, + 0, 16, 0, 0, 0, 0, 0, 166, 14, 16, 0, 0, 0, 0, 0, + 27, 0, 0, 5, 50, 0, 16, 0, 2, 0, 0, 0, 230, 10, 16, + 0, 0, 0, 0, 0, 65, 0, 0, 5, 194, 0, 16, 0, 0, 0, + 0, 0, 6, 4, 16, 0, 1, 0, 0, 0, 0, 0, 0, 8, 50, + 0, 16, 0, 1, 0, 0, 0, 230, 10, 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 70, 0, 16, 0, 1, 0, 0, 0, 27, 0, 0, + 5, 50, 0, 16, 0, 3, 0, 0, 0, 230, 10, 16, 0, 0, 0, + 0, 0, 14, 32, 0, 7, 50, 0, 16, 0, 0, 0, 0, 0, 70, + 0, 16, 0, 1, 0, 0, 0, 70, 0, 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 66, 0, 16, 0, 2, 0, 0, 0, 1, 64, 0, + 0, 0, 0, 0, 0, 54, 0, 0, 5, 194, 0, 16, 0, 3, 0, + 0, 0, 86, 9, 16, 0, 2, 0, 0, 0, 45, 0, 0, 7, 242, + 0, 16, 0, 1, 0, 0, 0, 70, 15, 16, 0, 3, 0, 0, 0, + 70, 126, 16, 0, 0, 0, 0, 0, 45, 0, 0, 7, 242, 0, 16, + 0, 4, 0, 0, 0, 134, 15, 16, 0, 3, 0, 0, 0, 70, 126, + 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 130, 0, 16, 0, 2, + 0, 0, 0, 26, 0, 16, 0, 3, 0, 0, 0, 45, 0, 0, 7, + 242, 0, 16, 0, 3, 0, 0, 0, 198, 10, 16, 0, 2, 0, 0, + 0, 70, 126, 16, 0, 0, 0, 0, 0, 45, 0, 0, 7, 242, 0, + 16, 0, 2, 0, 0, 0, 70, 10, 16, 0, 2, 0, 0, 0, 70, + 126, 16, 0, 0, 0, 0, 0, 56, 0, 0, 7, 114, 0, 16, 0, + 4, 0, 0, 0, 6, 0, 16, 0, 0, 0, 0, 0, 70, 2, 16, + 0, 4, 0, 0, 0, 56, 0, 0, 7, 114, 0, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 1, + 0, 0, 0, 0, 0, 0, 11, 82, 0, 16, 0, 0, 0, 0, 0, + 6, 1, 16, 128, 65, 0, 0, 0, 0, 0, 0, 0, 2, 64, 0, + 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, + 0, 0, 50, 0, 0, 9, 114, 0, 16, 0, 1, 0, 0, 0, 6, + 0, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 3, 0, 0, 0, + 70, 2, 16, 0, 1, 0, 0, 0, 56, 0, 0, 7, 114, 0, 16, + 0, 1, 0, 0, 0, 86, 5, 16, 0, 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, 50, 0, 0, 9, 178, 0, 16, 0, 0, + 0, 0, 0, 6, 0, 16, 0, 0, 0, 0, 0, 70, 8, 16, 0, + 2, 0, 0, 0, 70, 8, 16, 0, 4, 0, 0, 0, 50, 0, 0, + 9, 114, 32, 16, 0, 0, 0, 0, 0, 166, 10, 16, 0, 0, 0, + 0, 0, 70, 3, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 1, + 0, 0, 0, 54, 0, 0, 5, 130, 32, 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, 128, 63, 62, 0, 0, 1, 83, 84, 65, + 84, 116, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 4, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, +}; + +namespace GpBinarizedShaders +{ + const unsigned char *g_scaleQuadP_D3D11[2] = { gs_shaderData, gs_shaderData + sizeof(gs_shaderData) }; +}; diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp index e1f3fe7..f2b2908 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp +++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp @@ -23,6 +23,7 @@ namespace GpBinarizedShaders extern const unsigned char *g_drawQuadV_D3D11[2]; extern const unsigned char *g_drawQuadPaletteP_D3D11[2]; extern const unsigned char *g_drawQuadRGBP_D3D11[2]; + extern const unsigned char *g_scaleQuadP_D3D11[2]; extern const unsigned char *g_drawQuad15BitP_D3D11[2]; } @@ -200,7 +201,7 @@ bool GpDisplayDriverD3D11::DetachSwapChain() return true; } -bool GpDisplayDriverD3D11::InitBackBuffer() +bool GpDisplayDriverD3D11::InitBackBuffer(uint32_t virtualWidth, uint32_t virtualHeight) { m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast(m_backBufferTexture.GetMutablePtr())); @@ -213,16 +214,61 @@ bool GpDisplayDriverD3D11::InitBackBuffer() rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; rtvDesc.Texture2D.MipSlice = 0; + m_backBufferRTV = nullptr; if (m_device->CreateRenderTargetView(m_backBufferTexture, &rtvDesc, m_backBufferRTV.GetMutablePtr()) != S_OK) return false; } + DXGI_FORMAT vbbFormat = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + + { + D3D11_TEXTURE2D_DESC vbbTextureDesc; + vbbTextureDesc.Width = static_cast(virtualWidth); + vbbTextureDesc.Height = static_cast(virtualHeight); + vbbTextureDesc.MipLevels = 1; + vbbTextureDesc.ArraySize = 1; + vbbTextureDesc.Format = vbbFormat; + vbbTextureDesc.SampleDesc.Count = 1; + vbbTextureDesc.SampleDesc.Quality = 0; + vbbTextureDesc.Usage = D3D11_USAGE_DEFAULT; + vbbTextureDesc.BindFlags = (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET); + vbbTextureDesc.CPUAccessFlags = 0; + vbbTextureDesc.MiscFlags = 0; + + m_virtualScreenTexture = nullptr; + if (m_device->CreateTexture2D(&vbbTextureDesc, nullptr, m_virtualScreenTexture.GetMutablePtr()) != S_OK) + return false; + } + + { + D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; + rtvDesc.Format = vbbFormat; + rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + rtvDesc.Texture2D.MipSlice = 0; + + m_virtualScreenTextureRTV = nullptr; + if (m_device->CreateRenderTargetView(m_virtualScreenTexture, &rtvDesc, m_virtualScreenTextureRTV.GetMutablePtr()) != S_OK) + return false; + } + + { + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + srvDesc.Format = vbbFormat; + srvDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MipLevels = 1; + srvDesc.Texture2D.MostDetailedMip = 0; + + m_virtualScreenTextureSRV = nullptr; + if (m_device->CreateShaderResourceView(m_virtualScreenTexture, &srvDesc, m_virtualScreenTextureSRV.GetMutablePtr()) != S_OK) + return false; + } + return true; } -bool GpDisplayDriverD3D11::InitResources() +bool GpDisplayDriverD3D11::InitResources(uint32_t virtualWidth, uint32_t virtualHeight) { - if (!InitBackBuffer()) + if (!InitBackBuffer(virtualWidth, virtualHeight)) return false; // Quad vertex constant buffer @@ -291,11 +337,13 @@ bool GpDisplayDriverD3D11::InitResources() const GpShaderCodeBlob drawQuadPalettePBlob = GetBinarizedShader(GpBinarizedShaders::g_drawQuadPaletteP_D3D11); const GpShaderCodeBlob drawQuadRGBPBlob = GetBinarizedShader(GpBinarizedShaders::g_drawQuadRGBP_D3D11); const GpShaderCodeBlob drawQuad15BitPBlob = GetBinarizedShader(GpBinarizedShaders::g_drawQuad15BitP_D3D11); + const GpShaderCodeBlob scaleQuadPBlob = GetBinarizedShader(GpBinarizedShaders::g_scaleQuadP_D3D11); m_device->CreateVertexShader(drawQuadVBlob.m_data, drawQuadVBlob.m_size, nullptr, m_drawQuadVertexShader.GetMutablePtr()); m_device->CreatePixelShader(drawQuadPalettePBlob.m_data, drawQuadPalettePBlob.m_size, nullptr, m_drawQuadPalettePixelShader.GetMutablePtr()); m_device->CreatePixelShader(drawQuadRGBPBlob.m_data, drawQuadRGBPBlob.m_size, nullptr, m_drawQuadRGBPixelShader.GetMutablePtr()); m_device->CreatePixelShader(drawQuad15BitPBlob.m_data, drawQuad15BitPBlob.m_size, nullptr, m_drawQuad15BitPixelShader.GetMutablePtr()); + m_device->CreatePixelShader(scaleQuadPBlob.m_data, scaleQuadPBlob.m_size, nullptr, m_scaleQuadPixelShader.GetMutablePtr()); // Quad input layout { @@ -403,17 +451,18 @@ GpDisplayDriverTickStatus_t GpDisplayDriverD3D11::PresentFrameAndSync() { SynchronizeCursors(); - m_deviceContext->ClearRenderTargetView(m_backBufferRTV, m_bgColor); + m_deviceContext->ClearRenderTargetView(m_virtualScreenTextureRTV, m_bgColor); - ID3D11RenderTargetView *const rtv = m_backBufferRTV; - m_deviceContext->OMSetRenderTargets(1, &rtv, nullptr); + //ID3D11RenderTargetView *const rtv = m_backBufferRTV; + ID3D11RenderTargetView *const vsRTV = m_virtualScreenTextureRTV; + m_deviceContext->OMSetRenderTargets(1, &vsRTV, nullptr); { D3D11_VIEWPORT viewport; viewport.TopLeftX = 0; viewport.TopLeftY = 0; - viewport.Width = static_cast(m_windowWidthPhysical); - viewport.Height = static_cast(m_windowHeightPhysical); + viewport.Width = static_cast(m_windowWidthVirtual); + viewport.Height = static_cast(m_windowHeightVirtual); viewport.MinDepth = 0.0f; viewport.MaxDepth = 1.0f; @@ -422,6 +471,8 @@ GpDisplayDriverTickStatus_t GpDisplayDriverD3D11::PresentFrameAndSync() m_properties.m_renderFunc(m_properties.m_renderFuncContext); + ScaleVirtualScreen(); + DXGI_PRESENT_PARAMETERS presentParams; ZeroMemory(&presentParams, sizeof(presentParams)); @@ -539,6 +590,84 @@ GpDisplayDriverTickStatus_t GpDisplayDriverD3D11::PresentFrameAndSync() return GpDisplayDriverTickStatuses::kOK; } +void GpDisplayDriverD3D11::ScaleVirtualScreen() +{ + { + D3D11_VIEWPORT viewport; + viewport.TopLeftX = 0; + viewport.TopLeftY = 0; + viewport.Width = static_cast(m_windowWidthPhysical); + viewport.Height = static_cast(m_windowHeightPhysical); + viewport.MinDepth = 0.0f; + viewport.MaxDepth = 1.0f; + + m_deviceContext->RSSetViewports(1, &viewport); + } + + + ID3D11Buffer *vbPtr = m_quadVertexBuffer; + UINT vbStride = sizeof(float) * 2; + UINT zero = 0; + + ID3D11RenderTargetView *const rtv = m_backBufferRTV; + m_deviceContext->OMSetRenderTargets(1, &rtv, nullptr); + + //m_deviceContext->OMSetDepthStencilState(m_drawQuadDepthStencilState, 0); + + { + const float twoDivWidth = 2.0f / static_cast(m_windowWidthPhysical); + const float negativeTwoDivHeight = -2.0f / static_cast(m_windowHeightPhysical); + + DrawQuadVertexConstants constantsData; + constantsData.m_ndcOriginX = -1.0f; + constantsData.m_ndcOriginY = 1.0f; + constantsData.m_ndcWidth = static_cast(m_windowWidthPhysical) * twoDivWidth; + constantsData.m_ndcHeight = static_cast(m_windowHeightPhysical) * negativeTwoDivHeight; + + constantsData.m_surfaceDimensionX = static_cast(m_windowWidthVirtual); + constantsData.m_surfaceDimensionY = static_cast(m_windowHeightVirtual); + + D3D11_MAPPED_SUBRESOURCE mappedConstants; + if (m_deviceContext->Map(m_drawQuadVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedConstants) == S_OK) + { + memcpy(mappedConstants.pData, &constantsData, sizeof(constantsData)); + m_deviceContext->Unmap(m_drawQuadVertexConstantBuffer, 0); + } + } + + m_deviceContext->IASetVertexBuffers(0, 1, &vbPtr, &vbStride, &zero); + m_deviceContext->IASetIndexBuffer(m_quadIndexBuffer, DXGI_FORMAT_R16_UINT, 0); + m_deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + m_deviceContext->IASetInputLayout(m_drawQuadInputLayout); + + ID3D11Buffer *vsConstants = m_drawQuadVertexConstantBuffer; + m_deviceContext->VSSetShader(m_drawQuadVertexShader, nullptr, 0); + m_deviceContext->VSSetConstantBuffers(0, 1, &vsConstants); + + ID3D11SamplerState *samplerStates[] = + { + m_nearestNeighborSamplerState, + }; + m_deviceContext->PSSetSamplers(0, sizeof(samplerStates) / sizeof(samplerStates[0]), samplerStates); + + + ID3D11ShaderResourceView *psResourceViews[] = + { + m_virtualScreenTextureSRV, + }; + + m_deviceContext->PSSetShader(m_scaleQuadPixelShader, nullptr, 0); + m_deviceContext->PSSetShaderResources(0, sizeof(psResourceViews) / sizeof(psResourceViews[0]), psResourceViews); + + m_deviceContext->DrawIndexed(6, 0, 0); + + ID3D11ShaderResourceView *unbindPSResourceViews[] = + { + 0, + }; + m_deviceContext->PSSetShaderResources(0, sizeof(unbindPSResourceViews) / sizeof(unbindPSResourceViews[0]), unbindPSResourceViews); +} + void GpDisplayDriverD3D11::SynchronizeCursors() { HCURSOR replacementCursor = nullptr; @@ -745,7 +874,7 @@ void GpDisplayDriverD3D11::Run() StartD3DForWindow(m_osGlobals->m_hwnd, m_swapChain, m_device, m_deviceContext); - InitResources(); + InitResources(m_windowWidthVirtual, m_windowHeightVirtual); LARGE_INTEGER lastTimestamp; memset(&lastTimestamp, 0, sizeof(lastTimestamp)); @@ -809,7 +938,7 @@ void GpDisplayDriverD3D11::Run() bool resizedOK = ResizeD3DWindow(m_osGlobals->m_hwnd, m_windowWidthPhysical, m_windowHeightPhysical, desiredWidth, desiredHeight, windowStyle, menus); resizedOK = resizedOK && DetachSwapChain(); resizedOK = resizedOK && ResizeSwapChain(m_swapChain, m_windowWidthPhysical, m_windowHeightPhysical); - resizedOK = resizedOK && InitBackBuffer(); + resizedOK = resizedOK && InitBackBuffer(virtualWidth, virtualHeight); if (!resizedOK) break; // Critical video driver error, exit diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h index bee4905..a367817 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h +++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h @@ -75,9 +75,10 @@ private: ~GpDisplayDriverD3D11(); bool DetachSwapChain(); - bool InitBackBuffer(); - bool InitResources(); + bool InitBackBuffer(uint32_t virtualWidth, uint32_t virtualHeight); + bool InitResources(uint32_t virtualWidth, uint32_t virtualHeight); GpDisplayDriverTickStatus_t PresentFrameAndSync(); + void ScaleVirtualScreen(); void SynchronizeCursors(); void ChangeToCursor(HCURSOR cursor); @@ -96,6 +97,7 @@ private: GpComPtr m_drawQuadPalettePixelShader; GpComPtr m_drawQuad15BitPixelShader; GpComPtr m_drawQuadRGBPixelShader; + GpComPtr m_scaleQuadPixelShader; GpComPtr m_drawQuadVertexConstantBuffer; GpComPtr m_drawQuadDepthStencilState; GpComPtr m_nearestNeighborSamplerState; @@ -105,6 +107,10 @@ private: GpComPtr m_backBufferTexture; GpComPtr m_backBufferRTV; + GpComPtr m_virtualScreenTexture; + GpComPtr m_virtualScreenTextureRTV; + GpComPtr m_virtualScreenTextureSRV; + GpRingBuffer m_presentHistory; GpDisplayDriverProperties m_properties; diff --git a/GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj b/GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj index 80ef8c6..433e1b7 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj +++ b/GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj @@ -127,6 +127,7 @@ + diff --git a/GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj.filters b/GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj.filters index 9f22b4f..b99af81 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj.filters +++ b/GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj.filters @@ -39,6 +39,9 @@ Source Files\CompiledShaders + + Source Files\CompiledShaders + diff --git a/ShaderSrc/DrawQuadPaletteP.hlsl b/ShaderSrc/DrawQuadPaletteP.hlsl index f1bd455..f1e78ca 100644 --- a/ShaderSrc/DrawQuadPaletteP.hlsl +++ b/ShaderSrc/DrawQuadPaletteP.hlsl @@ -17,28 +17,8 @@ float3 SamplePixel(int2 texCoord) SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input) { - float dx = ddx(input.texCoord.x); - float dy = ddy(input.texCoord.y); - - float2 pixelTopLeftCoord = max(0.0, input.texCoord.xy - float2(dx, dy) * 0.5); - float2 pixelBottomRightCoord = pixelTopLeftCoord + min(float2(1.0, 1.0), float2(dx, dy)); - - int2 topLeftCoordInteger = int2(floor(pixelTopLeftCoord)); - int2 bottomRightCoordInteger = int2(floor(pixelBottomRightCoord)); - - float2 interpolators = saturate((pixelBottomRightCoord - float2(bottomRightCoordInteger)) / float2(dx, dy)); - - float3 topLeftColor = SamplePixel(topLeftCoordInteger); - float3 topRightColor = SamplePixel(int2(bottomRightCoordInteger.x, topLeftCoordInteger.y)); - float3 bottomLeftColor = SamplePixel(int2(topLeftCoordInteger.x, bottomRightCoordInteger.y)); - float3 bottomRightColor = SamplePixel(bottomRightCoordInteger); - - float3 topColor = (1.0 - interpolators.x) * topLeftColor + interpolators.x * topRightColor; - float3 bottomColor = (1.0 - interpolators.x) * bottomLeftColor + interpolators.x * bottomRightColor; - float3 interpolatedColor = (1.0 - interpolators.y) * topColor + interpolators.y * bottomColor; - SDrawQuadPixelOutput result; - result.color = float4(interpolatedColor, 1.0); + result.color = float4(SamplePixel(int2(floor(input.texCoord.xy))), 1.0); return result; } diff --git a/ShaderSrc/DrawQuadRGBP.hlsl b/ShaderSrc/DrawQuadRGBP.hlsl index 7655517..92177c4 100644 --- a/ShaderSrc/DrawQuadRGBP.hlsl +++ b/ShaderSrc/DrawQuadRGBP.hlsl @@ -1,7 +1,7 @@ #include "DrawQuad.h" SamplerState surfaceSampler : register(s0); -Texture2D surfaceTexture : register(t0); +Texture2D surfaceTexture : register(t0); struct SDrawQuadPixelOutput { @@ -10,9 +10,9 @@ struct SDrawQuadPixelOutput SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input) { - float surfaceColor = surfaceTexture.Sample(surfaceSampler, input.texCoord.xy).r; + float3 surfaceColor = surfaceTexture.Load(int3(input.texCoord.xy, 0)).rgb; SDrawQuadPixelOutput result; - result.color = float4(surfaceColor, input.texCoord.x, input.texCoord.y, 1.0); + result.color = float4(surfaceColor, 1.0); return result; } diff --git a/ShaderSrc/ScaleQuadP.hlsl b/ShaderSrc/ScaleQuadP.hlsl new file mode 100644 index 0000000..ca4c1d7 --- /dev/null +++ b/ShaderSrc/ScaleQuadP.hlsl @@ -0,0 +1,41 @@ +#include "DrawQuad.h" + +SamplerState surfaceSampler : register(s0); +Texture2D surfaceTexture : register(t0); + +struct SDrawQuadPixelOutput +{ + float4 color : SV_TARGET; +}; + +float3 SamplePixel(int2 coord) +{ + return surfaceTexture.Load(int3(coord, 0)).rgb; +} + +SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input) +{ + float dx = ddx(input.texCoord.x); + float dy = ddy(input.texCoord.y); + + float2 pixelTopLeftCoord = max(0.0, input.texCoord.xy - float2(dx, dy) * 0.5); + float2 pixelBottomRightCoord = pixelTopLeftCoord + min(float2(1.0, 1.0), float2(dx, dy)); + + int2 topLeftCoordInteger = int2(floor(pixelTopLeftCoord)); + int2 bottomRightCoordInteger = int2(floor(pixelBottomRightCoord)); + + float2 interpolators = saturate((pixelBottomRightCoord - float2(bottomRightCoordInteger)) / float2(dx, dy)); + + float3 topLeftColor = SamplePixel(topLeftCoordInteger); + float3 topRightColor = SamplePixel(int2(bottomRightCoordInteger.x, topLeftCoordInteger.y)); + float3 bottomLeftColor = SamplePixel(int2(topLeftCoordInteger.x, bottomRightCoordInteger.y)); + float3 bottomRightColor = SamplePixel(bottomRightCoordInteger); + + float3 topColor = (1.0 - interpolators.x) * topLeftColor + interpolators.x * topRightColor; + float3 bottomColor = (1.0 - interpolators.x) * bottomLeftColor + interpolators.x * bottomRightColor; + float3 interpolatedColor = (1.0 - interpolators.y) * topColor + interpolators.y * bottomColor; + + SDrawQuadPixelOutput result; + result.color = float4(interpolatedColor, 1.0); + return result; +}