Some enum renaming, move RasterChannel to GPU.h.

This commit is contained in:
Henrik Rydgård 2022-08-08 11:24:35 +02:00
parent 1913930541
commit 131098c4d4
11 changed files with 45 additions and 41 deletions

View File

@ -283,7 +283,7 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame
WARN_LOG_ONCE(color_equal_z, G3D, "Framebuffer bound with color addr == z addr, likely will not use Z in this pass: %08x", params.fb_address);
}
FramebufferRenderMode mode = FB_MODE_NORMAL;
RasterMode mode = RASTER_MODE_NORMAL;
// Find a matching framebuffer
VirtualFramebuffer *vfb = nullptr;
@ -331,7 +331,7 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame
// Seems impractical to use the other 16-bit formats for this due to the limited control over alpha,
// so we'll simply only support 565.
if (params.fmt == GE_FORMAT_565) {
mode = FB_MODE_COLOR_TO_DEPTH;
mode = RASTER_MODE_COLOR_TO_DEPTH;
break;
}
} else if (v->fb_stride == params.fb_stride && v->format == params.fmt) {
@ -368,7 +368,7 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame
}
}
if (mode == FB_MODE_COLOR_TO_DEPTH) {
if (mode == RASTER_MODE_COLOR_TO_DEPTH) {
// Lookup in the depth tracking to find which VFB has the latest version of this Z buffer.
// Then bind it in color-to-depth mode.
//

View File

@ -1018,7 +1018,7 @@ void ConvertMaskState(GenericMaskState &maskState, bool allowFramebufferRead) {
return;
}
if (gstate_c.renderMode == FB_MODE_COLOR_TO_DEPTH) {
if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) {
// Suppress color writes entirely in this mode.
maskState.applyFramebufferRead = false;
maskState.rgba[0] = false;

View File

@ -264,7 +264,7 @@ void ComputeFragmentShaderID(FShaderID *id_out, const Draw::Bugs &bugs) {
bool doFlatShading = gstate.getShadeMode() == GE_SHADE_FLAT;
bool useShaderDepal = gstate_c.useShaderDepal;
bool colorWriteMask = IsColorWriteMaskComplex(gstate_c.allowFramebufferRead);
bool colorToDepth = gstate_c.renderMode == FramebufferRenderMode::FB_MODE_COLOR_TO_DEPTH;
bool colorToDepth = gstate_c.renderMode == RasterMode::RASTER_MODE_COLOR_TO_DEPTH;
// Note how we here recompute some of the work already done in state mapping.
// Not ideal! At least we share the code.

View File

@ -265,7 +265,7 @@ SamplerCacheKey TextureCacheCommon::GetSamplingParams(int maxLevel, const TexCac
}
}
if (gstate_c.renderMode == FB_MODE_COLOR_TO_DEPTH) {
if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) {
forceFiltering = TEX_FILTER_FORCE_NEAREST;
}
@ -625,8 +625,8 @@ std::vector<AttachCandidate> TextureCacheCommon::GetFramebufferCandidates(const
std::vector<AttachCandidate> candidates;
FramebufferNotificationChannel channel = Memory::IsDepthTexVRAMAddress(entry.addr) ? FramebufferNotificationChannel::NOTIFY_FB_DEPTH : FramebufferNotificationChannel::NOTIFY_FB_COLOR;
if (channel == FramebufferNotificationChannel::NOTIFY_FB_DEPTH && !gstate_c.Supports(GPU_SUPPORTS_DEPTH_TEXTURE)) {
RasterChannel channel = Memory::IsDepthTexVRAMAddress(entry.addr) ? RasterChannel::RASTER_DEPTH : RasterChannel::RASTER_COLOR;
if (channel == RasterChannel::RASTER_DEPTH && !gstate_c.Supports(GPU_SUPPORTS_DEPTH_TEXTURE)) {
// Depth texture not supported. Don't try to match it, fall back to the memory behind..
return std::vector<AttachCandidate>();
}
@ -645,7 +645,7 @@ std::vector<AttachCandidate> TextureCacheCommon::GetFramebufferCandidates(const
}
if (candidates.size() > 1) {
bool depth = channel == FramebufferNotificationChannel::NOTIFY_FB_DEPTH;
bool depth = channel == RasterChannel::RASTER_DEPTH;
std::string cands;
for (auto &candidate : candidates) {
@ -687,7 +687,7 @@ int TextureCacheCommon::GetBestCandidateIndex(const std::vector<AttachCandidate>
}
// Bonus point for matching stride.
if (candidate.channel == NOTIFY_FB_COLOR && candidate.fb->fb_stride == candidate.entry.bufw) {
if (candidate.channel == RASTER_COLOR && candidate.fb->fb_stride == candidate.entry.bufw) {
relevancy += 100;
}
@ -696,9 +696,9 @@ int TextureCacheCommon::GetBestCandidateIndex(const std::vector<AttachCandidate>
relevancy += 10;
}
if (candidate.channel == NOTIFY_FB_COLOR && candidate.fb->last_frame_render == gpuStats.numFlips) {
if (candidate.channel == RASTER_COLOR && candidate.fb->last_frame_render == gpuStats.numFlips) {
relevancy += 5;
} else if (candidate.channel == NOTIFY_FB_DEPTH && candidate.fb->last_frame_depth_render == gpuStats.numFlips) {
} else if (candidate.channel == RASTER_DEPTH && candidate.fb->last_frame_depth_render == gpuStats.numFlips) {
relevancy += 5;
}
@ -878,10 +878,10 @@ void TextureCacheCommon::NotifyFramebuffer(VirtualFramebuffer *framebuffer, Fram
FramebufferMatchInfo TextureCacheCommon::MatchFramebuffer(
const TextureDefinition &entry,
VirtualFramebuffer *framebuffer, u32 texaddrOffset, FramebufferNotificationChannel channel) const {
VirtualFramebuffer *framebuffer, u32 texaddrOffset, RasterChannel channel) const {
static const u32 MAX_SUBAREA_Y_OFFSET_SAFE = 32;
uint32_t fb_address = channel == NOTIFY_FB_DEPTH ? framebuffer->z_address : framebuffer->fb_address;
uint32_t fb_address = channel == RASTER_DEPTH ? framebuffer->z_address : framebuffer->fb_address;
u32 addr = fb_address & 0x3FFFFFFF;
u32 texaddr = entry.addr + texaddrOffset;
@ -906,14 +906,14 @@ FramebufferMatchInfo TextureCacheCommon::MatchFramebuffer(
case 0x00000000:
case 0x00400000:
// Don't match the depth channel with these addresses when texturing.
if (channel == FramebufferNotificationChannel::NOTIFY_FB_DEPTH) {
if (channel == RasterChannel::RASTER_DEPTH) {
return FramebufferMatchInfo{ FramebufferMatch::NO_MATCH };
}
break;
case 0x00200000:
case 0x00600000:
// Don't match the color channel with these addresses when texturing.
if (channel == FramebufferNotificationChannel::NOTIFY_FB_COLOR) {
if (channel == RasterChannel::RASTER_COLOR) {
return FramebufferMatchInfo{ FramebufferMatch::NO_MATCH };
}
break;
@ -924,7 +924,7 @@ FramebufferMatchInfo TextureCacheCommon::MatchFramebuffer(
}
const bool noOffset = texaddr == addr;
const bool exactMatch = noOffset && entry.format < 4 && channel == NOTIFY_FB_COLOR;
const bool exactMatch = noOffset && entry.format < 4 && channel == RASTER_COLOR;
const u32 w = 1 << ((entry.dim >> 0) & 0xf);
const u32 h = 1 << ((entry.dim >> 8) & 0xf);
// 512 on a 272 framebuffer is sane, so let's be lenient.
@ -958,9 +958,9 @@ FramebufferMatchInfo TextureCacheCommon::MatchFramebuffer(
// Check works for D16 too (???)
const bool matchingClutFormat =
(channel != NOTIFY_FB_COLOR && entry.format == GE_TFMT_CLUT16) ||
(channel == NOTIFY_FB_COLOR && framebuffer->format == GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT32) ||
(channel == NOTIFY_FB_COLOR && framebuffer->format != GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT16);
(channel != RASTER_COLOR && entry.format == GE_TFMT_CLUT16) ||
(channel == RASTER_COLOR && framebuffer->format == GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT32) ||
(channel == RASTER_COLOR && framebuffer->format != GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT16);
// To avoid ruining git blame, kept the same name as the old struct.
FramebufferMatchInfo fbInfo{ FramebufferMatch::VALID };
@ -1782,7 +1782,7 @@ void TextureCacheCommon::ApplyTexture() {
if (nextFramebufferTexture_) {
bool depth = Memory::IsDepthTexVRAMAddress(gstate.getTextureAddress(0));
// ApplyTextureFrameBuffer is responsible for setting SetTextureFullAlpha.
ApplyTextureFramebuffer(nextFramebufferTexture_, gstate.getTextureFormat(), depth ? NOTIFY_FB_DEPTH : NOTIFY_FB_COLOR);
ApplyTextureFramebuffer(nextFramebufferTexture_, gstate.getTextureFormat(), depth ? RASTER_DEPTH : RASTER_COLOR);
nextFramebufferTexture_ = nullptr;
}
@ -1845,12 +1845,12 @@ void TextureCacheCommon::ApplyTexture() {
gstate_c.SetTextureIs3D((entry->status & TexCacheEntry::STATUS_3D) != 0);
}
void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) {
void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, RasterChannel channel) {
DepalShader *depalShader = nullptr;
uint32_t clutMode = gstate.clutformat & 0xFFFFFF;
bool need_depalettize = IsClutFormat(texFormat);
bool depth = channel == NOTIFY_FB_DEPTH;
bool depth = channel == RASTER_DEPTH;
bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && !depth && !gstate_c.curTextureIs3D;
// TODO: Implement shader depal in the fragment shader generator for D3D11 at least.
@ -2262,7 +2262,7 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt
}
// Don't upscale textures in color-to-depth mode.
if (gstate_c.renderMode == FB_MODE_COLOR_TO_DEPTH) {
if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) {
plan.scaleFactor = 1;
}

View File

@ -25,6 +25,7 @@
#include "Common/MemoryUtil.h"
#include "Core/TextureReplacer.h"
#include "Core/System.h"
#include "GPU/GPU.h"
#include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Common/TextureDecoder.h"
#include "GPU/Common/TextureScalerCommon.h"
@ -36,11 +37,6 @@ enum FramebufferNotification {
NOTIFY_FB_DESTROYED,
};
enum FramebufferNotificationChannel {
NOTIFY_FB_COLOR = 0,
NOTIFY_FB_DEPTH = 1,
};
// Changes more frequent than this will be considered "frequent" and prevent texture scaling.
#define TEXCACHE_FRAME_CHANGE_FREQUENT 6
// Note: only used when hash backoff is disabled.
@ -229,7 +225,7 @@ struct AttachCandidate {
FramebufferMatchInfo match;
TextureDefinition entry;
VirtualFramebuffer *fb;
FramebufferNotificationChannel channel;
RasterChannel channel;
std::string ToString();
};
@ -336,7 +332,7 @@ protected:
void DeleteTexture(TexCache::iterator it);
void Decimate(bool forcePressure = false);
void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel);
void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, RasterChannel channel);
void HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete);
virtual void BuildTexture(TexCacheEntry *const entry) = 0;
@ -369,7 +365,7 @@ protected:
SamplerCacheKey GetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight);
void UpdateMaxSeenV(TexCacheEntry *entry, bool throughMode);
FramebufferMatchInfo MatchFramebuffer(const TextureDefinition &entry, VirtualFramebuffer *framebuffer, u32 texaddrOffset, FramebufferNotificationChannel channel) const;
FramebufferMatchInfo MatchFramebuffer(const TextureDefinition &entry, VirtualFramebuffer *framebuffer, u32 texaddrOffset, RasterChannel channel) const;
std::vector<AttachCandidate> GetFramebufferCandidates(const TextureDefinition &entry, u32 texAddrOffset);
int GetBestCandidateIndex(const std::vector<AttachCandidate> &candidates);

View File

@ -293,7 +293,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
GenericStencilFuncState stencilState;
ConvertStencilFuncState(stencilState);
if (gstate_c.renderMode == FB_MODE_COLOR_TO_DEPTH) {
if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) {
// Enforce plain depth writing.
keys_.depthStencil.value = 0;
keys_.depthStencil.depthTestEnable = true;

View File

@ -214,7 +214,7 @@ void DrawEngineDX9::ApplyDrawState(int prim) {
// Set Stencil/Depth
if (gstate_c.renderMode == FB_MODE_COLOR_TO_DEPTH) {
if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) {
// Enforce plain depth writing.
dxstate.depthTest.enable();
dxstate.depthFunc.set(D3DCMP_ALWAYS);

View File

@ -251,7 +251,7 @@ void DrawEngineGLES::ApplyDrawState(int prim) {
GenericStencilFuncState stencilState;
ConvertStencilFuncState(stencilState);
if (gstate_c.renderMode == FB_MODE_COLOR_TO_DEPTH) {
if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) {
// Enforce plain depth writing.
renderManager->SetStencilDisabled();
renderManager->SetDepth(true, true, GL_ALWAYS);

View File

@ -24,9 +24,17 @@ class GPUInterface;
class GPUDebugInterface;
class GraphicsContext;
enum FramebufferRenderMode {
FB_MODE_NORMAL = 0,
FB_MODE_COLOR_TO_DEPTH = 1,
enum RasterMode {
RASTER_MODE_NORMAL = 0,
RASTER_MODE_COLOR_TO_DEPTH = 1,
};
// PSP rasterization has two outputs, color and depth. Stencil is packed
// into the alpha channel of color (if exists), so possibly RASTER_COLOR
// should be named RASTER_COLOR_STENCIL but it gets kinda hard to read.
enum RasterChannel {
RASTER_COLOR = 0,
RASTER_DEPTH = 1,
};
enum SkipDrawReasonFlags {

View File

@ -555,7 +555,7 @@ struct GPUStateCache {
Dirty(DIRTY_FRAGMENTSHADER_STATE | (is3D ? DIRTY_MIPBIAS : 0));
}
}
void SetFramebufferRenderMode(FramebufferRenderMode mode) {
void SetFramebufferRenderMode(RasterMode mode) {
if (mode != renderMode) {
// This mode modifies the fragment shader to write depth, the depth state to write without testing, and the blend state to write nothing to color.
// So we need to re-evaluate those states.
@ -614,7 +614,7 @@ struct GPUStateCache {
bool blueToAlpha;
// Some games try to write to the Z buffer using color. Catch that and actually do the writes to the Z buffer instead.
FramebufferRenderMode renderMode;
RasterMode renderMode;
// TODO: These should be accessed from the current VFB object directly.
u32 curRTWidth;

View File

@ -250,7 +250,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
GenericStencilFuncState stencilState;
ConvertStencilFuncState(stencilState);
if (gstate_c.renderMode == FB_MODE_COLOR_TO_DEPTH) {
if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) {
// Enforce plain depth writing.
key.depthTestEnable = true;
key.depthWriteEnable = true;