From 8f354e5312fff63a82c6599d67844475c2a0a025 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 3 Jun 2018 08:08:18 -0700 Subject: [PATCH] GPU: Minor framebuffer code cleanup. --- GPU/D3D11/FramebufferManagerD3D11.cpp | 72 +++++++++------------------ GPU/D3D11/FramebufferManagerD3D11.h | 9 ---- GPU/GLES/FramebufferManagerGLES.cpp | 33 ++++-------- GPU/GLES/FramebufferManagerGLES.h | 4 -- GPU/Vulkan/FramebufferVulkan.cpp | 50 ++++++------------- GPU/Vulkan/FramebufferVulkan.h | 6 +-- 6 files changed, 51 insertions(+), 123 deletions(-) diff --git a/GPU/D3D11/FramebufferManagerD3D11.cpp b/GPU/D3D11/FramebufferManagerD3D11.cpp index cf17bdbf1..0bfc41254 100644 --- a/GPU/D3D11/FramebufferManagerD3D11.cpp +++ b/GPU/D3D11/FramebufferManagerD3D11.cpp @@ -161,10 +161,7 @@ FramebufferManagerD3D11::~FramebufferManagerD3D11() { postInputLayout_->Release(); } - // FBO cleanup - for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) { - it->second.fbo->Release(); - } + // Temp FBOs cleared by FramebufferCommon. delete[] convBuf; // Stencil cleanup @@ -266,8 +263,6 @@ void FramebufferManagerD3D11::CompilePostShader() { } void FramebufferManagerD3D11::MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height, float &u1, float &v1) { - u8 *convBuf = nullptr; - // TODO: Check / use D3DCAPS2_DYNAMICTEXTURES? if (drawPixelsTex_ && (drawPixelsTexW_ != width || drawPixelsTexH_ != height)) { drawPixelsTex_->Release(); @@ -301,54 +296,35 @@ void FramebufferManagerD3D11::MakePixelTexture(const u8 *srcPixels, GEBufferForm D3D11_MAPPED_SUBRESOURCE map; context_->Map(drawPixelsTex_, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); - convBuf = (u8*)map.pData; - - if (srcPixelFormat != GE_FORMAT_8888 || srcStride != 512) { - for (int y = 0; y < height; y++) { - switch (srcPixelFormat) { - case GE_FORMAT_565: - { - const u16_le *src = (const u16_le *)srcPixels + srcStride * y; - u32 *dst = (u32 *)(convBuf + map.RowPitch * y); - ConvertRGB565ToBGRA8888(dst, src, width); - } - break; - // faster - case GE_FORMAT_5551: - { - const u16_le *src = (const u16_le *)srcPixels + srcStride * y; - u32 *dst = (u32 *)(convBuf + map.RowPitch * y); - ConvertRGBA5551ToBGRA8888(dst, src, width); - } - break; - case GE_FORMAT_4444: - { - const u16_le *src = (const u16_le *)srcPixels + srcStride * y; - u8 *dst = (u8 *)(convBuf + map.RowPitch * y); - ConvertRGBA4444ToBGRA8888((u32 *)dst, src, width); - } + for (int y = 0; y < height; y++) { + const u16_le *src16 = (const u16_le *)srcPixels + srcStride * y; + const u32_le *src32 = (const u32_le *)srcPixels + srcStride * y; + u32 *dst = (u32 *)((u8 *)map.pData + map.RowPitch * y); + switch (srcPixelFormat) { + case GE_FORMAT_565: + ConvertRGB565ToBGRA8888(dst, src16, width); break; - case GE_FORMAT_8888: - { - const u32_le *src = (const u32_le *)srcPixels + srcStride * y; - u32 *dst = (u32 *)(convBuf + map.RowPitch * y); - ConvertRGBA8888ToBGRA8888(dst, src, width); - } + case GE_FORMAT_5551: + ConvertRGBA5551ToBGRA8888(dst, src16, width); + break; + + case GE_FORMAT_4444: + ConvertRGBA4444ToBGRA8888(dst, src16, width); + break; + + case GE_FORMAT_8888: + ConvertRGBA8888ToBGRA8888(dst, src32, width); + break; + + case GE_FORMAT_INVALID: + _dbg_assert_msg_(G3D, false, "Invalid pixelFormat passed to DrawPixels()."); break; - } - } - } else { - for (int y = 0; y < height; y++) { - const u32_le *src = (const u32_le *)srcPixels + srcStride * y; - u32 *dst = (u32 *)(convBuf + map.RowPitch * y); - ConvertRGBA8888ToBGRA8888(dst, src, width); } } context_->Unmap(drawPixelsTex_, 0); context_->PSSetShaderResources(0, 1, &drawPixelsTexView_); - // D3DXSaveTextureToFile("game:\\cc.png", D3DXIFF_PNG, drawPixelsTex_, NULL); } void FramebufferManagerD3D11::DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags) { @@ -718,8 +694,8 @@ void FramebufferManagerD3D11::DestroyAllFBOs() { } bvfbs_.clear(); - for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) { - it->second.fbo->Release(); + for (auto &tempFB : tempFBOs_) { + tempFB.second.fbo->Release(); } tempFBOs_.clear(); diff --git a/GPU/D3D11/FramebufferManagerD3D11.h b/GPU/D3D11/FramebufferManagerD3D11.h index 253bc8dd6..d73b772b6 100644 --- a/GPU/D3D11/FramebufferManagerD3D11.h +++ b/GPU/D3D11/FramebufferManagerD3D11.h @@ -17,10 +17,6 @@ #pragma once -#include -#include -#include - #include // Keeps track of allocated FBOs. @@ -122,9 +118,4 @@ private: ID3D11InputLayout *postInputLayout_ = nullptr; ID3D11Buffer *postConstants_ = nullptr; static const D3D11_INPUT_ELEMENT_DESC g_PostVertexElements[2]; - -#if 0 - AsyncPBO *pixelBufObj_; //this isn't that large - u8 currentPBO_; -#endif }; diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index d27353898..b72b90cf1 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -76,8 +76,6 @@ static const char basic_vs[] = " gl_Position = a_position;\n" "}\n"; -const int MAX_PBO = 2; - void FramebufferManagerGLES::CompileDraw2DProgram() { if (!draw2dprogram_) { std::string errorString; @@ -359,37 +357,24 @@ void FramebufferManagerGLES::MakePixelTexture(const u8 *srcPixels, GEBufferForma u32 neededSize = texWidth * height * 4; u8 *convBuf = new u8[neededSize]; for (int y = 0; y < height; y++) { + const u16_le *src16 = (const u16_le *)srcPixels + srcStride * y; + const u32_le *src32 = (const u32_le *)srcPixels + srcStride * y; + u32 *dst = (u32 *)convBuf + texWidth * y; switch (srcPixelFormat) { case GE_FORMAT_565: - { - const u16 *src = (const u16 *)srcPixels + srcStride * y; - u8 *dst = convBuf + 4 * texWidth * y; - ConvertRGBA565ToRGBA8888((u32 *)dst, src, width); - } + ConvertRGBA565ToRGBA8888((u32 *)dst, src16, width); break; case GE_FORMAT_5551: - { - const u16 *src = (const u16 *)srcPixels + srcStride * y; - u8 *dst = convBuf + 4 * texWidth * y; - ConvertRGBA5551ToRGBA8888((u32 *)dst, src, width); - } + ConvertRGBA5551ToRGBA8888((u32 *)dst, src16, width); break; case GE_FORMAT_4444: - { - const u16 *src = (const u16 *)srcPixels + srcStride * y; - u8 *dst = convBuf + 4 * texWidth * y; - ConvertRGBA4444ToRGBA8888((u32 *)dst, src, width); - } + ConvertRGBA4444ToRGBA8888((u32 *)dst, src16, width); break; case GE_FORMAT_8888: - { - const u8 *src = srcPixels + srcStride * 4 * y; - u8 *dst = convBuf + 4 * texWidth * y; - memcpy(dst, src, 4 * width); - } + memcpy(dst, src32, 4 * width); break; case GE_FORMAT_INVALID: @@ -752,8 +737,8 @@ void FramebufferManagerGLES::DestroyAllFBOs() { } bvfbs_.clear(); - for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) { - it->second.fbo->Release(); + for (auto &tempFB : tempFBOs_) { + tempFB.second.fbo->Release(); } tempFBOs_.clear(); diff --git a/GPU/GLES/FramebufferManagerGLES.h b/GPU/GLES/FramebufferManagerGLES.h index c7ad04921..8c0be0ac1 100644 --- a/GPU/GLES/FramebufferManagerGLES.h +++ b/GPU/GLES/FramebufferManagerGLES.h @@ -17,10 +17,6 @@ #pragma once -#include -#include -#include - #include "ext/native/thin3d/thin3d.h" // Keeps track of allocated FBOs. // Also provides facilities for drawing and later converting raw diff --git a/GPU/Vulkan/FramebufferVulkan.cpp b/GPU/Vulkan/FramebufferVulkan.cpp index 171a1205a..d44b2a998 100644 --- a/GPU/Vulkan/FramebufferVulkan.cpp +++ b/GPU/Vulkan/FramebufferVulkan.cpp @@ -82,14 +82,7 @@ void main() { FramebufferManagerVulkan::FramebufferManagerVulkan(Draw::DrawContext *draw, VulkanContext *vulkan) : FramebufferManagerCommon(draw), - vulkan_(vulkan), - drawPixelsTex_(nullptr), - drawPixelsTexFormat_(GE_FORMAT_INVALID), - convBuf_(nullptr), - convBufSize_(0), - textureCacheVulkan_(nullptr), - shaderManagerVulkan_(nullptr), - pipelinePostShader_(VK_NULL_HANDLE) { + vulkan_(vulkan) { InitDeviceObjects(); @@ -215,7 +208,7 @@ void FramebufferManagerVulkan::MakePixelTexture(const u8 *srcPixels, GEBufferFor // TODO: We can just change the texture format and flip some bits around instead of this. // Could share code with the texture cache perhaps. - // Could also convert directly into the pushbuffer easily. + // TODO: Could also convert directly into the pushbuffer easily. const uint8_t *data = srcPixels; if (srcPixelFormat != GE_FORMAT_8888 || srcStride != width) { u32 neededSize = width * height * 4; @@ -226,38 +219,25 @@ void FramebufferManagerVulkan::MakePixelTexture(const u8 *srcPixels, GEBufferFor } data = convBuf_; for (int y = 0; y < height; y++) { + const u16_le *src16 = (const u16_le *)srcPixels + srcStride * y; + const u32_le *src32 = (const u32_le *)srcPixels + srcStride * y; + u32 *dst = (u32 *)convBuf_ + width * y; switch (srcPixelFormat) { case GE_FORMAT_565: - { - const u16 *src = (const u16 *)srcPixels + srcStride * y; - u8 *dst = convBuf_ + 4 * width * y; - ConvertRGBA565ToRGBA8888((u32 *)dst, src, width); - } - break; + ConvertRGBA565ToRGBA8888((u32 *)dst, src16, width); + break; case GE_FORMAT_5551: - { - const u16 *src = (const u16 *)srcPixels + srcStride * y; - u8 *dst = convBuf_ + 4 * width * y; - ConvertRGBA5551ToRGBA8888((u32 *)dst, src, width); - } - break; + ConvertRGBA5551ToRGBA8888((u32 *)dst, src16, width); + break; case GE_FORMAT_4444: - { - const u16 *src = (const u16 *)srcPixels + srcStride * y; - u8 *dst = convBuf_ + 4 * width * y; - ConvertRGBA4444ToRGBA8888((u32 *)dst, src, width); - } - break; + ConvertRGBA4444ToRGBA8888((u32 *)dst, src16, width); + break; case GE_FORMAT_8888: - { - const u8 *src = srcPixels + srcStride * 4 * y; - u8 *dst = convBuf_ + 4 * width * y; - memcpy(dst, src, 4 * width); - } - break; + memcpy(dst, src32, 4 * width); + break; case GE_FORMAT_INVALID: _dbg_assert_msg_(G3D, false, "Invalid pixelFormat passed to DrawPixels()."); @@ -571,8 +551,8 @@ void FramebufferManagerVulkan::DestroyAllFBOs() { } bvfbs_.clear(); - for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) { - it->second.fbo->Release(); + for (auto &tempFB : tempFBOs_) { + tempFB.second.fbo->Release(); } tempFBOs_.clear(); diff --git a/GPU/Vulkan/FramebufferVulkan.h b/GPU/Vulkan/FramebufferVulkan.h index e55fb0f1e..e7a7fa670 100644 --- a/GPU/Vulkan/FramebufferVulkan.h +++ b/GPU/Vulkan/FramebufferVulkan.h @@ -96,9 +96,9 @@ private: u8 *convBuf_ = nullptr; u32 convBufSize_ = 0; - TextureCacheVulkan *textureCacheVulkan_; - ShaderManagerVulkan *shaderManagerVulkan_; - DrawEngineVulkan *drawEngineVulkan_; + TextureCacheVulkan *textureCacheVulkan_ = nullptr; + ShaderManagerVulkan *shaderManagerVulkan_ = nullptr; + DrawEngineVulkan *drawEngineVulkan_ = nullptr; VulkanPushBuffer *push_; enum {