From 2e28ed3291bc531ba5d0cd4057aa9cefdbf128be Mon Sep 17 00:00:00 2001 From: booto Date: Tue, 7 Jul 2015 21:09:25 +0800 Subject: Video: respect stride of efb copies to xfb --- Source/Core/VideoBackends/OGL/TextureConverter.cpp | 40 +++++++++------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/TextureConverter.cpp') diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp index c696ccf687..c25d30d088 100644 --- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp @@ -213,12 +213,12 @@ void Shutdown() s_texConvFrameBuffer[1] = 0; } +// dst_line_size, writeStride in bytes + static void EncodeToRamUsingShader(GLuint srcTexture, - u8* destAddr, int dstWidth, int dstHeight, int readStride, - bool linearFilter) + u8* destAddr, u32 dst_line_size, u32 dstHeight, + u32 writeStride, bool linearFilter) { - - // switch to texture converter frame buffer // attach render buffer as color destination FramebufferManager::SetFramebuffer(s_texConvFrameBuffer[0]); @@ -234,19 +234,13 @@ static void EncodeToRamUsingShader(GLuint srcTexture, else g_sampler_cache->BindNearestSampler(9); - glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight); + glViewport(0, 0, (GLsizei)(dst_line_size / 4), (GLsizei)dstHeight); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - // .. and then read back the results. - // TODO: make this less slow. - - int writeStride = bpmem.copyMipMapStrideChannels * 32; - int dstSize = dstWidth*dstHeight*4; - int readHeight = readStride / dstWidth / 4; // 4 bytes per pixel - int readLoops = dstHeight / readHeight; + int dstSize = dst_line_size * dstHeight; - if (writeStride != readStride && readLoops > 1) + if ((writeStride != dst_line_size) && (dstHeight > 1)) { // writing to a texture of a different size // also copy more then one block line, so the different strides matters @@ -255,13 +249,13 @@ static void EncodeToRamUsingShader(GLuint srcTexture, // CPU overhead because of the pbo glBindBuffer(GL_PIXEL_PACK_BUFFER, s_PBO); glBufferData(GL_PIXEL_PACK_BUFFER, dstSize, nullptr, GL_STREAM_READ); - glReadPixels(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, nullptr); + glReadPixels(0, 0, (GLsizei)(dst_line_size / 4), (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, nullptr); u8* pbo = (u8*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, dstSize, GL_MAP_READ_BIT); - for (int i = 0; i < readLoops; i++) + for (size_t i = 0; i < dstHeight; ++i) { - memcpy(destAddr, pbo, readStride); - pbo += readStride; + memcpy(destAddr, pbo, dst_line_size); + pbo += dst_line_size; destAddr += writeStride; } @@ -270,11 +264,11 @@ static void EncodeToRamUsingShader(GLuint srcTexture, } else { - glReadPixels(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, destAddr); + glReadPixels(0, 0, (GLsizei)(dst_line_size / 4), (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, destAddr); } } -int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source) +int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source, u32 writeStride) { u32 format = copyfmt; @@ -323,13 +317,13 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, cacheLinesPerRow = numBlocksX; EncodeToRamUsingShader(source_texture, - dest_ptr, cacheLinesPerRow * 8, numBlocksY, cacheLinesPerRow * 32, - bScaleByHalf > 0 && !bFromZBuffer); + dest_ptr, cacheLinesPerRow * 32, numBlocksY, + writeStride, bScaleByHalf > 0 && !bFromZBuffer); return size_in_bytes; // TODO: D3D11 is calculating this value differently! } -void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, int dstWidth, int dstHeight) +void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, u32 dstWidth, u32 dstStride, u32 dstHeight) { g_renderer->ResetAPIState(); @@ -341,7 +335,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des // We enable linear filtering, because the GameCube does filtering in the vertical direction when // yscale is enabled. // Otherwise we get jaggies when a game uses yscaling (most PAL games) - EncodeToRamUsingShader(srcTexture, destAddr, dstWidth / 2, dstHeight, dstWidth*dstHeight*2, true); + EncodeToRamUsingShader(srcTexture, destAddr, dstWidth * 2, dstHeight, dstStride * 2, true); FramebufferManager::SetFramebuffer(0); TextureCache::DisableStage(0); g_renderer->RestoreAPIState(); -- cgit v1.2.3 From efd250494d62272451bed3257771f6dae6edb695 Mon Sep 17 00:00:00 2001 From: booto Date: Sat, 25 Jul 2015 02:48:56 +0800 Subject: Video: stride in bytes rather than pixels --- Source/Core/VideoBackends/OGL/TextureConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/OGL/TextureConverter.cpp') diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp index c25d30d088..53b615a5aa 100644 --- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp @@ -335,7 +335,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des // We enable linear filtering, because the GameCube does filtering in the vertical direction when // yscale is enabled. // Otherwise we get jaggies when a game uses yscaling (most PAL games) - EncodeToRamUsingShader(srcTexture, destAddr, dstWidth * 2, dstHeight, dstStride * 2, true); + EncodeToRamUsingShader(srcTexture, destAddr, dstWidth * 2, dstHeight, dstStride, true); FramebufferManager::SetFramebuffer(0); TextureCache::DisableStage(0); g_renderer->RestoreAPIState(); -- cgit v1.2.3 From c80e3089c8465bdf48f178639ae6ee1928d3dc23 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 12 Aug 2015 17:31:18 -0500 Subject: [GLES] Fix real XFB. GLES doesn't support the BGRA texture format type, just use RGBA. --- Source/Core/VideoBackends/OGL/TextureConverter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/TextureConverter.cpp') diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp index 53b615a5aa..c85b617294 100644 --- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp @@ -121,7 +121,7 @@ static void CreatePrograms() // We switch top/bottom here. TODO: move this to screen blit. " ivec2 ts = textureSize(samp9, 0);\n" " vec4 c0 = texelFetch(samp9, ivec2(uv.x>>1, ts.y-uv.y-1), 0);\n" - " float y = mix(c0.b, c0.r, (uv.x & 1) == 1);\n" + " float y = mix(c0.r, c0.b, (uv.x & 1) == 1);\n" " float yComp = 1.164 * (y - 0.0625);\n" " float uComp = c0.g - 0.5;\n" " float vComp = c0.a - 0.5;\n" @@ -365,7 +365,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur // set srcAddr as data for source texture glActiveTexture(GL_TEXTURE9); glBindTexture(GL_TEXTURE_2D, s_srcTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, srcWidth / 2, srcHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, srcAddr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, srcWidth / 2, srcHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, srcAddr); g_sampler_cache->BindNearestSampler(9); glViewport(0, 0, srcWidth, srcHeight); -- cgit v1.2.3 From b9be3245e1bcd3929baf4d1c66fe5a14b336cdbc Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sat, 5 Sep 2015 02:45:29 +1200 Subject: Move common EFB copy code into VideoCommon Addded a few duplicated depth copy texture formats to the enum in TextureDecoder.h. These texture formats were already implemented in TextureCacheBase and the ogl/dx11 texture cache implementations. --- Source/Core/VideoBackends/OGL/TextureConverter.cpp | 55 +++------------------- 1 file changed, 7 insertions(+), 48 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/TextureConverter.cpp') diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp index c85b617294..5020058da0 100644 --- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp @@ -268,59 +268,18 @@ static void EncodeToRamUsingShader(GLuint srcTexture, } } -int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source, u32 writeStride) +void EncodeToRamFromTexture(u8 *dest_ptr, const TextureCache::TCacheEntryBase *texture_entry, + GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, int bScaleByHalf, const EFBRectangle& source) { - u32 format = copyfmt; - - if (bFromZBuffer) - { - format |= _GX_TF_ZTF; - if (copyfmt == 11) - format = GX_TF_Z16; - else if (format < GX_TF_Z8 || format > GX_TF_Z24X8) - format |= _GX_TF_CTF; - } - else - { - if (copyfmt > GX_TF_RGBA8 || (copyfmt < GX_TF_RGB565 && !bIsIntensityFmt)) - format |= _GX_TF_CTF; - } - - SHADER& texconv_shader = GetOrCreateEncodingShader(format); - - u8 *dest_ptr = Memory::GetPointer(address); - - int width = (source.right - source.left) >> bScaleByHalf; - int height = (source.bottom - source.top) >> bScaleByHalf; - - int size_in_bytes = TexDecoder_GetTextureSizeInBytes(width, height, format); - - u16 blkW = TexDecoder_GetBlockWidthInTexels(format) - 1; - u16 blkH = TexDecoder_GetBlockHeightInTexels(format) - 1; - - // only copy on cache line boundaries - // extra pixels are copied but not displayed in the resulting texture - s32 expandedWidth = (width + blkW) & (~blkW); - s32 expandedHeight = (height + blkH) & (~blkH); + SHADER& texconv_shader = GetOrCreateEncodingShader(texture_entry->format); texconv_shader.Bind(); - glUniform4i(s_encodingUniforms[format], - source.left, source.top, - expandedWidth, bScaleByHalf ? 2 : 1); - - unsigned int numBlocksX = expandedWidth / TexDecoder_GetBlockWidthInTexels(format); - unsigned int numBlocksY = expandedHeight / TexDecoder_GetBlockHeightInTexels(format); - unsigned int cacheLinesPerRow; - if ((format & 0x0f) == 6) - cacheLinesPerRow = numBlocksX * 2; - else - cacheLinesPerRow = numBlocksX; + glUniform4i(s_encodingUniforms[texture_entry->format], + source.left, source.top, texture_entry->native_width, bScaleByHalf ? 2 : 1); EncodeToRamUsingShader(source_texture, - dest_ptr, cacheLinesPerRow * 32, numBlocksY, - writeStride, bScaleByHalf > 0 && !bFromZBuffer); - return size_in_bytes; // TODO: D3D11 is calculating this value differently! - + dest_ptr, texture_entry->CacheLinesPerRow() * 32, texture_entry->NumBlocksY(), + texture_entry->memory_stride, bScaleByHalf > 0 && !bFromZBuffer); } void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* destAddr, u32 dstWidth, u32 dstStride, u32 dstHeight) -- cgit v1.2.3