Skip to content
Permalink
Browse files

Merge pull request #11128 from unknownbrackets/gpu-minor

Minor framebuffer code cleanup
  • Loading branch information...
hrydgard committed Jun 6, 2018
2 parents 03175b7 + 4f93b1d commit 6bf6490c2fd5c0f58dbc25f308b13694a4ee4c13
@@ -1100,7 +1100,7 @@ void FramebufferManagerCommon::DecimateFBOs() {
int age = frameLastFramebufUsed_ - it->second.last_frame_used;
if (age > FBO_OLD_AGE) {
it->second.fbo->Release();
tempFBOs_.erase(it++);
it = tempFBOs_.erase(it);
} else {
++it;
}
@@ -19,7 +19,7 @@

#include <set>
#include <vector>
#include <map>
#include <unordered_map>

#include "Common/CommonTypes.h"
#include "Core/MemMap.h"
@@ -412,7 +412,7 @@ class FramebufferManagerCommon {
int last_frame_used;
};

std::map<u64, TempFBOInfo> tempFBOs_;
std::unordered_map<u64, TempFBOInfo> tempFBOs_;

std::vector<Draw::Framebuffer *> fbosToDelete_;

@@ -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);
}
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_5551:
ConvertRGBA5551ToBGRA8888(dst, src16, 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);
}

case GE_FORMAT_4444:
ConvertRGBA4444ToBGRA8888(dst, src16, 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);
}

case GE_FORMAT_8888:
ConvertRGBA8888ToBGRA8888(dst, src32, 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_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();

@@ -17,10 +17,6 @@

#pragma once

#include <list>
#include <set>
#include <map>

#include <d3d11.h>

// Keeps track of allocated FBOs.
@@ -122,9 +118,4 @@ class FramebufferManagerD3D11 : public FramebufferManagerCommon {
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
};
@@ -82,12 +82,7 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
};

FramebufferManagerDX9::FramebufferManagerDX9(Draw::DrawContext *draw)
: FramebufferManagerCommon(draw),
drawPixelsTex_(0),
convBuf(0),
stencilUploadPS_(nullptr),
stencilUploadVS_(nullptr),
stencilUploadFailed_(false) {
: FramebufferManagerCommon(draw) {

device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);
deviceEx_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE_EX);
@@ -119,8 +114,8 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
if (drawPixelsTex_) {
drawPixelsTex_->Release();
}
for (auto it = offscreenSurfaces_.begin(), end = offscreenSurfaces_.end(); it != end; ++it) {
it->second.surface->Release();
for (auto &it : offscreenSurfaces_) {
it.second.surface->Release();
}
delete [] convBuf;
if (stencilUploadPS_) {
@@ -534,16 +529,7 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
const u32 *src32 = (const u32 *)src;

if (format == GE_FORMAT_8888) {
u32 *dst32 = (u32 *)dst;
if (src == dst) {
return;
} else {
for (u32 y = 0; y < height; ++y) {
ConvertBGRA8888ToRGBA8888(dst32, src32, width);
src32 += srcStride;
dst32 += dstStride;
}
}
ConvertFromBGRA8888(dst, src, dstStride, srcStride, width, height, Draw::DataFormat::R8G8B8A8_UNORM);
} else {
// But here it shouldn't matter if they do intersect
u16 *dst16 = (u16 *)dst;
@@ -680,7 +666,7 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
int age = frameLastFramebufUsed_ - it->second.last_frame_used;
if (age > FBO_OLD_AGE) {
it->second.surface->Release();
offscreenSurfaces_.erase(it++);
it = offscreenSurfaces_.erase(it);
} else {
++it;
}
@@ -706,8 +692,8 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
}
bvfbs_.clear();

for (auto it = offscreenSurfaces_.begin(), end = offscreenSurfaces_.end(); it != end; ++it) {
it->second.surface->Release();
for (auto &it : offscreenSurfaces_) {
it.second.surface->Release();
}
offscreenSurfaces_.clear();

@@ -17,9 +17,7 @@

#pragma once

#include <list>
#include <set>
#include <map>
#include <unordered_map>

#include <d3d9.h>

@@ -91,20 +89,20 @@ class FramebufferManagerDX9 : public FramebufferManagerCommon {
LPDIRECT3DDEVICE9 deviceEx_;

// Used by DrawPixels
LPDIRECT3DTEXTURE9 drawPixelsTex_;
LPDIRECT3DTEXTURE9 drawPixelsTex_ = nullptr;
int drawPixelsTexW_;
int drawPixelsTexH_;

LPDIRECT3DVERTEXSHADER9 pFramebufferVertexShader;
LPDIRECT3DPIXELSHADER9 pFramebufferPixelShader;
LPDIRECT3DVERTEXDECLARATION9 pFramebufferVertexDecl;
LPDIRECT3DVERTEXSHADER9 pFramebufferVertexShader = nullptr;
LPDIRECT3DPIXELSHADER9 pFramebufferPixelShader = nullptr;
LPDIRECT3DVERTEXDECLARATION9 pFramebufferVertexDecl = nullptr;

u8 *convBuf;
u8 *convBuf = nullptr;

int plainColorLoc_;
LPDIRECT3DPIXELSHADER9 stencilUploadPS_;
LPDIRECT3DVERTEXSHADER9 stencilUploadVS_;
bool stencilUploadFailed_;
LPDIRECT3DPIXELSHADER9 stencilUploadPS_ = nullptr;
LPDIRECT3DVERTEXSHADER9 stencilUploadVS_ = nullptr;
bool stencilUploadFailed_ = false;

TextureCacheDX9 *textureCacheDX9_;
ShaderManagerDX9 *shaderManagerDX9_;
@@ -115,12 +113,7 @@ class FramebufferManagerDX9 : public FramebufferManagerCommon {
int last_frame_used;
};

std::map<u64, OffscreenSurface> offscreenSurfaces_;

#if 0
AsyncPBO *pixelBufObj_; //this isn't that large
u8 currentPBO_;
#endif
std::unordered_map<u64, OffscreenSurface> offscreenSurfaces_;
};

};
Oops, something went wrong.

0 comments on commit 6bf6490

Please sign in to comment.
You can’t perform that action at this time.