From ef75f3005d5e09edaa739d298f644be1f28e3f19 Mon Sep 17 00:00:00 2001 From: magumagu Date: Sun, 25 Jan 2015 15:49:35 -0800 Subject: WIP. --- .../Core/VideoCommon/TextureConversionShader.cpp | 35 +++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'Source/Core/VideoCommon/TextureConversionShader.cpp') diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index 8734eb42c3..3e09113518 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -70,21 +70,24 @@ static void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, " out vec4 ocol0;\n"); WRITE(p, "void main()\n"); + WRITE(p, "{\n" + " int2 sampleUv;\n" + " int2 uv1 = int2(gl_FragCoord.xy);\n" + ); } else // D3D { - WRITE(p,"sampler samp0 : register(s0);\n"); + WRITE(p, "sampler samp0 : register(s0);\n"); WRITE(p, "Texture2D Tex0 : register(t0);\n"); - WRITE(p,"void main(\n"); - WRITE(p," out float4 ocol0 : SV_Target)\n"); + WRITE(p, "void main(\n"); + WRITE(p, " out float4 ocol0 : SV_Target, in float4 rawpos : SV_Position)\n"); + WRITE(p, "{\n" + " int2 sampleUv;\n" + " int2 uv1 = int2((rawpos + 1) / 2 * float2(640, 528));\n" + ); } - WRITE(p, "{\n" - " int2 sampleUv;\n" - " int2 uv1 = int2(gl_FragCoord.xy);\n" - ); - WRITE(p, " int y_block_position = uv1.y & %d;\n", ~(blkH - 1)); WRITE(p, " int y_offset_in_block = uv1.y & %d;\n", blkH - 1); WRITE(p, " int x_virtual_position = (uv1.x << %d) + y_offset_in_block * position.z;\n", IntLog2(samples)); @@ -116,9 +119,18 @@ static void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) static void WriteSampleColor(char*& p, const char* colorComp, const char* dest, int xoffset, API_TYPE ApiType) { - WRITE(p, " %s = texture(samp0, float3(uv0 + float2(%d, 0) * sample_offset, 0.0)).%s;\n", - dest, xoffset, colorComp - ); + if (ApiType == API_OPENGL) + { + WRITE(p, " %s = texture(samp0, float3(uv0 + float2(%d, 0) * sample_offset, 0.0)).%s;\n", + dest, xoffset, colorComp + ); + } + else + { + WRITE(p, " %s = Tex0.Sample(samp0, float3(uv0 + float2(%d, 0) * sample_offset, 0.0)).%s;\n", + dest, xoffset, colorComp + ); + } } static void WriteColorToIntensity(char*& p, const char* src, const char* dest) @@ -134,6 +146,7 @@ static void WriteColorToIntensity(char*& p, const char* src, const char* dest) static void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest) { + //WRITE(p, " ocol0 = float4(1,1,1,1;\n"); WRITE(p, " %s = floor(%s * 255.0 / exp2(8.0 - %d.0));\n", dest, src, depth); } -- cgit v1.2.3 From 6c1bdfe04cd12cbc75c86d6b71472393443426a5 Mon Sep 17 00:00:00 2001 From: magumagu Date: Sun, 25 Jan 2015 17:22:29 -0800 Subject: More work. --- Source/Core/VideoCommon/TextureConversionShader.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoCommon/TextureConversionShader.cpp') diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index 3e09113518..e7600d6248 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -84,7 +84,7 @@ static void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, " out float4 ocol0 : SV_Target, in float4 rawpos : SV_Position)\n"); WRITE(p, "{\n" " int2 sampleUv;\n" - " int2 uv1 = int2((rawpos + 1) / 2 * float2(640, 528));\n" + " int2 uv1 = int2(rawpos.xy);\n" ); } @@ -127,7 +127,7 @@ static void WriteSampleColor(char*& p, const char* colorComp, const char* dest, } else { - WRITE(p, " %s = Tex0.Sample(samp0, float3(uv0 + float2(%d, 0) * sample_offset, 0.0)).%s;\n", + WRITE(p, " %s = Tex0.Sample(samp0, uv0 + float2(%d, 0) * sample_offset).%s;\n", dest, xoffset, colorComp ); } @@ -146,7 +146,6 @@ static void WriteColorToIntensity(char*& p, const char* src, const char* dest) static void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest) { - //WRITE(p, " ocol0 = float4(1,1,1,1;\n"); WRITE(p, " %s = floor(%s * 255.0 / exp2(8.0 - %d.0));\n", dest, src, depth); } -- cgit v1.2.3 From b0b99b69229c1c76c6eca51583a47090bd2e383c Mon Sep 17 00:00:00 2001 From: magumagu Date: Sun, 25 Jan 2015 19:48:29 -0800 Subject: Fix shader so it's possible to use with D3D Map(). Well, that's not strictly true, but trying to memcpy between two buffers using different row lengths and different strides is at minimum extremely unintuitive. --- Source/Core/VideoCommon/TextureConversionShader.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'Source/Core/VideoCommon/TextureConversionShader.cpp') diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index e7600d6248..ebb3b065fd 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -88,21 +88,19 @@ static void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) ); } - WRITE(p, " int y_block_position = uv1.y & %d;\n", ~(blkH - 1)); - WRITE(p, " int y_offset_in_block = uv1.y & %d;\n", blkH - 1); - WRITE(p, " int x_virtual_position = (uv1.x << %d) + y_offset_in_block * position.z;\n", IntLog2(samples)); - WRITE(p, " int x_block_position = (x_virtual_position >> %d) & %d;\n", IntLog2(blkH), ~(blkW - 1)); + WRITE(p, " int x_block_position = (uv1.x >> %d) << %d;\n", IntLog2(blkH * blkW / samples), IntLog2(blkW)); + WRITE(p, " int y_block_position = uv1.y << %d;\n", IntLog2(blkH)); + WRITE(p, " int offset_in_block = uv1.x & %d;\n", (blkH * blkW / samples) - 1); + WRITE(p, " int y_offset_in_block = offset_in_block >> %d;\n", IntLog2(blkW / samples)); + WRITE(p, " int x_offset_in_block = (offset_in_block & %d) << %d;\n", (blkW / samples) - 1, IntLog2(samples)); if (samples == 1) { - // 32 bit textures (RGBA8 and Z24) are stored in 2 cache line increments - WRITE(p, " bool first = 0 == (x_virtual_position & %d);\n", 8 * samples); // first cache line, used in the encoders - WRITE(p, " x_virtual_position = x_virtual_position << 1;\n"); + WRITE(p, " bool first = 0 == (x_block_position & %d);\n", blkW); + WRITE(p, " x_block_position >>= 1;\n", blkW); } - WRITE(p, " int x_offset_in_block = x_virtual_position & %d;\n", blkW - 1); - WRITE(p, " int y_offset = (x_virtual_position >> %d) & %d;\n", IntLog2(blkW), blkH - 1); - WRITE(p, " sampleUv.x = x_offset_in_block + x_block_position;\n"); - WRITE(p, " sampleUv.y = y_block_position + y_offset;\n"); + WRITE(p, " sampleUv.x = x_block_position + x_offset_in_block;\n"); + WRITE(p, " sampleUv.y = y_block_position + y_offset_in_block;\n"); WRITE(p, " float2 uv0 = float2(sampleUv);\n"); // sampleUv is the sample position in (int)gx_coords WRITE(p, " uv0 += float2(0.5, 0.5);\n"); // move to center of pixel -- cgit v1.2.3 From 92189823f3d07045431191267c807cf898a066b5 Mon Sep 17 00:00:00 2001 From: magumagu Date: Sun, 25 Jan 2015 22:53:30 -0800 Subject: Fix RGBA8 encoding. --- Source/Core/VideoCommon/TextureConversionShader.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoCommon/TextureConversionShader.cpp') diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index ebb3b065fd..1c56621dc2 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -90,14 +90,15 @@ static void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, " int x_block_position = (uv1.x >> %d) << %d;\n", IntLog2(blkH * blkW / samples), IntLog2(blkW)); WRITE(p, " int y_block_position = uv1.y << %d;\n", IntLog2(blkH)); - WRITE(p, " int offset_in_block = uv1.x & %d;\n", (blkH * blkW / samples) - 1); - WRITE(p, " int y_offset_in_block = offset_in_block >> %d;\n", IntLog2(blkW / samples)); - WRITE(p, " int x_offset_in_block = (offset_in_block & %d) << %d;\n", (blkW / samples) - 1, IntLog2(samples)); if (samples == 1) { - WRITE(p, " bool first = 0 == (x_block_position & %d);\n", blkW); - WRITE(p, " x_block_position >>= 1;\n", blkW); + // With samples == 1, we write out pairs of blocks; one A8R8, one G8B8. + WRITE(p, " bool first = !(uv1.x & %d);\n", blkH * blkW / 2); + samples = 2; } + WRITE(p, " int offset_in_block = uv1.x & %d;\n", (blkH * blkW / samples) - 1); + WRITE(p, " int y_offset_in_block = offset_in_block >> %d;\n", IntLog2(blkW / samples)); + WRITE(p, " int x_offset_in_block = (offset_in_block & %d) << %d;\n", (blkW / samples) - 1, IntLog2(samples)); WRITE(p, " sampleUv.x = x_block_position + x_offset_in_block;\n"); WRITE(p, " sampleUv.y = y_block_position + y_offset_in_block;\n"); -- cgit v1.2.3 From b56025e6eb30034eb522049355c3547e0e513ed2 Mon Sep 17 00:00:00 2001 From: magumagu Date: Sun, 25 Jan 2015 23:28:39 -0800 Subject: Don't use boolean negation. --- Source/Core/VideoCommon/TextureConversionShader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/TextureConversionShader.cpp') diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index 1c56621dc2..ab7ab643d1 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -93,7 +93,7 @@ static void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) if (samples == 1) { // With samples == 1, we write out pairs of blocks; one A8R8, one G8B8. - WRITE(p, " bool first = !(uv1.x & %d);\n", blkH * blkW / 2); + WRITE(p, " bool first = (uv1.x & %d) == 0;\n", blkH * blkW / 2); samples = 2; } WRITE(p, " int offset_in_block = uv1.x & %d;\n", (blkH * blkW / samples) - 1); -- cgit v1.2.3