Skip to content

Commit

Permalink
Merge pull request #15886 from hrydgard/refactor-depal
Browse files Browse the repository at this point in the history
Rename DepalShaderCache to TextureShaderCache
  • Loading branch information
hrydgard authored Aug 22, 2022
2 parents 3c307c9 + b39b74e commit 0e780be
Show file tree
Hide file tree
Showing 33 changed files with 253 additions and 308 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1536,8 +1536,8 @@ set(GPU_SOURCES
${GPU_NEON}
GPU/Common/Draw2D.cpp
GPU/Common/Draw2D.h
GPU/Common/DepalettizeCommon.cpp
GPU/Common/DepalettizeCommon.h
GPU/Common/TextureShaderCommon.cpp
GPU/Common/TextureShaderCommon.h
GPU/Common/DepalettizeShaderCommon.cpp
GPU/Common/DepalettizeShaderCommon.h
GPU/Common/FragmentShaderGenerator.cpp
Expand Down
182 changes: 0 additions & 182 deletions GPU/Common/DepalettizeCommon.h

This file was deleted.

4 changes: 2 additions & 2 deletions GPU/Common/DepalettizeShaderCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static const InputDef vsInputs[2] = {
{ "vec2", "a_texcoord0", Draw::SEM_TEXCOORD0, },
};

// TODO: Deduplicate with DepalettizeCommon.cpp
// TODO: Deduplicate with TextureShaderCommon.cpp
static const SamplerDef samplers[2] = {
{ "tex" },
{ "pal" },
Expand Down Expand Up @@ -309,7 +309,7 @@ void GenerateDepalFs(char *buffer, const DepalConfig &config, const ShaderLangua
writer.EndFSMain("outColor", FSFLAG_NONE);
}

void GenerateDepalVs(char *buffer, const ShaderLanguageDesc &lang) {
void GenerateVs(char *buffer, const ShaderLanguageDesc &lang) {
ShaderWriter writer(buffer, lang, ShaderStage::Vertex, nullptr, 0);
writer.BeginVSMain(vsInputs, Slice<UniformDef>::empty(), varyings);
writer.C(" v_texcoord = a_texcoord0;\n");
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/DepalettizeShaderCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ struct DepalConfig {
};

void GenerateDepalFs(char *buffer, const DepalConfig &config, const ShaderLanguageDesc &lang);
void GenerateDepalVs(char *buffer, const ShaderLanguageDesc &lang);
void GenerateVs(char *buffer, const ShaderLanguageDesc &lang);
2 changes: 1 addition & 1 deletion GPU/Common/ShaderCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum DebugShaderType {
SHADER_TYPE_GEOMETRY = 2,
SHADER_TYPE_VERTEXLOADER = 3, // Not really a shader, but might as well re-use this mechanism
SHADER_TYPE_PIPELINE = 4, // Vulkan and DX12 combines a bunch of state into pipeline objects. Might as well make them inspectable.
SHADER_TYPE_DEPAL = 5,
SHADER_TYPE_TEXTURE = 5,
SHADER_TYPE_SAMPLER = 6, // Not really a shader either. Need to rename this enum...
};

Expand Down
29 changes: 14 additions & 15 deletions GPU/Common/TextureCacheCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw)

replacer_.Init();

depalShaderCache_ = new DepalShaderCache(draw);
textureShaderCache_ = new TextureShaderCache(draw);
}

TextureCacheCommon::~TextureCacheCommon() {
delete depalShaderCache_;
delete textureShaderCache_;

FreeAlignedMemory(clutBufConverted_);
FreeAlignedMemory(clutBufRaw_);
Expand Down Expand Up @@ -1860,7 +1860,7 @@ bool CanDepalettize(GETextureFormat texFormat, GEBufferFormat bufferFormat) {
}

void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, RasterChannel channel) {
DepalShader *depalShader = nullptr;
TextureShader *textureShader = nullptr;
uint32_t clutMode = gstate.clutformat & 0xFFFFFF;

bool depth = channel == RASTER_DEPTH;
Expand All @@ -1886,7 +1886,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
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_);
Draw::Texture *clutTexture = textureShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_);
BindAsClutTexture(clutTexture);

framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
Expand All @@ -1913,13 +1913,13 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
return;
}

depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, texFormat, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat);
textureShader = textureShaderCache_->GetDepalettizeShader(clutMode, texFormat, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat);
gstate_c.SetUseShaderDepal(false);
}

if (depalShader) {
if (textureShader) {
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_);
Draw::Texture *clutTexture = textureShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_);
Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight);
draw_->BindTexture(0, nullptr);
draw_->BindTexture(1, nullptr);
Expand All @@ -1929,17 +1929,16 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f };
draw_->SetViewports(1, &vp);

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();

draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0);
draw_->BindTexture(1, clutTexture);
Draw::SamplerState *nearest = depalShaderCache_->GetSampler();
Draw::SamplerState *nearest = textureShaderCache_->GetSampler();
draw_->BindSamplerStates(0, 1, &nearest);
draw_->BindSamplerStates(1, 1, &nearest);

shaderApply.Shade();
textureShaderCache_->ApplyShader(textureShader,
framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight,
gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset);

draw_->BindTexture(0, nullptr);
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");

Expand Down Expand Up @@ -1971,7 +1970,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
}

void TextureCacheCommon::Clear(bool delete_them) {
depalShaderCache_->Clear();
textureShaderCache_->Clear();

ForgetLastTexture();
for (TexCache::iterator iter = cache_.begin(); iter != cache_.end(); ++iter) {
Expand Down Expand Up @@ -2413,5 +2412,5 @@ CheckAlphaResult TextureCacheCommon::CheckCLUTAlpha(const uint8_t *pixelData, GE
}

void TextureCacheCommon::StartFrame() {
depalShaderCache_->Decimate();
textureShaderCache_->Decimate();
}
6 changes: 3 additions & 3 deletions GPU/Common/TextureCacheCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Common/TextureDecoder.h"
#include "GPU/Common/TextureScalerCommon.h"
#include "GPU/Common/DepalettizeCommon.h"
#include "GPU/Common/TextureShaderCommon.h"

enum FramebufferNotification {
NOTIFY_FB_CREATED,
Expand Down Expand Up @@ -291,7 +291,7 @@ class TextureCacheCommon {
void InvalidateAll(GPUInvalidationType type);
void ClearNextFrame();

DepalShaderCache *GetDepalShaderCache() { return depalShaderCache_; }
TextureShaderCache *GetTextureShaderCache() { return textureShaderCache_; }

virtual void ForgetLastTexture() = 0;
virtual void InvalidateLastTexture() = 0;
Expand Down Expand Up @@ -403,7 +403,7 @@ class TextureCacheCommon {
TextureReplacer replacer_;
TextureScalerCommon scaler_;
FramebufferManagerCommon *framebufferManager_;
DepalShaderCache *depalShaderCache_;
TextureShaderCache *textureShaderCache_;
ShaderManagerCommon *shaderManager_;

bool clearCacheNextFrame_ = false;
Expand Down
Loading

0 comments on commit 0e780be

Please sign in to comment.