Switch over D3D9 as well. Buggy, will debug after unification

This commit is contained in:
Henrik Rydgård committed 2022-08-06 18:27:03 +02:00
1 parent e345a6ba3c
commit 7085861aad
10 files changed
+88 -438

No files matched your search

-2
View File
@@ -1483,8 +1483,6 @@ set(GPU_VULKAN
)
set(GPU_D3D9
GPU/Directx9/DepalettizeShaderDX9.cpp
GPU/Directx9/DepalettizeShaderDX9.h
GPU/Directx9/DrawEngineDX9.cpp
GPU/Directx9/DrawEngineDX9.h
GPU/Directx9/FramebufferManagerDX9.cpp
-200
View File
@@ -1,200 +0,0 @@
// Copyright (c) 2014- 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 <map>
#include <d3d9.h>
#include "Common/GPU/D3D9/D3D9ShaderCompiler.h"
#include "Common/GPU/thin3d.h"
#include "Common/Log.h"
#include "Common/StringUtils.h"
#include "Core/Reporting.h"
#include "GPU/Directx9/TextureCacheDX9.h"
#include "GPU/Directx9/DepalettizeShaderDX9.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
namespace DX9 {
static const int DEPAL_TEXTURE_OLD_AGE = 120;
#ifdef _WIN32
#define SHADERLOG
#endif
static const char *depalVShaderHLSL = R"(
struct VS_IN {
float3 a_position : POSITION;
float2 a_texcoord0 : TEXCOORD0;
};
struct VS_OUT {
float4 Position : POSITION;
float2 Texcoord : TEXCOORD0;
};
VS_OUT main(VS_IN input) {
VS_OUT output;
output.Texcoord = input.a_texcoord0;
output.Position = float4(input.a_position, 1.0);
return output;
}
)";
DepalShaderCacheDX9::DepalShaderCacheDX9(Draw::DrawContext *draw) {
device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);
std::string errorMessage;
if (!CompileVertexShaderD3D9(device_, depalVShaderHLSL, &vertexShader_, &errorMessage)) {
ERROR_LOG(G3D, "error compling depal vshader: %s", errorMessage.c_str());
}
}
DepalShaderCacheDX9::~DepalShaderCacheDX9() {
Clear();
if (vertexShader_) {
vertexShader_->Release();
}
}
LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(GEPaletteFormat clutFormat, u32 clutHash, u32 *rawClut) {
u32 clutId = GetClutID(clutFormat, clutHash);
auto oldtex = texCache_.find(clutId);
if (oldtex != texCache_.end()) {
oldtex->second->lastFrame = gpuStats.numFlips;
return oldtex->second->texture;
}
D3DFORMAT dstFmt = DX9::getClutDestFormat(clutFormat);
int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512;
DepalTextureDX9 *tex = new DepalTextureDX9();
// Create texture
D3DPOOL pool = D3DPOOL_MANAGED;
int usage = 0;
if (device_) {
pool = D3DPOOL_DEFAULT;
usage = D3DUSAGE_DYNAMIC; // TODO: Switch to using a staging texture?
}
HRESULT hr = device_->CreateTexture(texturePixels, 1, 1, usage, dstFmt, pool, &tex->texture, NULL);
if (FAILED(hr)) {
ERROR_LOG(G3D, "Failed to create D3D texture for depal");
delete tex;
return nullptr;
}
D3DLOCKED_RECT rect;
hr = tex->texture->LockRect(0, &rect, NULL, 0);
if (FAILED(hr)) {
ERROR_LOG(G3D, "Failed to lock D3D texture for depal");
delete tex;
return nullptr;
}
// Regardless of format, the CLUT should always be 1024 bytes.
memcpy(rect.pBits, rawClut, 1024);
tex->texture->UnlockRect(0);
device_->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
device_->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
device_->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);
device_->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
tex->lastFrame = gpuStats.numFlips;
texCache_[clutId] = tex;
return tex->texture;
}
void DepalShaderCacheDX9::Clear() {
for (auto shader = cache_.begin(); shader != cache_.end(); ++shader) {
shader->second->pixelShader->Release();
delete shader->second;
}
cache_.clear();
for (auto tex = texCache_.begin(); tex != texCache_.end(); ++tex) {
tex->second->texture->Release();
delete tex->second;
}
texCache_.clear();
}
void DepalShaderCacheDX9::Decimate() {
for (auto tex = texCache_.begin(); tex != texCache_.end();) {
if (tex->second->lastFrame + DEPAL_TEXTURE_OLD_AGE < gpuStats.numFlips) {
tex->second->texture->Release();
delete tex->second;
texCache_.erase(tex++);
} else {
++tex;
}
}
}
LPDIRECT3DPIXELSHADER9 DepalShaderCacheDX9::GetDepalettizePixelShader(uint32_t clutMode, GEBufferFormat pixelFormat) {
u32 id = GenerateShaderID(clutMode, pixelFormat);
auto shader = cache_.find(id);
if (shader != cache_.end()) {
return shader->second->pixelShader;
}
char *buffer = new char[2048];
GenerateDepalShader(buffer, pixelFormat, HLSL_D3D9);
LPDIRECT3DPIXELSHADER9 pshader;
std::string errorMessage;
if (!CompilePixelShaderD3D9(device_, buffer, &pshader, &errorMessage)) {
ERROR_LOG(G3D, "Failed to compile depal pixel shader: %s\n\n%s", buffer, errorMessage.c_str());
delete[] buffer;
return nullptr;
}
DepalShaderDX9 *depal = new DepalShaderDX9();
depal->pixelShader = pshader;
depal->code = buffer;
cache_[id] = depal;
delete[] buffer;
return depal->pixelShader;
}
std::vector<std::string> DepalShaderCacheDX9::DebugGetShaderIDs(DebugShaderType type) {
std::vector<std::string> ids;
for (auto &iter : cache_) {
ids.push_back(StringFromFormat("%08x", iter.first));
}
return ids;
}
std::string DepalShaderCacheDX9::DebugGetShaderString(std::string idstr, DebugShaderType type, DebugShaderStringType stringType) {
uint32_t id;
sscanf(idstr.c_str(), "%08x", &id);
auto iter = cache_.find(id);
if (iter == cache_.end())
return "";
switch (stringType) {
case SHADER_STRING_SHORT_DESC:
return idstr;
case SHADER_STRING_SOURCE_CODE:
return iter->second->code;
default:
return "";
}
}
} // namespace
-62
View File
@@ -1,62 +0,0 @@
// Copyright (c) 2014- 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 <map>
#include <d3d9.h>
#include "Common/CommonTypes.h"
#include "GPU/ge_constants.h"
#include "GPU/Common/ShaderCommon.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
namespace DX9 {
class DepalShaderDX9 {
public:
LPDIRECT3DPIXELSHADER9 pixelShader;
std::string code;
};
class DepalTextureDX9 {
public:
LPDIRECT3DTEXTURE9 texture;
int lastFrame;
};
// Caches both shaders and palette textures.
class DepalShaderCacheDX9 : public DepalShaderCacheCommon {
public:
DepalShaderCacheDX9(Draw::DrawContext *draw);
~DepalShaderCacheDX9();
// This also uploads the palette and binds the correct texture.
LPDIRECT3DPIXELSHADER9 GetDepalettizePixelShader(uint32_t clutMode, GEBufferFormat pixelFormat);
LPDIRECT3DVERTEXSHADER9 GetDepalettizeVertexShader() { return vertexShader_; }
LPDIRECT3DTEXTURE9 GetClutTexture(GEPaletteFormat clutFormat, u32 clutHash, u32 *rawClut);
void Clear();
void Decimate();
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type);
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType);
private:
LPDIRECT3DDEVICE9 device_;
LPDIRECT3DVERTEXSHADER9 vertexShader_ = nullptr;
std::map<u32, DepalShaderDX9 *> cache_;
std::map<u32, DepalTextureDX9 *> texCache_;
};
} // namespace
+2 -2
View File
@@ -23,7 +23,7 @@
#include "GPU/GPUCommon.h"
#include "GPU/Directx9/FramebufferManagerDX9.h"
#include "GPU/Directx9/DrawEngineDX9.h"
#include "GPU/Directx9/DepalettizeShaderDX9.h"
#include "GPU/Common/DepalettizeCommon.h"
#include "GPU/Common/VertexDecoderCommon.h"
namespace DX9 {
@@ -77,7 +77,7 @@ private:
FramebufferManagerDX9 *framebufferManagerDX9_;
TextureCacheDX9 *textureCacheDX9_;
DepalShaderCacheDX9 depalShaderCache_;
DepalShaderCache depalShaderCache_;
DrawEngineDX9 drawEngine_;
ShaderManagerDX9 *shaderManagerDX9_;
};
+76 -156
View File
@@ -27,8 +27,8 @@
#include "GPU/Directx9/TextureCacheDX9.h"
#include "GPU/Directx9/FramebufferManagerDX9.h"
#include "GPU/Directx9/ShaderManagerDX9.h"
#include "GPU/Directx9/DepalettizeShaderDX9.h"
#include "Common/GPU/D3D9/D3D9StateCache.h"
#include "GPU/Common/DepalettizeCommon.h"
#include "GPU/Common/FramebufferManagerCommon.h"
#include "GPU/Common/TextureDecoder.h"
#include "Core/Config.h"
@@ -220,187 +220,107 @@ void TextureCacheDX9::Unbind() {
InvalidateLastTexture();
}
class TextureShaderApplierDX9 {
public:
struct Pos {
Pos(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {
}
Pos() {
}
float x;
float y;
float z;
};
struct UV {
UV(float u_, float v_) : u(u_), v(v_) {
}
UV() {
}
float u;
float v;
};
struct PosUV {
Pos pos;
UV uv;
};
TextureShaderApplierDX9(LPDIRECT3DDEVICE9 device, LPDIRECT3DPIXELSHADER9 pshader, LPDIRECT3DVERTEXDECLARATION9 decl, float bufferW, float bufferH, int renderW, int renderH, float xoff, float yoff)
: device_(device), pshader_(pshader), decl_(decl), bufferW_(bufferW), bufferH_(bufferH), renderW_(renderW), renderH_(renderH) {
static const Pos pos[4] = {
{-1, 1, 0},
{ 1, 1, 0},
{-1, -1, 0},
{ 1, -1, 0},
};
static const UV uv[4] = {
{0, 0},
{1, 0},
{0, 1},
{1, 1},
};
for (int i = 0; i < 4; ++i) {
verts_[i].pos = pos[i];
verts_[i].pos.x += xoff;
verts_[i].pos.y += yoff;
verts_[i].uv = uv[i];
}
}
void ApplyBounds(const KnownVertexBounds &bounds, u32 uoff, u32 voff, float xoff, float yoff) {
// If min is not < max, then we don't have values (wasn't set during decode.)
if (bounds.minV < bounds.maxV) {
const float invWidth = 1.0f / bufferW_;
const float invHeight = 1.0f / bufferH_;
// Inverse of half = double.
const float invHalfWidth = invWidth * 2.0f;
const float invHalfHeight = invHeight * 2.0f;
const int u1 = bounds.minU + uoff;
const int v1 = bounds.minV + voff;
const int u2 = bounds.maxU + uoff;
const int v2 = bounds.maxV + voff;
const float left = u1 * invHalfWidth - 1.0f + xoff;
const float right = u2 * invHalfWidth - 1.0f + xoff;
const float top = (bufferH_ - v1) * invHalfHeight - 1.0f + yoff;
const float bottom = (bufferH_ - v2) * invHalfHeight - 1.0f + yoff;
float z = 0.0f;
verts_[0].pos = Pos(left, top, z);
verts_[1].pos = Pos(right, top, z);
verts_[2].pos = Pos(left, bottom, z);
verts_[3].pos = Pos(right, bottom, z);
// And also the UVs, same order.
const float uvleft = u1 * invWidth;
const float uvright = u2 * invWidth;
const float uvtop = v1 * invHeight;
const float uvbottom = v2 * invHeight;
verts_[0].uv = UV(uvleft, uvtop);
verts_[1].uv = UV(uvright, uvtop);
verts_[2].uv = UV(uvleft, uvbottom);
verts_[3].uv = UV(uvright, uvbottom);
// We need to reapply the texture next time since we cropped UV.
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
}
}
void Use(LPDIRECT3DVERTEXSHADER9 vshader) {
device_->SetPixelShader(pshader_);
device_->SetVertexShader(vshader);
device_->SetVertexDeclaration(decl_);
}
void Shade() {
// Intentionally bypassing the dxstate cache here (and using .Restore to recover afterwards). Not sure if this is a good idea.
device_->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
device_->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE);
device_->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
device_->SetRenderState(D3DRS_ZENABLE, FALSE);
device_->SetRenderState(D3DRS_STENCILENABLE, FALSE);
device_->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
device_->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
D3DVIEWPORT9 vp{ 0, 0, (DWORD)renderW_, (DWORD)renderH_, 0.0f, 1.0f };
device_->SetViewport(&vp);
HRESULT hr = device_->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, verts_, (3 + 2) * sizeof(float));
if (FAILED(hr)) {
ERROR_LOG_REPORT(G3D, "Depal render failed: %08x", (uint32_t)hr);
}
dxstate.Restore();
}
protected:
LPDIRECT3DDEVICE9 device_;
LPDIRECT3DPIXELSHADER9 pshader_;
LPDIRECT3DVERTEXDECLARATION9 decl_;
PosUV verts_[4];
float bufferW_;
float bufferH_;
int renderW_;
int renderH_;
};
void TextureCacheDX9::BindAsClutTexture(Draw::Texture *tex) {
LPDIRECT3DBASETEXTURE9 clutTexture = (LPDIRECT3DBASETEXTURE9)draw_->GetNativeObject(Draw::NativeObject::TEXTURE_VIEW, tex);
device_->SetTexture(1, clutTexture);
device_->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);
device_->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
device_->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
}
void TextureCacheDX9::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) {
LPDIRECT3DPIXELSHADER9 pshader = nullptr;
DepalShader *depalShader = nullptr;
uint32_t clutMode = gstate.clutformat & 0xFFFFFF;
bool need_depalettize = IsClutFormat(texFormat);
if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) {
pshader = depalShaderCache_->GetDepalettizePixelShader(clutMode, framebuffer->drawnFormat);
bool depth = channel == NOTIFY_FB_DEPTH;
bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300) || gstate_c.Supports(GPU_SUPPORTS_GLSL_330)) && !depth;
if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) {
useShaderDepal = false;
depth = false; // Can't support this
}
if (pshader) {
if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) {
if (useShaderDepal) {
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
// Very icky conflation here of native and thin3d rendering. This will need careful work per backend in BindAsClutTexture.
Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_);
BindAsClutTexture(clutTexture);
framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight);
samplerKey.magFilt = false;
samplerKey.minFilt = false;
samplerKey.mipEnable = false;
ApplySamplingParams(samplerKey);
// Since we started/ended render passes, might need these.
gstate_c.Dirty(DIRTY_DEPAL);
gstate_c.SetUseShaderDepal(true);
gstate_c.depalFramebufferFormat = framebuffer->drawnFormat;
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;
CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBuf_, clutFormat, clutTotalColors);
gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL);
draw_->InvalidateCachedState();
InvalidateLastTexture();
return;
}
depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat);
gstate_c.SetUseShaderDepal(false);
}
if (depalShader) {
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
LPDIRECT3DTEXTURE9 clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_);
Draw::Framebuffer *depalFBO = framebufferManagerDX9_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight);
Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_);
Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight);
draw_->BindTexture(0, nullptr);
draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Depal");
shaderManager_->DirtyLastShader();
float xoff = -0.5f / framebuffer->renderWidth;
float yoff = 0.5f / framebuffer->renderHeight;
draw_->SetScissorRect(0, 0, (int)framebuffer->renderWidth, (int)framebuffer->renderHeight);
Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f };
draw_->SetViewports(1, &vp);
TextureShaderApplierDX9 shaderApply(device_, pshader, pFramebufferVertexDecl, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight, xoff, yoff);
shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset, xoff, yoff);
shaderApply.Use(depalShaderCache_->GetDepalettizeVertexShader());
TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight);
shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset);
shaderApply.Use();
device_->SetTexture(1, clutTexture);
device_->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);
device_->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
device_->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
framebufferManagerDX9_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY | BINDFBCOLOR_FORCE_SELF);
device_->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
device_->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
device_->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
device_->SetSamplerState(0, D3DSAMP_MIPMAPLODBIAS, 0);
device_->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0);
draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0);
Draw::SamplerState *nearest = depalShaderCache_->GetSampler();
draw_->BindSamplerStates(0, 1, &nearest);
draw_->BindSamplerStates(1, 1, &nearest);
draw_->BindTexture(1, clutTexture);
shaderApply.Shade();
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");
draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0);
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;
CheckAlphaResult alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(clutFormat), clutTotalColors);
CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBufRaw_, clutFormat, clutTotalColors);
gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL);
} else {
framebufferManagerDX9_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
draw_->InvalidateCachedState();
shaderManager_->DirtyLastShader();
} else {
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");
framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
gstate_c.SetUseShaderDepal(false);
gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650);
}
framebufferManagerDX9_->RebindFramebuffer("RebindFramebuffer - ApplyTextureFromFramebuffer");
SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight);
ApplySamplingParams(samplerKey);
// Since we started/ended render passes, might need these.
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
}
void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) {
+4 -3
View File
@@ -24,11 +24,11 @@
#include "GPU/Common/TextureCacheCommon.h"
struct VirtualFramebuffer;
class DepalShaderCache;
namespace DX9 {
class FramebufferManagerDX9;
class DepalShaderCacheDX9;
class ShaderManagerDX9;
class TextureCacheDX9 : public TextureCacheCommon {
@@ -39,7 +39,7 @@ public:
void StartFrame();
void SetFramebufferManager(FramebufferManagerDX9 *fbManager);
void SetDepalShaderCache(DepalShaderCacheDX9 *dpCache) {
void SetDepalShaderCache(DepalShaderCache *dpCache) {
depalShaderCache_ = dpCache;
}
void SetShaderManager(ShaderManagerDX9 *sm) {
@@ -57,6 +57,7 @@ protected:
void BindTexture(TexCacheEntry *entry) override;
void Unbind() override;
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
void BindAsClutTexture(Draw::Texture *tex) override;
private:
void ApplySamplingParams(const SamplerCacheKey &key);
@@ -81,7 +82,7 @@ private:
float maxAnisotropyLevel;
FramebufferManagerDX9 *framebufferManagerDX9_;
DepalShaderCacheDX9 *depalShaderCache_;
DepalShaderCache *depalShaderCache_;
ShaderManagerDX9 *shaderManager_;
};
+6 -4
View File
@@ -257,7 +257,7 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_);
BindAsClutTexture(clutTexture);
framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight);
samplerKey.magFilt = false;
samplerKey.minFilt = false;
@@ -286,6 +286,7 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_);
Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight);
draw_->BindTexture(0, nullptr);
draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Depal");
draw_->SetScissorRect(0, 0, (int)framebuffer->renderWidth, (int)framebuffer->renderHeight);
@@ -304,6 +305,8 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
shaderApply.Shade();
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");
draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0);
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
@@ -315,14 +318,13 @@ void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
draw_->InvalidateCachedState();
shaderManager_->DirtyLastShader();
} else {
framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");
framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
gstate_c.SetUseShaderDepal(false);
gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650);
}
framebufferManagerGL_->RebindFramebuffer("ApplyTextureFramebuffer");
SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight);
ApplySamplingParams(samplerKey);
-2
View File
@@ -374,7 +374,6 @@
<ClInclude Include="Debugger\Record.h" />
<ClInclude Include="Debugger\RecordFormat.h" />
<ClInclude Include="Debugger\Stepping.h" />
<ClInclude Include="Directx9\DepalettizeShaderDX9.h" />
<ClInclude Include="Directx9\FramebufferManagerDX9.h" />
<ClInclude Include="Directx9\GPU_DX9.h" />
<ClInclude Include="Directx9\ShaderManagerDX9.h" />
@@ -515,7 +514,6 @@
<ClCompile Include="Debugger\Playback.cpp" />
<ClCompile Include="Debugger\Record.cpp" />
<ClCompile Include="Debugger\Stepping.cpp" />
<ClCompile Include="Directx9\DepalettizeShaderDX9.cpp" />
<ClCompile Include="Directx9\FramebufferManagerDX9.cpp" />
<ClCompile Include="Directx9\GPU_DX9.cpp" />
<ClCompile Include="Directx9\ShaderManagerDX9.cpp" />
-6
View File
@@ -117,9 +117,6 @@
<ClInclude Include="Common\DepalettizeShaderCommon.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Directx9\DepalettizeShaderDX9.h">
<Filter>DirectX9</Filter>
</ClInclude>
<ClInclude Include="Common\TextureScalerCommon.h">
<Filter>Common</Filter>
</ClInclude>
@@ -359,9 +356,6 @@
<ClCompile Include="Common\DepalettizeShaderCommon.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Directx9\DepalettizeShaderDX9.cpp">
<Filter>DirectX9</Filter>
</ClCompile>
<ClCompile Include="Common\VertexDecoderArm64.cpp">
<Filter>Common</Filter>
</ClCompile>
-1
View File
@@ -742,7 +742,6 @@ SOURCES_CXX += \
ifeq ($(PLATFORM_EXT), win32)
SOURCES_CXX += \
$(GPUDIR)/Directx9/DepalettizeShaderDX9.cpp \
$(GPUDIR)/Directx9/DrawEngineDX9.cpp \
$(GPUDIR)/Directx9/FramebufferManagerDX9.cpp \
$(GPUDIR)/Directx9/GPU_DX9.cpp \