From e49568f67d7c04db725df17123f499f6fe02dd08 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 16 Dec 2018 14:48:33 -0800 Subject: [PATCH] GLES: Move depth packing code to dedicated file. --- CMakeLists.txt | 1 + GPU/GLES/DepthBufferGLES.cpp | 64 +++++++++++++++++++++++++++++ GPU/GLES/FramebufferManagerGLES.cpp | 42 ------------------- GPU/GPU.vcxproj | 1 + GPU/GPU.vcxproj.filters | 3 ++ android/jni/Android.mk | 1 + libretro/Makefile.common | 1 + 7 files changed, 71 insertions(+), 42 deletions(-) create mode 100644 GPU/GLES/DepthBufferGLES.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e27986c643..4394ff27c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1223,6 +1223,7 @@ endif() set(GPU_GLES GPU/GLES/DepalettizeShaderGLES.cpp GPU/GLES/DepalettizeShaderGLES.h + GPU/GLES/DepthBufferGLES.cpp GPU/GLES/GPU_GLES.cpp GPU/GLES/GPU_GLES.h GPU/GLES/FragmentShaderGeneratorGLES.cpp diff --git a/GPU/GLES/DepthBufferGLES.cpp b/GPU/GLES/DepthBufferGLES.cpp new file mode 100644 index 0000000000..d142f8b9a4 --- /dev/null +++ b/GPU/GLES/DepthBufferGLES.cpp @@ -0,0 +1,64 @@ +// Copyright (c) 2012- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include + +#include "Core/Reporting.h" +#include "GPU/Common/GPUStateUtils.h" +#include "GPU/GLES/FramebufferManagerGLES.h" + +void FramebufferManagerGLES::PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h) { + if (!vfb->fbo) { + ERROR_LOG_REPORT_ONCE(vfbfbozero, SCEGE, "PackDepthbuffer: vfb->fbo == 0"); + return; + } + + // Pixel size always 4 here because we always request float + const u32 bufSize = vfb->z_stride * (h - y) * 4; + const u32 z_address = vfb->z_address; + const int packWidth = std::min(vfb->z_stride, std::min(x + w, (int)vfb->width)); + + if (!convBuf_ || convBufSize_ < bufSize) { + delete[] convBuf_; + convBuf_ = new u8[bufSize]; + convBufSize_ = bufSize; + } + + DEBUG_LOG(FRAMEBUF, "Reading depthbuffer to mem at %08x for vfb=%08x", z_address, vfb->fb_address); + + draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_DEPTH_BIT, 0, y, packWidth, h, Draw::DataFormat::D32F, convBuf_, vfb->z_stride); + + int dstByteOffset = y * vfb->z_stride * sizeof(u16); + u16 *depth = (u16 *)Memory::GetPointer(z_address + dstByteOffset); + GLfloat *packed = (GLfloat *)convBuf_; + + int totalPixels = h == 1 ? packWidth : vfb->z_stride * h; + for (int yp = 0; yp < h; ++yp) { + int row_offset = vfb->z_stride * yp; + for (int xp = 0; xp < packWidth; ++xp) { + const int i = row_offset + xp; + float scaled = FromScaledDepth(packed[i]); + if (scaled <= 0.0f) { + depth[i] = 0; + } else if (scaled >= 65535.0f) { + depth[i] = 65535; + } else { + depth[i] = (int)scaled; + } + } + } +} diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index 780735da13..144ca24dc7 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -650,48 +650,6 @@ void FramebufferManagerGLES::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_RASTER_STATE); } -void FramebufferManagerGLES::PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h) { - if (!vfb->fbo) { - ERROR_LOG_REPORT_ONCE(vfbfbozero, SCEGE, "PackDepthbuffer: vfb->fbo == 0"); - return; - } - - // Pixel size always 4 here because we always request float - const u32 bufSize = vfb->z_stride * (h - y) * 4; - const u32 z_address = (0x04000000) | vfb->z_address; - const int packWidth = std::min(vfb->z_stride, std::min(x + w, (int)vfb->width)); - - if (!convBuf_ || convBufSize_ < bufSize) { - delete [] convBuf_; - convBuf_ = new u8[bufSize]; - convBufSize_ = bufSize; - } - - DEBUG_LOG(FRAMEBUF, "Reading depthbuffer to mem at %08x for vfb=%08x", z_address, vfb->fb_address); - - draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_DEPTH_BIT, 0, y, packWidth, h, Draw::DataFormat::D32F, convBuf_, vfb->z_stride); - - int dstByteOffset = y * vfb->z_stride * sizeof(u16); - u16 *depth = (u16 *)Memory::GetPointer(z_address + dstByteOffset); - GLfloat *packed = (GLfloat *)convBuf_; - - int totalPixels = h == 1 ? packWidth : vfb->z_stride * h; - for (int yp = 0; yp < h; ++yp) { - int row_offset = vfb->z_stride * yp; - for (int xp = 0; xp < packWidth; ++xp) { - const int i = row_offset + xp; - float scaled = FromScaledDepth(packed[i]); - if (scaled <= 0.0f) { - depth[i] = 0; - } else if (scaled >= 65535.0f) { - depth[i] = 65535; - } else { - depth[i] = (int)scaled; - } - } - } -} - void FramebufferManagerGLES::EndFrame() { } diff --git a/GPU/GPU.vcxproj b/GPU/GPU.vcxproj index c3f2a1aa10..13264c837c 100644 --- a/GPU/GPU.vcxproj +++ b/GPU/GPU.vcxproj @@ -339,6 +339,7 @@ + diff --git a/GPU/GPU.vcxproj.filters b/GPU/GPU.vcxproj.filters index 1710c3f790..76b0113d10 100644 --- a/GPU/GPU.vcxproj.filters +++ b/GPU/GPU.vcxproj.filters @@ -548,5 +548,8 @@ Debugger + + GLES + \ No newline at end of file diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 1ed3b4eb69..7e5d2829d6 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -247,6 +247,7 @@ EXEC_AND_LIB_FILES := \ $(SRC)/GPU/Debugger/Stepping.cpp \ $(SRC)/GPU/GLES/FramebufferManagerGLES.cpp \ $(SRC)/GPU/GLES/DepalettizeShaderGLES.cpp \ + $(SRC)/GPU/GLES/DepthBufferGLES.cpp.arm \ $(SRC)/GPU/GLES/GPU_GLES.cpp.arm \ $(SRC)/GPU/GLES/StencilBufferGLES.cpp.arm \ $(SRC)/GPU/GLES/TextureCacheGLES.cpp.arm \ diff --git a/libretro/Makefile.common b/libretro/Makefile.common index f127fab167..44d56478e3 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -188,6 +188,7 @@ SOURCES_CXX += \ $(GPUDIR)/Software/Lighting.cpp \ $(GPUDIR)/Software/Rasterizer.cpp \ $(GPUDIR)/GLES/DepalettizeShaderGLES.cpp \ + $(GPUDIR)/GLES/DepthBufferGLES.cpp \ $(GPUDIR)/GLES/VertexShaderGeneratorGLES.cpp \ $(GPUDIR)/GLES/DrawEngineGLES.cpp \ $(GPUDIR)/GLES/GPU_GLES.cpp \