mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
VideoCommon: Make dst_alpha state implicit.
This commit is contained in:
@@ -551,9 +551,9 @@ void PixelShaderCache::Shutdown()
|
||||
g_ps_disk_cache.Close();
|
||||
}
|
||||
|
||||
bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode)
|
||||
bool PixelShaderCache::SetShader()
|
||||
{
|
||||
PixelShaderUid uid = GetPixelShaderUid(dstAlphaMode);
|
||||
PixelShaderUid uid = GetPixelShaderUid();
|
||||
|
||||
// Check if the shader is already set
|
||||
if (last_entry)
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
#include "VideoCommon/PixelShaderGen.h"
|
||||
|
||||
enum DSTALPHA_MODE;
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
class PixelShaderCache
|
||||
@@ -19,7 +17,7 @@ public:
|
||||
static void Init();
|
||||
static void Clear();
|
||||
static void Shutdown();
|
||||
static bool SetShader(DSTALPHA_MODE dstAlphaMode); // TODO: Should be renamed to LoadShader
|
||||
static bool SetShader(); // TODO: Should be renamed to LoadShader
|
||||
static bool InsertByteCode(const PixelShaderUid& uid, const void* bytecode,
|
||||
unsigned int bytecodelen);
|
||||
|
||||
|
||||
@@ -940,8 +940,12 @@ void Renderer::RestoreAPIState()
|
||||
BPFunctions::SetScissor();
|
||||
}
|
||||
|
||||
void Renderer::ApplyState(bool bUseDstAlpha)
|
||||
void Renderer::ApplyState()
|
||||
{
|
||||
// TODO: Refactor this logic here.
|
||||
bool bUseDstAlpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
|
||||
bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24;
|
||||
|
||||
gx_state.blend.use_dst_alpha = bUseDstAlpha;
|
||||
D3D::stateman->PushBlendState(gx_state_cache.Get(gx_state.blend));
|
||||
D3D::stateman->PushDepthState(gx_state_cache.Get(gx_state.zmode));
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
bool IsFullscreen() const override;
|
||||
|
||||
// TODO: Fix confusing names (see ResetAPIState and RestoreAPIState)
|
||||
void ApplyState(bool bUseDstAlpha) override;
|
||||
void ApplyState() override;
|
||||
void RestoreState() override;
|
||||
|
||||
void ApplyCullDisable();
|
||||
|
||||
@@ -147,9 +147,9 @@ void VertexManager::Draw(u32 stride)
|
||||
static_cast<Renderer*>(g_renderer.get())->RestoreCull();
|
||||
}
|
||||
|
||||
void VertexManager::vFlush(bool useDstAlpha)
|
||||
void VertexManager::vFlush()
|
||||
{
|
||||
if (!PixelShaderCache::SetShader(useDstAlpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE))
|
||||
if (!PixelShaderCache::SetShader())
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR, true, { printf("Fail to set pixel shader\n"); });
|
||||
return;
|
||||
@@ -179,7 +179,7 @@ void VertexManager::vFlush(bool useDstAlpha)
|
||||
PrepareDrawBuffers(stride);
|
||||
|
||||
VertexLoaderManager::GetCurrentVertexFormat()->SetupVertexPointers();
|
||||
g_renderer->ApplyState(useDstAlpha);
|
||||
g_renderer->ApplyState();
|
||||
|
||||
Draw(stride);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
void PrepareDrawBuffers(u32 stride);
|
||||
void Draw(u32 stride);
|
||||
// temp
|
||||
void vFlush(bool useDstAlpha) override;
|
||||
void vFlush() override;
|
||||
|
||||
u32 m_vertexDrawOffset;
|
||||
u32 m_indexDrawOffset;
|
||||
|
||||
@@ -920,8 +920,12 @@ void Renderer::RestoreAPIState()
|
||||
static bool s_previous_use_dst_alpha = false;
|
||||
static D3DVertexFormat* s_previous_vertex_format = nullptr;
|
||||
|
||||
void Renderer::ApplyState(bool use_dst_alpha)
|
||||
void Renderer::ApplyState()
|
||||
{
|
||||
// TODO: Refactor this logic here.
|
||||
bool use_dst_alpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
|
||||
bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24;
|
||||
|
||||
if (use_dst_alpha != s_previous_use_dst_alpha)
|
||||
{
|
||||
s_previous_use_dst_alpha = use_dst_alpha;
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
void SetViewport() override;
|
||||
|
||||
// TODO: Fix confusing names (see ResetAPIState and RestoreAPIState)
|
||||
void ApplyState(bool use_dst_alpha) override;
|
||||
void ApplyState() override;
|
||||
void RestoreState() override;
|
||||
|
||||
void ApplyCullDisable();
|
||||
|
||||
@@ -132,12 +132,12 @@ void ShaderCache::Shutdown()
|
||||
s_vs_disk_cache.Close();
|
||||
}
|
||||
|
||||
void ShaderCache::LoadAndSetActiveShaders(DSTALPHA_MODE ps_dst_alpha_mode, u32 gs_primitive_type)
|
||||
void ShaderCache::LoadAndSetActiveShaders(u32 gs_primitive_type)
|
||||
{
|
||||
SetCurrentPrimitiveTopology(gs_primitive_type);
|
||||
|
||||
GeometryShaderUid gs_uid = GetGeometryShaderUid(gs_primitive_type);
|
||||
PixelShaderUid ps_uid = GetPixelShaderUid(ps_dst_alpha_mode);
|
||||
PixelShaderUid ps_uid = GetPixelShaderUid();
|
||||
VertexShaderUid vs_uid = GetVertexShaderUid();
|
||||
|
||||
bool gs_changed = gs_uid != s_last_geometry_shader_uid;
|
||||
@@ -156,7 +156,7 @@ void ShaderCache::LoadAndSetActiveShaders(DSTALPHA_MODE ps_dst_alpha_mode, u32 g
|
||||
|
||||
if (ps_changed)
|
||||
{
|
||||
HandlePSUIDChange(ps_uid, ps_dst_alpha_mode);
|
||||
HandlePSUIDChange(ps_uid);
|
||||
}
|
||||
|
||||
if (vs_changed)
|
||||
@@ -219,7 +219,7 @@ void ShaderCache::HandleGSUIDChange(GeometryShaderUid gs_uid, u32 gs_primitive_t
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderCache::HandlePSUIDChange(PixelShaderUid ps_uid, DSTALPHA_MODE ps_dst_alpha_mode)
|
||||
void ShaderCache::HandlePSUIDChange(PixelShaderUid ps_uid)
|
||||
{
|
||||
s_last_pixel_shader_uid = ps_uid;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
static void Clear();
|
||||
static void Shutdown();
|
||||
|
||||
static void LoadAndSetActiveShaders(DSTALPHA_MODE ps_dst_alpha_mode, u32 gs_primitive_type);
|
||||
static void LoadAndSetActiveShaders(u32 gs_primitive_type);
|
||||
|
||||
template <class UidType, class ShaderCacheType>
|
||||
static D3D12_SHADER_BYTECODE InsertByteCode(const UidType& uid, ShaderCacheType* shader_cache,
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
static void SetCurrentPrimitiveTopology(u32 gs_primitive_type);
|
||||
|
||||
static void HandleGSUIDChange(GeometryShaderUid gs_uid, u32 gs_primitive_type);
|
||||
static void HandlePSUIDChange(PixelShaderUid ps_uid, DSTALPHA_MODE ps_dst_alpha_mode);
|
||||
static void HandlePSUIDChange(PixelShaderUid ps_uid);
|
||||
static void HandleVSUIDChange(VertexShaderUid vs_uid);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -135,10 +135,9 @@ void VertexManager::Draw(u32 stride)
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
}
|
||||
|
||||
void VertexManager::vFlush(bool use_dst_alpha)
|
||||
void VertexManager::vFlush()
|
||||
{
|
||||
ShaderCache::LoadAndSetActiveShaders(use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE,
|
||||
m_current_primitive_type);
|
||||
ShaderCache::LoadAndSetActiveShaders(m_current_primitive_type);
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsBBox && BoundingBox::active)
|
||||
BBox::Invalidate();
|
||||
@@ -147,7 +146,7 @@ void VertexManager::vFlush(bool use_dst_alpha)
|
||||
|
||||
PrepareDrawBuffers(stride);
|
||||
|
||||
g_renderer->ApplyState(use_dst_alpha);
|
||||
g_renderer->ApplyState();
|
||||
|
||||
Draw(stride);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ protected:
|
||||
private:
|
||||
void PrepareDrawBuffers(u32 stride);
|
||||
void Draw(u32 stride);
|
||||
void vFlush(bool use_dst_alpha) override;
|
||||
void vFlush() override;
|
||||
|
||||
u32 m_vertex_draw_offset;
|
||||
u32 m_index_draw_offset;
|
||||
|
||||
@@ -33,9 +33,9 @@ void ShaderCache<Uid>::Clear()
|
||||
}
|
||||
|
||||
template <typename Uid>
|
||||
bool ShaderCache<Uid>::SetShader(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type)
|
||||
bool ShaderCache<Uid>::SetShader(u32 primitive_type)
|
||||
{
|
||||
Uid uid = GetUid(dst_alpha_mode, primitive_type, APIType::OpenGL);
|
||||
Uid uid = GetUid(primitive_type, APIType::OpenGL);
|
||||
|
||||
// Check if the shader is already set
|
||||
if (m_last_entry)
|
||||
|
||||
@@ -22,10 +22,10 @@ public:
|
||||
virtual ~ShaderCache();
|
||||
|
||||
void Clear();
|
||||
bool SetShader(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type);
|
||||
bool SetShader(u32 primitive_type);
|
||||
|
||||
protected:
|
||||
virtual Uid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type, APIType api_type) = 0;
|
||||
virtual Uid GetUid(u32 primitive_type, APIType api_type) = 0;
|
||||
virtual ShaderCode GenerateCode(APIType api_type, Uid uid) = 0;
|
||||
|
||||
private:
|
||||
@@ -40,8 +40,7 @@ public:
|
||||
static std::unique_ptr<VertexShaderCache> s_instance;
|
||||
|
||||
protected:
|
||||
VertexShaderUid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type,
|
||||
APIType api_type) override
|
||||
VertexShaderUid GetUid(u32 primitive_type, APIType api_type) override
|
||||
{
|
||||
return GetVertexShaderUid();
|
||||
}
|
||||
@@ -57,8 +56,7 @@ public:
|
||||
static std::unique_ptr<GeometryShaderCache> s_instance;
|
||||
|
||||
protected:
|
||||
GeometryShaderUid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type,
|
||||
APIType api_type) override
|
||||
GeometryShaderUid GetUid(u32 primitive_type, APIType api_type) override
|
||||
{
|
||||
return GetGeometryShaderUid(primitive_type);
|
||||
}
|
||||
@@ -74,9 +72,9 @@ public:
|
||||
static std::unique_ptr<PixelShaderCache> s_instance;
|
||||
|
||||
protected:
|
||||
PixelShaderUid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type, APIType api_type) override
|
||||
PixelShaderUid GetUid(u32 primitive_type, APIType api_type) override
|
||||
{
|
||||
return GetPixelShaderUid(dst_alpha_mode);
|
||||
return GetPixelShaderUid();
|
||||
}
|
||||
ShaderCode GenerateCode(APIType api_type, PixelShaderUid uid) override
|
||||
{
|
||||
|
||||
@@ -40,14 +40,11 @@ void VertexManager::ResetBuffer(u32 stride)
|
||||
IndexGenerator::Start(&m_local_i_buffer[0]);
|
||||
}
|
||||
|
||||
void VertexManager::vFlush(bool use_dst_alpha)
|
||||
void VertexManager::vFlush()
|
||||
{
|
||||
VertexShaderCache::s_instance->SetShader(
|
||||
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, m_current_primitive_type);
|
||||
GeometryShaderCache::s_instance->SetShader(
|
||||
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, m_current_primitive_type);
|
||||
PixelShaderCache::s_instance->SetShader(
|
||||
use_dst_alpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE, m_current_primitive_type);
|
||||
VertexShaderCache::s_instance->SetShader(m_current_primitive_type);
|
||||
GeometryShaderCache::s_instance->SetShader(m_current_primitive_type);
|
||||
PixelShaderCache::s_instance->SetShader(m_current_primitive_type);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -21,7 +21,7 @@ protected:
|
||||
void ResetBuffer(u32 stride) override;
|
||||
|
||||
private:
|
||||
void vFlush(bool use_dst_alpha) override;
|
||||
void vFlush() override;
|
||||
std::vector<u8> m_local_v_buffer;
|
||||
std::vector<u16> m_local_i_buffer;
|
||||
};
|
||||
|
||||
@@ -174,10 +174,10 @@ void ProgramShaderCache::UploadConstants()
|
||||
}
|
||||
}
|
||||
|
||||
SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 primitive_type)
|
||||
SHADER* ProgramShaderCache::SetShader(u32 primitive_type)
|
||||
{
|
||||
SHADERUID uid;
|
||||
GetShaderId(&uid, dstAlphaMode, primitive_type);
|
||||
GetShaderId(&uid, primitive_type);
|
||||
|
||||
// Check if the shader is already set
|
||||
if (last_entry)
|
||||
@@ -388,9 +388,9 @@ GLuint ProgramShaderCache::CompileSingleShader(GLuint type, const std::string& c
|
||||
return result;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 primitive_type)
|
||||
void ProgramShaderCache::GetShaderId(SHADERUID* uid, u32 primitive_type)
|
||||
{
|
||||
uid->puid = GetPixelShaderUid(dstAlphaMode);
|
||||
uid->puid = GetPixelShaderUid();
|
||||
uid->vuid = GetVertexShaderUid();
|
||||
uid->guid = GetGeometryShaderUid(primitive_type);
|
||||
}
|
||||
|
||||
@@ -62,8 +62,8 @@ public:
|
||||
};
|
||||
|
||||
static PCacheEntry GetShaderProgram();
|
||||
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 primitive_type);
|
||||
static void GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 primitive_type);
|
||||
static SHADER* SetShader(u32 primitive_type);
|
||||
static void GetShaderId(SHADERUID* uid, u32 primitive_type);
|
||||
|
||||
static bool CompileShader(SHADER& shader, const std::string& vcode, const std::string& pcode,
|
||||
const std::string& gcode = "");
|
||||
|
||||
@@ -136,7 +136,7 @@ void VertexManager::Draw(u32 stride)
|
||||
static_cast<Renderer*>(g_renderer.get())->SetGenerationMode();
|
||||
}
|
||||
|
||||
void VertexManager::vFlush(bool useDstAlpha)
|
||||
void VertexManager::vFlush()
|
||||
{
|
||||
GLVertexFormat* nativeVertexFmt = (GLVertexFormat*)VertexLoaderManager::GetCurrentVertexFormat();
|
||||
u32 stride = nativeVertexFmt->GetVertexStride();
|
||||
@@ -149,19 +149,7 @@ void VertexManager::vFlush(bool useDstAlpha)
|
||||
|
||||
PrepareDrawBuffers(stride);
|
||||
|
||||
// Makes sure we can actually do Dual source blending
|
||||
bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
|
||||
|
||||
// If host supports GL_ARB_blend_func_extended, we can do dst alpha in
|
||||
// the same pass as regular rendering.
|
||||
if (useDstAlpha && dualSourcePossible)
|
||||
{
|
||||
ProgramShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, m_current_primitive_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgramShaderCache::SetShader(DSTALPHA_NONE, m_current_primitive_type);
|
||||
}
|
||||
ProgramShaderCache::SetShader(m_current_primitive_type);
|
||||
|
||||
// upload global constants
|
||||
ProgramShaderCache::UploadConstants();
|
||||
|
||||
@@ -41,7 +41,7 @@ protected:
|
||||
|
||||
private:
|
||||
void Draw(u32 stride);
|
||||
void vFlush(bool useDstAlpha) override;
|
||||
void vFlush() override;
|
||||
void PrepareDrawBuffers(u32 stride);
|
||||
|
||||
// Alternative buffers in CPU memory for primatives we are going to discard.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user