PixelShaderGen: Drop dstAlphaMode constant in shader generation.

It is already stored within the UID.
This commit is contained in:
degasus 2016-09-28 22:31:39 +02:00
parent 7b29b3c571
commit 829fc8f0ad
10 changed files with 26 additions and 33 deletions

View File

@ -578,7 +578,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode)
} }
// Need to compile a new shader // Need to compile a new shader
ShaderCode code = GeneratePixelShaderCode(dstAlphaMode, APIType::D3D, uid.GetUidData()); ShaderCode code = GeneratePixelShaderCode(APIType::D3D, uid.GetUidData());
D3DBlob* pbytecode; D3DBlob* pbytecode;
if (!D3D::CompilePixelShader(code.GetBuffer(), &pbytecode)) if (!D3D::CompilePixelShader(code.GetBuffer(), &pbytecode))

View File

@ -231,8 +231,7 @@ void ShaderCache::HandlePSUIDChange(PixelShaderUid ps_uid, DSTALPHA_MODE ps_dst_
} }
else else
{ {
ShaderCode ps_code = ShaderCode ps_code = GeneratePixelShaderCode(APIType::D3D, ps_uid.GetUidData());
GeneratePixelShaderCode(ps_dst_alpha_mode, APIType::D3D, ps_uid.GetUidData());
ID3DBlob* ps_bytecode = nullptr; ID3DBlob* ps_bytecode = nullptr;
if (!D3D::CompilePixelShader(ps_code.GetBuffer(), &ps_bytecode)) if (!D3D::CompilePixelShader(ps_code.GetBuffer(), &ps_bytecode))
@ -355,4 +354,4 @@ D3D12_SHADER_BYTECODE ShaderCache::GetVertexShaderFromUid(const VertexShaderUid*
return D3D12_SHADER_BYTECODE(); return D3D12_SHADER_BYTECODE();
} }
} }

View File

@ -60,7 +60,7 @@ bool ShaderCache<Uid>::SetShader(DSTALPHA_MODE dst_alpha_mode, u32 primitive_typ
} }
// Need to compile a new shader // Need to compile a new shader
ShaderCode code = GenerateCode(dst_alpha_mode, APIType::OpenGL, uid); ShaderCode code = GenerateCode(APIType::OpenGL, uid);
m_shaders.emplace(uid, code.GetBuffer()); m_shaders.emplace(uid, code.GetBuffer());
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);

View File

@ -26,7 +26,7 @@ public:
protected: protected:
virtual Uid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type, APIType api_type) = 0; virtual Uid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type, APIType api_type) = 0;
virtual ShaderCode GenerateCode(DSTALPHA_MODE dst_alpha_mode, APIType api_type, Uid uid) = 0; virtual ShaderCode GenerateCode(APIType api_type, Uid uid) = 0;
private: private:
std::map<Uid, std::string> m_shaders; std::map<Uid, std::string> m_shaders;
@ -45,8 +45,7 @@ protected:
{ {
return GetVertexShaderUid(); return GetVertexShaderUid();
} }
ShaderCode GenerateCode(DSTALPHA_MODE dst_alpha_mode, APIType api_type, ShaderCode GenerateCode(APIType api_type, VertexShaderUid uid) override
VertexShaderUid uid) override
{ {
return GenerateVertexShaderCode(api_type, uid.GetUidData()); return GenerateVertexShaderCode(api_type, uid.GetUidData());
} }
@ -63,8 +62,7 @@ protected:
{ {
return GetGeometryShaderUid(primitive_type); return GetGeometryShaderUid(primitive_type);
} }
ShaderCode GenerateCode(DSTALPHA_MODE dst_alpha_mode, APIType api_type, ShaderCode GenerateCode(APIType api_type, GeometryShaderUid uid) override
GeometryShaderUid uid) override
{ {
return GenerateGeometryShaderCode(api_type, uid.GetUidData()); return GenerateGeometryShaderCode(api_type, uid.GetUidData());
} }
@ -80,10 +78,9 @@ protected:
{ {
return GetPixelShaderUid(dst_alpha_mode); return GetPixelShaderUid(dst_alpha_mode);
} }
ShaderCode GenerateCode(DSTALPHA_MODE dst_alpha_mode, APIType api_type, ShaderCode GenerateCode(APIType api_type, PixelShaderUid uid) override
PixelShaderUid uid) override
{ {
return GeneratePixelShaderCode(dst_alpha_mode, api_type, uid.GetUidData()); return GeneratePixelShaderCode(api_type, uid.GetUidData());
} }
}; };

View File

@ -208,7 +208,7 @@ SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 primitive_
newentry.in_cache = 0; newentry.in_cache = 0;
ShaderCode vcode = GenerateVertexShaderCode(APIType::OpenGL, uid.vuid.GetUidData()); ShaderCode vcode = GenerateVertexShaderCode(APIType::OpenGL, uid.vuid.GetUidData());
ShaderCode pcode = GeneratePixelShaderCode(dstAlphaMode, APIType::OpenGL, uid.puid.GetUidData()); ShaderCode pcode = GeneratePixelShaderCode(APIType::OpenGL, uid.puid.GetUidData());
ShaderCode gcode; ShaderCode gcode;
if (g_ActiveConfig.backend_info.bSupportsGeometryShaders && if (g_ActiveConfig.backend_info.bSupportsGeometryShaders &&
!uid.guid.GetUidData()->IsPassthrough()) !uid.guid.GetUidData()->IsPassthrough())

View File

@ -525,8 +525,7 @@ VkShaderModule ObjectCache::GetGeometryShaderForUid(const GeometryShaderUid& uid
return module; return module;
} }
VkShaderModule ObjectCache::GetPixelShaderForUid(const PixelShaderUid& uid, VkShaderModule ObjectCache::GetPixelShaderForUid(const PixelShaderUid& uid)
DSTALPHA_MODE dstalpha_mode)
{ {
auto it = m_ps_cache.shader_map.find(uid); auto it = m_ps_cache.shader_map.find(uid);
if (it != m_ps_cache.shader_map.end()) if (it != m_ps_cache.shader_map.end())
@ -535,8 +534,7 @@ VkShaderModule ObjectCache::GetPixelShaderForUid(const PixelShaderUid& uid,
// Not in the cache, so compile the shader. // Not in the cache, so compile the shader.
ShaderCompiler::SPIRVCodeVector spv; ShaderCompiler::SPIRVCodeVector spv;
VkShaderModule module = VK_NULL_HANDLE; VkShaderModule module = VK_NULL_HANDLE;
ShaderCode source_code = ShaderCode source_code = GeneratePixelShaderCode(APIType::Vulkan, uid.GetUidData());
GeneratePixelShaderCode(dstalpha_mode, APIType::Vulkan, uid.GetUidData());
if (ShaderCompiler::CompileFragmentShader(&spv, source_code.GetBuffer().c_str(), if (ShaderCompiler::CompileFragmentShader(&spv, source_code.GetBuffer().c_str(),
source_code.GetBuffer().length())) source_code.GetBuffer().length()))
{ {

View File

@ -101,7 +101,7 @@ public:
// Accesses ShaderGen shader caches // Accesses ShaderGen shader caches
VkShaderModule GetVertexShaderForUid(const VertexShaderUid& uid); VkShaderModule GetVertexShaderForUid(const VertexShaderUid& uid);
VkShaderModule GetGeometryShaderForUid(const GeometryShaderUid& uid); VkShaderModule GetGeometryShaderForUid(const GeometryShaderUid& uid);
VkShaderModule GetPixelShaderForUid(const PixelShaderUid& uid, DSTALPHA_MODE dstalpha_mode); VkShaderModule GetPixelShaderForUid(const PixelShaderUid& uid);
// Static samplers // Static samplers
VkSampler GetPointSampler() const { return m_point_sampler; } VkSampler GetPointSampler() const { return m_point_sampler; }

View File

@ -223,7 +223,7 @@ bool StateTracker::CheckForShaderChanges(u32 gx_primitive_type, DSTALPHA_MODE ds
if (ps_uid != m_ps_uid) if (ps_uid != m_ps_uid)
{ {
m_pipeline_state.ps = g_object_cache->GetPixelShaderForUid(ps_uid, dstalpha_mode); m_pipeline_state.ps = g_object_cache->GetPixelShaderForUid(ps_uid);
m_ps_uid = ps_uid; m_ps_uid = ps_uid;
changed = true; changed = true;
} }

View File

@ -342,11 +342,10 @@ static void WriteTevRegular(ShaderCode& out, const char* components, int bias, i
static void SampleTexture(ShaderCode& out, const char* texcoords, const char* texswap, int texmap, static void SampleTexture(ShaderCode& out, const char* texcoords, const char* texswap, int texmap,
bool stereo, APIType ApiType); bool stereo, APIType ApiType);
static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType, static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType,
DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth); bool per_pixel_depth);
static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data); static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data);
ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType, ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data)
const pixel_shader_uid_data* uid_data)
{ {
ShaderCode out; ShaderCode out;
@ -515,7 +514,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan) if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
{ {
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
{ {
if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_FRAGMENT_SHADER_INDEX_DECORATION)) if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_FRAGMENT_SHADER_INDEX_DECORATION))
{ {
@ -587,8 +586,9 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
{ {
out.Write("void main(\n"); out.Write("void main(\n");
out.Write(" out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n", out.Write(" out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : SV_Target1," : uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ?
"", "\n out float4 ocol1 : SV_Target1," :
"",
uid_data->per_pixel_depth ? "\n out float depth : SV_Depth," : ""); uid_data->per_pixel_depth ? "\n out float depth : SV_Depth," : "");
out.Write(" in %s float4 colors_0 : COLOR0,\n", out.Write(" in %s float4 colors_0 : COLOR0,\n",
@ -716,7 +716,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
// testing result) // testing result)
if (uid_data->Pretest == AlphaTest::UNDETERMINED || if (uid_data->Pretest == AlphaTest::UNDETERMINED ||
(uid_data->Pretest == AlphaTest::FAIL && uid_data->late_ztest)) (uid_data->Pretest == AlphaTest::FAIL && uid_data->late_ztest))
WriteAlphaTest(out, uid_data, ApiType, dstAlphaMode, uid_data->per_pixel_depth); WriteAlphaTest(out, uid_data, ApiType, uid_data->per_pixel_depth);
if (uid_data->zfreeze) if (uid_data->zfreeze)
{ {
@ -787,7 +787,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
out.Write("\tdepth = float(zCoord) / 16777216.0;\n"); out.Write("\tdepth = float(zCoord) / 16777216.0;\n");
} }
if (dstAlphaMode == DSTALPHA_ALPHA_PASS) if (uid_data->dstAlphaMode == DSTALPHA_ALPHA_PASS)
{ {
out.SetConstantsUsed(C_ALPHA, C_ALPHA); out.SetConstantsUsed(C_ALPHA, C_ALPHA);
out.Write("\tocol0 = float4(float3(prev.rgb), float(" I_ALPHA ".a)) / 255.0;\n"); out.Write("\tocol0 = float4(float3(prev.rgb), float(" I_ALPHA ".a)) / 255.0;\n");
@ -799,7 +799,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
} }
// Use dual-source color blending to perform dst alpha in a single pass // Use dual-source color blending to perform dst alpha in a single pass
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
{ {
out.SetConstantsUsed(C_ALPHA, C_ALPHA); out.SetConstantsUsed(C_ALPHA, C_ALPHA);
@ -1195,7 +1195,7 @@ static const char* tevAlphaFunclogicTable[] = {
}; };
static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType, static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType,
DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth) bool per_pixel_depth)
{ {
static const char* alphaRef[2] = {I_ALPHA ".r", I_ALPHA ".g"}; static const char* alphaRef[2] = {I_ALPHA ".r", I_ALPHA ".g"};
@ -1222,7 +1222,7 @@ static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_dat
out.Write(")) {\n"); out.Write(")) {\n");
out.Write("\t\tocol0 = float4(0.0, 0.0, 0.0, 0.0);\n"); out.Write("\t\tocol0 = float4(0.0, 0.0, 0.0, 0.0);\n");
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
out.Write("\t\tocol1 = float4(0.0, 0.0, 0.0, 0.0);\n"); out.Write("\t\tocol1 = float4(0.0, 0.0, 0.0, 0.0);\n");
if (per_pixel_depth) if (per_pixel_depth)
{ {

View File

@ -166,6 +166,5 @@ struct pixel_shader_uid_data
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid; typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType, ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data);
const pixel_shader_uid_data* uid_data);
PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode); PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode);