More cleanup, fixes.

This commit is contained in:
Henrik Rydgård 2022-08-05 15:09:33 +02:00
parent 9a5893ce6e
commit ded8ba8806
10 changed files with 23 additions and 29 deletions

View file

@ -486,7 +486,7 @@ public:
case NativeObject::NULL_IMAGEVIEW:
return (uint64_t)GetNullTexture()->GetImageView();
case NativeObject::TEXTURE_VIEW:
return (uint64_t)(((VulkanTexture *)srcObject)->GetImageView());
return (uint64_t)(((VKTexture *)srcObject)->GetImageView());
default:
Crash();
return 0;

View file

@ -134,9 +134,10 @@ TextureCacheCommon::TextureCacheCommon(Draw::DrawContext *draw)
}
TextureCacheCommon::~TextureCacheCommon() {
delete depalShaderCache_;
FreeAlignedMemory(clutBufConverted_);
FreeAlignedMemory(clutBufRaw_);
delete depalShaderCache_;
}
// Produces a signed 1.23.8 value.
@ -1846,10 +1847,11 @@ void TextureCacheCommon::ApplyTexture() {
void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) {
DepalShader *depalShader = nullptr;
uint32_t clutMode = gstate.clutformat & 0xFFFFFF;
bool need_depalettize = IsClutFormat(texFormat);
bool need_depalettize = IsClutFormat(texFormat);
bool expand32 = !gstate_c.Supports(GPU_SUPPORTS_16BIT_FORMATS);
bool depth = channel == NOTIFY_FB_DEPTH;
bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && !depth;
bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && !depth && !gstate_c.curTextureIs3D;
// TODO: Implement shader depal in the fragment shader generator for D3D11 at least.
if (!draw_->GetDeviceCaps().fragmentShaderInt32Supported) {
@ -1875,6 +1877,9 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
BindAsClutTexture(clutTexture);
framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
// Vulkan needs to do some extra work here to pick out the native handle from Draw.
BoundFramebufferTexture();
SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight);
samplerKey.magFilt = false;
samplerKey.minFilt = false;
@ -1892,6 +1897,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
draw_->InvalidateCachedState();
InvalidateLastTexture();
return;
}
@ -1926,6 +1932,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");
draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0);
BoundFramebufferTexture();
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;
@ -1938,6 +1945,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
} else {
framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer");
framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
BoundFramebufferTexture();
gstate_c.SetUseShaderDepal(false);
gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650);

View file

@ -373,6 +373,8 @@ protected:
void SetTextureFramebuffer(const AttachCandidate &candidate);
virtual void BoundFramebufferTexture() {}
virtual void StartFrame();
void DecimateVideos();

View file

@ -53,8 +53,7 @@ namespace DX9 {
GPU_DX9::GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
: GPUCommon(gfxCtx, draw),
depalShaderCache_(draw),
drawEngine_(draw) {
drawEngine_(draw) {
device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);
deviceEx_ = (LPDIRECT3DDEVICE9EX)draw->GetNativeObject(Draw::NativeObject::DEVICE_EX);
@ -75,7 +74,6 @@ GPU_DX9::GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
framebufferManagerDX9_->SetDrawEngine(&drawEngine_);
framebufferManagerDX9_->Init();
textureCacheDX9_->SetFramebufferManager(framebufferManagerDX9_);
textureCacheDX9_->SetDepalShaderCache(&depalShaderCache_);
textureCacheDX9_->SetShaderManager(shaderManagerDX9_);
// Sanity check gstate
@ -282,7 +280,6 @@ void GPU_DX9::ReapplyGfxState() {
void GPU_DX9::BeginFrame() {
textureCacheDX9_->StartFrame();
drawEngine_.BeginFrame();
depalShaderCache_.Decimate();
// fragmentTestCache_.Decimate();
GPUCommon::BeginFrame();
@ -371,7 +368,6 @@ void GPU_DX9::DoState(PointerWrap &p) {
// None of these are necessary when saving.
if (p.mode == p.MODE_READ && !PSP_CoreParameter().frozen) {
textureCache_->Clear(true);
depalShaderCache_.Clear();
drawEngine_.ClearTrackedVertexArrays();
gstate_c.Dirty(DIRTY_TEXTURE_IMAGE);
@ -384,7 +380,7 @@ std::vector<std::string> GPU_DX9::DebugGetShaderIDs(DebugShaderType type) {
case SHADER_TYPE_VERTEXLOADER:
return drawEngine_.DebugGetVertexLoaderIDs();
case SHADER_TYPE_DEPAL:
return depalShaderCache_.DebugGetShaderIDs(type);
return textureCache_->GetDepalShaderCache()->DebugGetShaderIDs(type);
default:
return shaderManagerDX9_->DebugGetShaderIDs(type);
}
@ -395,7 +391,7 @@ std::string GPU_DX9::DebugGetShaderString(std::string id, DebugShaderType type,
case SHADER_TYPE_VERTEXLOADER:
return drawEngine_.DebugGetVertexLoaderString(id, stringType);
case SHADER_TYPE_DEPAL:
return depalShaderCache_.DebugGetShaderString(id, type, stringType);
return textureCache_->GetDepalShaderCache()->DebugGetShaderString(id, type, stringType);
default:
return shaderManagerDX9_->DebugGetShaderString(id, type, stringType);
}

View file

@ -77,7 +77,6 @@ private:
FramebufferManagerDX9 *framebufferManagerDX9_;
TextureCacheDX9 *textureCacheDX9_;
DepalShaderCache depalShaderCache_;
DrawEngineDX9 drawEngine_;
ShaderManagerDX9 *shaderManagerDX9_;
};

View file

@ -39,9 +39,6 @@ public:
void StartFrame() override;
void SetFramebufferManager(FramebufferManagerDX9 *fbManager);
void SetDepalShaderCache(DepalShaderCache *dpCache) {
depalShaderCache_ = dpCache;
}
void ForgetLastTexture() override {
InvalidateLastTexture();

View file

@ -52,9 +52,7 @@
#include "Core/HLE/sceGe.h"
GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
: GPUCommon(gfxCtx, draw),
depalShaderCache_(draw),
drawEngine_(draw) {
: GPUCommon(gfxCtx, draw), drawEngine_(draw) {
CheckGPUFeatures();
VulkanContext *vulkan = (VulkanContext *)gfxCtx->GetAPIContext();
@ -79,7 +77,6 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
framebufferManagerVulkan_->SetDrawEngine(&drawEngine_);
framebufferManagerVulkan_->SetShaderManager(shaderManagerVulkan_);
framebufferManagerVulkan_->Init();
textureCacheVulkan_->SetDepalShaderCache(&depalShaderCache_);
textureCacheVulkan_->SetFramebufferManager(framebufferManagerVulkan_);
textureCacheVulkan_->SetShaderManager(shaderManagerVulkan_);
textureCacheVulkan_->SetDrawEngine(&drawEngine_);
@ -179,8 +176,6 @@ GPU_Vulkan::~GPU_Vulkan() {
// Note: We save the cache in DeviceLost
DestroyDeviceObjects();
framebufferManagerVulkan_->DestroyAllFBOs();
depalShaderCache_.Clear();
depalShaderCache_.DeviceLost();
drawEngine_.DeviceLost();
delete textureCacheVulkan_;
delete pipelineManager_;
@ -429,7 +424,6 @@ void GPU_Vulkan::BuildReportingInfo() {
void GPU_Vulkan::Reinitialize() {
GPUCommon::Reinitialize();
depalShaderCache_.Clear();
}
void GPU_Vulkan::InitClear() {
@ -541,7 +535,6 @@ void GPU_Vulkan::DeviceLost() {
drawEngine_.DeviceLost();
pipelineManager_->DeviceLost();
textureCacheVulkan_->DeviceLost();
depalShaderCache_.DeviceLost();
shaderManagerVulkan_->ClearShaders();
GPUCommon::DeviceLost();
@ -560,7 +553,6 @@ void GPU_Vulkan::DeviceRestore() {
pipelineManager_->DeviceRestore(vulkan);
textureCacheVulkan_->DeviceRestore(draw_);
shaderManagerVulkan_->DeviceRestore(draw_);
depalShaderCache_.DeviceRestore(draw_);
}
void GPU_Vulkan::GetStats(char *buffer, size_t bufsize) {
@ -602,7 +594,6 @@ void GPU_Vulkan::DoState(PointerWrap &p) {
// In Freeze-Frame mode, we don't want to do any of this.
if (p.mode == p.MODE_READ && !PSP_CoreParameter().frozen) {
textureCache_->Clear(true);
depalShaderCache_.Clear();
gstate_c.Dirty(DIRTY_TEXTURE_IMAGE);
framebufferManager_->DestroyAllFBOs();

View file

@ -91,7 +91,6 @@ private:
FramebufferManagerVulkan *framebufferManagerVulkan_;
TextureCacheVulkan *textureCacheVulkan_;
DepalShaderCache depalShaderCache_;
DrawEngineVulkan drawEngine_;
// Manages shaders and UBO data

View file

@ -763,6 +763,10 @@ void TextureCacheVulkan::LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePt
}
}
void TextureCacheVulkan::BoundFramebufferTexture() {
imageView_ = (VkImageView)draw_->GetNativeObject(Draw::NativeObject::BOUND_TEXTURE0_IMAGEVIEW);
}
bool TextureCacheVulkan::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) {
SetTexture();
if (!nextTexture_) {

View file

@ -64,9 +64,6 @@ public:
void DeviceRestore(Draw::DrawContext *draw);
void SetFramebufferManager(FramebufferManagerVulkan *fbManager);
void SetDepalShaderCache(DepalShaderCache *dpCache) {
depalShaderCache_ = dpCache;
}
void SetDrawEngine(DrawEngineVulkan *td) {
drawEngine_ = td;
}
@ -99,6 +96,7 @@ protected:
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
void BindAsClutTexture(Draw::Texture *tex) override;
void ApplySamplingParams(const SamplerCacheKey &key) override;
void BoundFramebufferTexture() override;
private:
void LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt);