Unify a little bit of depal code.

This commit is contained in:
Henrik Rydgård 2017-11-05 10:40:21 +01:00
parent 2b7d1c1ded
commit 5d0bd85a70
10 changed files with 45 additions and 46 deletions

View File

@ -288,4 +288,13 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat, ShaderLanguag
}
}
uint32_t DepalShaderCacheCommon::GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat) const {
return (clutMode & 0xFFFFFF) | (pixelFormat << 24);
}
uint32_t DepalShaderCacheCommon::GetClutID(GEPaletteFormat clutFormat, uint32_t clutHash) const {
// Simplistic.
return clutHash ^ (uint32_t)clutFormat;
}
#undef WRITE

View File

@ -17,9 +17,19 @@
#pragma once
#include <cstdint>
#include "GPU/ge_constants.h"
#include "GPU/Common/ShaderCommon.h"
static const int DEPAL_TEXTURE_OLD_AGE = 120;
void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat, ShaderLanguage language);
class DepalShaderCacheCommon {
public:
virtual ~DepalShaderCacheCommon() {}
protected:
uint32_t GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat) const;
uint32_t GetClutID(GEPaletteFormat clutFormat, uint32_t clutHash) const;
};

View File

@ -70,14 +70,10 @@ DepalShaderCacheD3D11::~DepalShaderCacheD3D11() {
inputLayout_->Release();
}
u32 DepalShaderCacheD3D11::GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat) {
return (clutMode & 0xFFFFFF) | (pixelFormat << 24);
}
ID3D11ShaderResourceView *DepalShaderCacheD3D11::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut, bool expandTo32bit) {
const u32 clutId = GetClutID(clutFormat, clutHash);
ID3D11ShaderResourceView *DepalShaderCacheD3D11::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutID, u32 *rawClut, bool expandTo32bit) {
const u32 realClutID = clutID ^ clutFormat;
auto oldtex = texCache_.find(realClutID);
auto oldtex = texCache_.find(clutId);
if (oldtex != texCache_.end()) {
oldtex->second->lastFrame = gpuStats.numFlips;
return oldtex->second->view;
@ -128,7 +124,7 @@ ID3D11ShaderResourceView *DepalShaderCacheD3D11::GetClutTexture(GEPaletteFormat
ASSERT_SUCCESS(device_->CreateTexture2D(&desc, &data, &tex->texture));
ASSERT_SUCCESS(device_->CreateShaderResourceView(tex->texture, nullptr, &tex->view));
tex->lastFrame = gpuStats.numFlips;
texCache_[realClutID] = tex;
texCache_[clutId] = tex;
if (expandTo32bit) {
delete[] expanded;

View File

@ -23,6 +23,7 @@
#include "Common/CommonTypes.h"
#include "GPU/ge_constants.h"
#include "thin3d/thin3d.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
class DepalShaderD3D11 {
public:
@ -44,7 +45,7 @@ public:
};
// Caches both shaders and palette textures.
class DepalShaderCacheD3D11 {
class DepalShaderCacheD3D11 : public DepalShaderCacheCommon {
public:
DepalShaderCacheD3D11(Draw::DrawContext *draw);
~DepalShaderCacheD3D11();
@ -60,8 +61,6 @@ public:
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType);
private:
u32 GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat);
ID3D11Device *device_;
ID3D11DeviceContext *context_;
D3D_FEATURE_LEVEL featureLevel_;

View File

@ -67,14 +67,10 @@ DepalShaderCacheDX9::~DepalShaderCacheDX9() {
}
}
u32 DepalShaderCacheDX9::GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat) {
return (clutMode & 0xFFFFFF) | (pixelFormat << 24);
}
LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(GEPaletteFormat clutFormat, u32 clutHash, u32 *rawClut) {
u32 clutId = GetClutID(clutFormat, clutHash);
LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutID, u32 *rawClut) {
const u32 realClutID = clutID ^ clutFormat;
auto oldtex = texCache_.find(realClutID);
auto oldtex = texCache_.find(clutId);
if (oldtex != texCache_.end()) {
oldtex->second->lastFrame = gpuStats.numFlips;
return oldtex->second->texture;
@ -117,7 +113,7 @@ LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(GEPaletteFormat clutForma
device_->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
tex->lastFrame = gpuStats.numFlips;
texCache_[realClutID] = tex;
texCache_[clutId] = tex;
return tex->texture;
}

View File

@ -21,6 +21,7 @@
#include "Common/CommonTypes.h"
#include "GPU/ge_constants.h"
#include "GPU/Common/ShaderCommon.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
namespace DX9 {
@ -37,7 +38,7 @@ public:
};
// Caches both shaders and palette textures.
class DepalShaderCacheDX9 {
class DepalShaderCacheDX9 : public DepalShaderCacheCommon {
public:
DepalShaderCacheDX9(Draw::DrawContext *draw);
~DepalShaderCacheDX9();
@ -45,15 +46,13 @@ public:
// 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, const u32 clutHash, u32 *rawClut);
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:
u32 GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat);
LPDIRECT3DDEVICE9 device_;
LPDIRECT3DVERTEXSHADER9 vertexShader_;
std::map<u32, DepalShaderDX9 *> cache_;

View File

@ -120,14 +120,10 @@ bool DepalShaderCacheGLES::CreateVertexShader() {
return !vertexShaderFailed_;
}
u32 DepalShaderCacheGLES::GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat) {
return (clutMode & 0xFFFFFF) | (pixelFormat << 24);
}
GLuint DepalShaderCacheGLES::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut) {
u32 clutId = GetClutID(clutFormat, clutHash);
GLuint DepalShaderCacheGLES::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutID, u32 *rawClut) {
const u32 realClutID = clutID ^ clutFormat;
auto oldtex = texCache_.find(realClutID);
auto oldtex = texCache_.find(clutId);
if (oldtex != texCache_.end()) {
oldtex->second->lastFrame = gpuStats.numFlips;
return oldtex->second->texture;
@ -151,7 +147,7 @@ GLuint DepalShaderCacheGLES::GetClutTexture(GEPaletteFormat clutFormat, const u3
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
tex->lastFrame = gpuStats.numFlips;
texCache_[realClutID] = tex;
texCache_[clutId] = tex;
return tex->texture;
}

View File

@ -21,6 +21,7 @@
#include "gfx/gl_common.h"
#include "GPU/ge_constants.h"
#include "GPU/Common/ShaderCommon.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
class DepalShader {
public:
@ -38,7 +39,7 @@ public:
};
// Caches both shaders and palette textures.
class DepalShaderCacheGLES {
class DepalShaderCacheGLES : public DepalShaderCacheCommon {
public:
DepalShaderCacheGLES();
~DepalShaderCacheGLES();
@ -52,7 +53,6 @@ public:
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType);
private:
u32 GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat);
bool CreateVertexShader();
bool useGL3_;

View File

@ -103,11 +103,9 @@ DepalShaderVulkan *DepalShaderCacheVulkan::GetDepalettizeShader(uint32_t clutMod
return depal;
}
VulkanTexture *DepalShaderCacheVulkan::GetClutTexture(GEPaletteFormat clutFormat, u32 clutID, u32 *rawClut) {
VkCommandBuffer cmd = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::INIT_COMMANDBUFFER);
const u32 realClutID = clutID ^ clutFormat;
auto oldtex = texCache_.find(realClutID);
VulkanTexture *DepalShaderCacheVulkan::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;
@ -121,6 +119,7 @@ VulkanTexture *DepalShaderCacheVulkan::GetClutTexture(GEPaletteFormat clutFormat
uint32_t pushOffset = push_->PushAligned(rawClut, 1024, 4, &pushBuffer);
VulkanTexture *vktex = new VulkanTexture(vulkan_, alloc_);
VkCommandBuffer cmd = (VkCommandBuffer)draw_->GetNativeObject(Draw::NativeObject::INIT_COMMANDBUFFER);
if (!vktex->CreateDirect(cmd, texturePixels, 1, 1, destFormat,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, &componentMapping)) {
Crash();
@ -131,7 +130,7 @@ VulkanTexture *DepalShaderCacheVulkan::GetClutTexture(GEPaletteFormat clutFormat
DepalTextureVulkan *tex = new DepalTextureVulkan();
tex->texture = vktex;
tex->lastFrame = gpuStats.numFlips;
texCache_[realClutID] = tex;
texCache_[clutId] = tex;
return tex->texture;
}
@ -161,7 +160,3 @@ void DepalShaderCacheVulkan::Decimate() {
}
}
}
u32 DepalShaderCacheVulkan::GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat) {
return (clutMode & 0xFFFFFF) | (pixelFormat << 24);
}

View File

@ -25,6 +25,7 @@
#include "Common/Vulkan/VulkanMemory.h"
#include "GPU/ge_constants.h"
#include "thin3d/thin3d.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
class DepalShaderVulkan {
public:
@ -47,7 +48,7 @@ class Vulkan2D;
// Caches both shaders and palette textures.
// Could even avoid bothering with palette texture and just use uniform data...
class DepalShaderCacheVulkan {
class DepalShaderCacheVulkan : public DepalShaderCacheCommon {
public:
DepalShaderCacheVulkan(Draw::DrawContext *draw, VulkanContext *vulkan);
~DepalShaderCacheVulkan();
@ -64,8 +65,6 @@ public:
void SetVShader(VkShaderModule vshader) { vshader_ = vshader; }
private:
u32 GenerateShaderID(uint32_t clutMode, GEBufferFormat pixelFormat);
Draw::DrawContext *draw_ = nullptr;
VulkanContext *vulkan_ = nullptr;
VulkanPushBuffer *push_ = nullptr;