mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Move shader caches to VideoCommon
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "Core/ConfigManager.h"
|
||||
@@ -25,16 +24,9 @@
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
GeometryShaderCache::GSCache GeometryShaderCache::GeometryShaders;
|
||||
const GeometryShaderCache::GSCacheEntry* GeometryShaderCache::last_entry;
|
||||
GeometryShaderUid GeometryShaderCache::last_uid;
|
||||
const GeometryShaderCache::GSCacheEntry GeometryShaderCache::pass_entry;
|
||||
|
||||
ID3D11GeometryShader* ClearGeometryShader = nullptr;
|
||||
ID3D11GeometryShader* CopyGeometryShader = nullptr;
|
||||
|
||||
LinearDiskCache<GeometryShaderUid, u8> g_gs_disk_cache;
|
||||
|
||||
ID3D11GeometryShader* GeometryShaderCache::GetClearGeometryShader()
|
||||
{
|
||||
return (g_ActiveConfig.stereo_mode != StereoMode::Off) ? ClearGeometryShader : nullptr;
|
||||
@@ -63,16 +55,6 @@ ID3D11Buffer*& GeometryShaderCache::GetConstantBuffer()
|
||||
return gscbuf;
|
||||
}
|
||||
|
||||
// this class will load the precompiled shaders into our cache
|
||||
class GeometryShaderCacheInserter : public LinearDiskCacheReader<GeometryShaderUid, u8>
|
||||
{
|
||||
public:
|
||||
void Read(const GeometryShaderUid& key, const u8* value, u32 value_size)
|
||||
{
|
||||
GeometryShaderCache::InsertByteCode(key, value, value_size);
|
||||
}
|
||||
};
|
||||
|
||||
const char clear_shader_code[] = {
|
||||
"struct VSOUTPUT\n"
|
||||
"{\n"
|
||||
@@ -155,44 +137,6 @@ void GeometryShaderCache::Init()
|
||||
CopyGeometryShader = D3D::CompileAndCreateGeometryShader(copy_shader_code);
|
||||
CHECK(CopyGeometryShader != nullptr, "Create copy geometry shader");
|
||||
D3D::SetDebugObjectName(CopyGeometryShader, "copy geometry shader");
|
||||
|
||||
Clear();
|
||||
|
||||
if (g_ActiveConfig.bShaderCache)
|
||||
LoadShaderCache();
|
||||
|
||||
if (g_ActiveConfig.CanPrecompileUberShaders())
|
||||
PrecompileShaders();
|
||||
}
|
||||
|
||||
void GeometryShaderCache::LoadShaderCache()
|
||||
{
|
||||
GeometryShaderCacheInserter inserter;
|
||||
g_gs_disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::D3D, "GS", true, true), inserter);
|
||||
}
|
||||
|
||||
void GeometryShaderCache::Reload()
|
||||
{
|
||||
g_gs_disk_cache.Sync();
|
||||
g_gs_disk_cache.Close();
|
||||
Clear();
|
||||
|
||||
if (g_ActiveConfig.bShaderCache)
|
||||
LoadShaderCache();
|
||||
|
||||
if (g_ActiveConfig.CanPrecompileUberShaders())
|
||||
PrecompileShaders();
|
||||
}
|
||||
|
||||
// ONLY to be used during shutdown.
|
||||
void GeometryShaderCache::Clear()
|
||||
{
|
||||
for (auto& iter : GeometryShaders)
|
||||
iter.second.Destroy();
|
||||
GeometryShaders.clear();
|
||||
|
||||
last_entry = nullptr;
|
||||
last_uid = {};
|
||||
}
|
||||
|
||||
void GeometryShaderCache::Shutdown()
|
||||
@@ -201,83 +145,5 @@ void GeometryShaderCache::Shutdown()
|
||||
|
||||
SAFE_RELEASE(ClearGeometryShader);
|
||||
SAFE_RELEASE(CopyGeometryShader);
|
||||
|
||||
Clear();
|
||||
g_gs_disk_cache.Sync();
|
||||
g_gs_disk_cache.Close();
|
||||
}
|
||||
|
||||
bool GeometryShaderCache::SetShader(PrimitiveType primitive_type)
|
||||
{
|
||||
GeometryShaderUid uid = GetGeometryShaderUid(primitive_type);
|
||||
if (last_entry && uid == last_uid)
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
D3D::stateman->SetGeometryShader(last_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the shader is a pass-through shader
|
||||
if (uid.GetUidData()->IsPassthrough())
|
||||
{
|
||||
// Return the default pass-through shader
|
||||
last_uid = uid;
|
||||
last_entry = &pass_entry;
|
||||
D3D::stateman->SetGeometryShader(last_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the shader is already in the cache
|
||||
auto iter = GeometryShaders.find(uid);
|
||||
if (iter != GeometryShaders.end())
|
||||
{
|
||||
const GSCacheEntry& entry = iter->second;
|
||||
last_uid = uid;
|
||||
last_entry = &entry;
|
||||
D3D::stateman->SetGeometryShader(last_entry->shader);
|
||||
return (entry.shader != nullptr);
|
||||
}
|
||||
|
||||
// Need to compile a new shader
|
||||
if (CompileShader(uid))
|
||||
return SetShader(primitive_type);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GeometryShaderCache::CompileShader(const GeometryShaderUid& uid)
|
||||
{
|
||||
D3DBlob* bytecode;
|
||||
ShaderCode code =
|
||||
GenerateGeometryShaderCode(APIType::D3D, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
if (!D3D::CompileGeometryShader(code.GetBuffer(), &bytecode) ||
|
||||
!InsertByteCode(uid, bytecode ? bytecode->Data() : nullptr, bytecode ? bytecode->Size() : 0))
|
||||
{
|
||||
SAFE_RELEASE(bytecode);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Insert the bytecode into the caches
|
||||
g_gs_disk_cache.Append(uid, bytecode->Data(), bytecode->Size());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeometryShaderCache::InsertByteCode(const GeometryShaderUid& uid, const u8* bytecode,
|
||||
size_t len)
|
||||
{
|
||||
GSCacheEntry& newentry = GeometryShaders[uid];
|
||||
newentry.shader = bytecode ? D3D::CreateGeometryShaderFromByteCode(bytecode, len) : nullptr;
|
||||
return newentry.shader != nullptr;
|
||||
}
|
||||
|
||||
void GeometryShaderCache::PrecompileShaders()
|
||||
{
|
||||
EnumerateGeometryShaderUids([](const GeometryShaderUid& uid) {
|
||||
if (GeometryShaders.find(uid) != GeometryShaders.end())
|
||||
return;
|
||||
|
||||
CompileShader(uid);
|
||||
});
|
||||
}
|
||||
|
||||
} // DX11
|
||||
|
||||
@@ -15,36 +15,12 @@ class GeometryShaderCache
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Reload();
|
||||
static void Clear();
|
||||
static void Shutdown();
|
||||
static bool SetShader(PrimitiveType primitive_type);
|
||||
static bool CompileShader(const GeometryShaderUid& uid);
|
||||
static bool InsertByteCode(const GeometryShaderUid& uid, const u8* bytecode, size_t len);
|
||||
static void PrecompileShaders();
|
||||
|
||||
static ID3D11GeometryShader* GetClearGeometryShader();
|
||||
static ID3D11GeometryShader* GetCopyGeometryShader();
|
||||
|
||||
static ID3D11Buffer*& GetConstantBuffer();
|
||||
|
||||
private:
|
||||
struct GSCacheEntry
|
||||
{
|
||||
ID3D11GeometryShader* shader;
|
||||
|
||||
GSCacheEntry() : shader(nullptr) {}
|
||||
void Destroy() { SAFE_RELEASE(shader); }
|
||||
};
|
||||
|
||||
typedef std::map<GeometryShaderUid, GSCacheEntry> GSCache;
|
||||
|
||||
static void LoadShaderCache();
|
||||
|
||||
static GSCache GeometryShaders;
|
||||
static const GSCacheEntry* last_entry;
|
||||
static GeometryShaderUid last_uid;
|
||||
static const GSCacheEntry pass_entry;
|
||||
};
|
||||
|
||||
} // namespace DX11
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "Common/Align.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
@@ -27,17 +26,6 @@
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
|
||||
PixelShaderCache::UberPSCache PixelShaderCache::UberPixelShaders;
|
||||
const PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry;
|
||||
const PixelShaderCache::PSCacheEntry* PixelShaderCache::last_uber_entry;
|
||||
PixelShaderUid PixelShaderCache::last_uid;
|
||||
UberShader::PixelShaderUid PixelShaderCache::last_uber_uid;
|
||||
|
||||
LinearDiskCache<PixelShaderUid, u8> g_ps_disk_cache;
|
||||
LinearDiskCache<UberShader::PixelShaderUid, u8> g_uber_ps_disk_cache;
|
||||
extern std::unique_ptr<VideoCommon::AsyncShaderCompiler> g_async_compiler;
|
||||
|
||||
ID3D11PixelShader* s_ColorCopyProgram[2] = {nullptr};
|
||||
ID3D11PixelShader* s_ClearProgram = nullptr;
|
||||
ID3D11PixelShader* s_AnaglyphProgram = nullptr;
|
||||
@@ -309,17 +297,6 @@ ID3D11Buffer* PixelShaderCache::GetConstantBuffer()
|
||||
return pscbuf;
|
||||
}
|
||||
|
||||
// this class will load the precompiled shaders into our cache
|
||||
template <typename UidType>
|
||||
class PixelShaderCacheInserter : public LinearDiskCacheReader<UidType, u8>
|
||||
{
|
||||
public:
|
||||
void Read(const UidType& key, const u8* value, u32 value_size)
|
||||
{
|
||||
PixelShaderCache::InsertByteCode(key, value, value_size);
|
||||
}
|
||||
};
|
||||
|
||||
void PixelShaderCache::Init()
|
||||
{
|
||||
unsigned int cbsize = Common::AlignUp(static_cast<unsigned int>(sizeof(PixelShaderConstants)),
|
||||
@@ -344,58 +321,6 @@ void PixelShaderCache::Init()
|
||||
s_ColorCopyProgram[0] = D3D::CompileAndCreatePixelShader(color_copy_program_code);
|
||||
CHECK(s_ColorCopyProgram[0] != nullptr, "Create color copy pixel shader");
|
||||
D3D::SetDebugObjectName(s_ColorCopyProgram[0], "color copy pixel shader");
|
||||
|
||||
Clear();
|
||||
|
||||
SETSTAT(stats.numPixelShadersCreated, 0);
|
||||
SETSTAT(stats.numPixelShadersAlive, 0);
|
||||
|
||||
if (g_ActiveConfig.bShaderCache)
|
||||
LoadShaderCache();
|
||||
|
||||
if (g_ActiveConfig.CanPrecompileUberShaders())
|
||||
QueueUberShaderCompiles();
|
||||
}
|
||||
|
||||
void PixelShaderCache::LoadShaderCache()
|
||||
{
|
||||
PixelShaderCacheInserter<PixelShaderUid> inserter;
|
||||
g_ps_disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::D3D, "PS", true, true), inserter);
|
||||
|
||||
PixelShaderCacheInserter<UberShader::PixelShaderUid> uber_inserter;
|
||||
g_uber_ps_disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::D3D, "UberPS", false, true),
|
||||
uber_inserter);
|
||||
}
|
||||
|
||||
void PixelShaderCache::Reload()
|
||||
{
|
||||
g_ps_disk_cache.Sync();
|
||||
g_ps_disk_cache.Close();
|
||||
g_uber_ps_disk_cache.Sync();
|
||||
g_uber_ps_disk_cache.Close();
|
||||
Clear();
|
||||
|
||||
if (g_ActiveConfig.bShaderCache)
|
||||
LoadShaderCache();
|
||||
|
||||
if (g_ActiveConfig.CanPrecompileUberShaders())
|
||||
QueueUberShaderCompiles();
|
||||
}
|
||||
|
||||
// ONLY to be used during shutdown.
|
||||
void PixelShaderCache::Clear()
|
||||
{
|
||||
for (auto& iter : PixelShaders)
|
||||
iter.second.Destroy();
|
||||
for (auto& iter : UberPixelShaders)
|
||||
iter.second.Destroy();
|
||||
PixelShaders.clear();
|
||||
UberPixelShaders.clear();
|
||||
|
||||
last_entry = nullptr;
|
||||
last_uber_entry = nullptr;
|
||||
last_uid = {};
|
||||
last_uber_uid = {};
|
||||
}
|
||||
|
||||
// Used in Swap() when AA mode has changed
|
||||
@@ -420,255 +345,5 @@ void PixelShaderCache::Shutdown()
|
||||
SAFE_RELEASE(s_rgba6_to_rgb8[i]);
|
||||
SAFE_RELEASE(s_rgb8_to_rgba6[i]);
|
||||
}
|
||||
|
||||
Clear();
|
||||
g_ps_disk_cache.Sync();
|
||||
g_ps_disk_cache.Close();
|
||||
g_uber_ps_disk_cache.Sync();
|
||||
g_uber_ps_disk_cache.Close();
|
||||
}
|
||||
|
||||
bool PixelShaderCache::SetShader()
|
||||
{
|
||||
if (g_ActiveConfig.bDisableSpecializedShaders)
|
||||
return SetUberShader();
|
||||
|
||||
PixelShaderUid uid = GetPixelShaderUid();
|
||||
ClearUnusedPixelShaderUidBits(APIType::D3D, &uid);
|
||||
if (last_entry && uid == last_uid)
|
||||
{
|
||||
if (last_entry->pending)
|
||||
return SetUberShader();
|
||||
|
||||
if (!last_entry->shader)
|
||||
return false;
|
||||
|
||||
D3D::stateman->SetPixelShader(last_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the shader is already in the cache
|
||||
auto iter = PixelShaders.find(uid);
|
||||
if (iter != PixelShaders.end())
|
||||
{
|
||||
const PSCacheEntry& entry = iter->second;
|
||||
if (entry.pending)
|
||||
return SetUberShader();
|
||||
|
||||
last_uid = uid;
|
||||
last_entry = &entry;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
if (!last_entry->shader)
|
||||
return false;
|
||||
|
||||
D3D::stateman->SetPixelShader(last_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Background compiling?
|
||||
if (g_ActiveConfig.CanBackgroundCompileShaders())
|
||||
{
|
||||
// Create a pending entry
|
||||
PSCacheEntry entry;
|
||||
entry.pending = true;
|
||||
PixelShaders[uid] = entry;
|
||||
|
||||
// Queue normal shader compiling and use ubershader
|
||||
g_async_compiler->QueueWorkItem(
|
||||
g_async_compiler->CreateWorkItem<PixelShaderCompilerWorkItem>(uid));
|
||||
return SetUberShader();
|
||||
}
|
||||
|
||||
// Need to compile a new shader
|
||||
D3DBlob* bytecode = nullptr;
|
||||
ShaderCode code =
|
||||
GeneratePixelShaderCode(APIType::D3D, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
D3D::CompilePixelShader(code.GetBuffer(), &bytecode);
|
||||
if (!InsertByteCode(uid, bytecode ? bytecode->Data() : nullptr, bytecode ? bytecode->Size() : 0))
|
||||
{
|
||||
SAFE_RELEASE(bytecode);
|
||||
return false;
|
||||
}
|
||||
|
||||
g_ps_disk_cache.Append(uid, bytecode->Data(), bytecode->Size());
|
||||
return SetShader();
|
||||
}
|
||||
|
||||
bool PixelShaderCache::SetUberShader()
|
||||
{
|
||||
UberShader::PixelShaderUid uid = UberShader::GetPixelShaderUid();
|
||||
UberShader::ClearUnusedPixelShaderUidBits(APIType::D3D, &uid);
|
||||
|
||||
if (last_uber_entry && last_uber_uid == uid)
|
||||
{
|
||||
if (!last_uber_entry->shader)
|
||||
return false;
|
||||
|
||||
D3D::stateman->SetPixelShader(last_uber_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto iter = UberPixelShaders.find(uid);
|
||||
if (iter != UberPixelShaders.end())
|
||||
{
|
||||
const PSCacheEntry& entry = iter->second;
|
||||
last_uber_uid = uid;
|
||||
last_uber_entry = &entry;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
if (!last_uber_entry->shader)
|
||||
return false;
|
||||
|
||||
D3D::stateman->SetPixelShader(last_uber_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
D3DBlob* bytecode = nullptr;
|
||||
ShaderCode code =
|
||||
UberShader::GenPixelShader(APIType::D3D, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
D3D::CompilePixelShader(code.GetBuffer(), &bytecode);
|
||||
if (!InsertByteCode(uid, bytecode ? bytecode->Data() : nullptr, bytecode ? bytecode->Size() : 0))
|
||||
{
|
||||
SAFE_RELEASE(bytecode);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Lookup map again.
|
||||
g_uber_ps_disk_cache.Append(uid, bytecode->Data(), bytecode->Size());
|
||||
bytecode->Release();
|
||||
return SetUberShader();
|
||||
}
|
||||
|
||||
bool PixelShaderCache::InsertByteCode(const PixelShaderUid& uid, const u8* data, size_t len)
|
||||
{
|
||||
ID3D11PixelShader* shader = data ? D3D::CreatePixelShaderFromByteCode(data, len) : nullptr;
|
||||
if (!InsertShader(uid, shader))
|
||||
{
|
||||
SAFE_RELEASE(shader);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PixelShaderCache::InsertByteCode(const UberShader::PixelShaderUid& uid, const u8* data,
|
||||
size_t len)
|
||||
{
|
||||
ID3D11PixelShader* shader = data ? D3D::CreatePixelShaderFromByteCode(data, len) : nullptr;
|
||||
if (!InsertShader(uid, shader))
|
||||
{
|
||||
SAFE_RELEASE(shader);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PixelShaderCache::InsertShader(const PixelShaderUid& uid, ID3D11PixelShader* shader)
|
||||
{
|
||||
auto iter = PixelShaders.find(uid);
|
||||
if (iter != PixelShaders.end() && !iter->second.pending)
|
||||
return false;
|
||||
|
||||
PSCacheEntry& newentry = PixelShaders[uid];
|
||||
newentry.pending = false;
|
||||
newentry.shader = shader;
|
||||
|
||||
INCSTAT(stats.numPixelShadersCreated);
|
||||
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
|
||||
return (shader != nullptr);
|
||||
}
|
||||
|
||||
bool PixelShaderCache::InsertShader(const UberShader::PixelShaderUid& uid,
|
||||
ID3D11PixelShader* shader)
|
||||
{
|
||||
auto iter = UberPixelShaders.find(uid);
|
||||
if (iter != UberPixelShaders.end() && !iter->second.pending)
|
||||
return false;
|
||||
|
||||
PSCacheEntry& newentry = UberPixelShaders[uid];
|
||||
newentry.pending = false;
|
||||
newentry.shader = shader;
|
||||
return (shader != nullptr);
|
||||
}
|
||||
|
||||
void PixelShaderCache::QueueUberShaderCompiles()
|
||||
{
|
||||
UberShader::EnumeratePixelShaderUids([&](const UberShader::PixelShaderUid& uid) {
|
||||
if (UberPixelShaders.find(uid) != UberPixelShaders.end())
|
||||
return;
|
||||
|
||||
g_async_compiler->QueueWorkItem(
|
||||
g_async_compiler->CreateWorkItem<UberPixelShaderCompilerWorkItem>(uid));
|
||||
});
|
||||
|
||||
g_async_compiler->WaitUntilCompletion([](size_t completed, size_t total) {
|
||||
Host_UpdateProgressDialog(GetStringT("Compiling shaders...").c_str(),
|
||||
static_cast<int>(completed), static_cast<int>(total));
|
||||
});
|
||||
g_async_compiler->RetrieveWorkItems();
|
||||
Host_UpdateProgressDialog("", -1, -1);
|
||||
}
|
||||
|
||||
PixelShaderCache::PixelShaderCompilerWorkItem::PixelShaderCompilerWorkItem(
|
||||
const PixelShaderUid& uid)
|
||||
{
|
||||
std::memcpy(&m_uid, &uid, sizeof(uid));
|
||||
}
|
||||
|
||||
PixelShaderCache::PixelShaderCompilerWorkItem::~PixelShaderCompilerWorkItem()
|
||||
{
|
||||
SAFE_RELEASE(m_bytecode);
|
||||
}
|
||||
|
||||
bool PixelShaderCache::PixelShaderCompilerWorkItem::Compile()
|
||||
{
|
||||
ShaderCode code =
|
||||
GeneratePixelShaderCode(APIType::D3D, ShaderHostConfig::GetCurrent(), m_uid.GetUidData());
|
||||
|
||||
if (D3D::CompilePixelShader(code.GetBuffer(), &m_bytecode))
|
||||
m_shader = D3D::CreatePixelShaderFromByteCode(m_bytecode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PixelShaderCache::PixelShaderCompilerWorkItem::Retrieve()
|
||||
{
|
||||
if (InsertShader(m_uid, m_shader))
|
||||
g_ps_disk_cache.Append(m_uid, m_bytecode->Data(), m_bytecode->Size());
|
||||
else
|
||||
SAFE_RELEASE(m_shader);
|
||||
}
|
||||
|
||||
PixelShaderCache::UberPixelShaderCompilerWorkItem::UberPixelShaderCompilerWorkItem(
|
||||
const UberShader::PixelShaderUid& uid)
|
||||
{
|
||||
std::memcpy(&m_uid, &uid, sizeof(uid));
|
||||
}
|
||||
|
||||
PixelShaderCache::UberPixelShaderCompilerWorkItem::~UberPixelShaderCompilerWorkItem()
|
||||
{
|
||||
SAFE_RELEASE(m_bytecode);
|
||||
}
|
||||
|
||||
bool PixelShaderCache::UberPixelShaderCompilerWorkItem::Compile()
|
||||
{
|
||||
ShaderCode code =
|
||||
UberShader::GenPixelShader(APIType::D3D, ShaderHostConfig::GetCurrent(), m_uid.GetUidData());
|
||||
|
||||
if (D3D::CompilePixelShader(code.GetBuffer(), &m_bytecode))
|
||||
m_shader = D3D::CreatePixelShaderFromByteCode(m_bytecode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PixelShaderCache::UberPixelShaderCompilerWorkItem::Retrieve()
|
||||
{
|
||||
if (InsertShader(m_uid, m_shader))
|
||||
g_uber_ps_disk_cache.Append(m_uid, m_bytecode->Data(), m_bytecode->Size());
|
||||
else
|
||||
SAFE_RELEASE(m_shader);
|
||||
}
|
||||
|
||||
} // DX11
|
||||
|
||||
@@ -19,16 +19,7 @@ class PixelShaderCache
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Reload();
|
||||
static void Clear();
|
||||
static void Shutdown();
|
||||
static bool SetShader();
|
||||
static bool SetUberShader();
|
||||
static bool InsertByteCode(const PixelShaderUid& uid, const u8* data, size_t len);
|
||||
static bool InsertByteCode(const UberShader::PixelShaderUid& uid, const u8* data, size_t len);
|
||||
static bool InsertShader(const PixelShaderUid& uid, ID3D11PixelShader* shader);
|
||||
static bool InsertShader(const UberShader::PixelShaderUid& uid, ID3D11PixelShader* shader);
|
||||
static void QueueUberShaderCompiles();
|
||||
|
||||
static ID3D11Buffer* GetConstantBuffer();
|
||||
|
||||
@@ -40,58 +31,6 @@ public:
|
||||
static ID3D11PixelShader* ReinterpRGB8ToRGBA6(bool multisampled);
|
||||
|
||||
static void InvalidateMSAAShaders();
|
||||
|
||||
private:
|
||||
struct PSCacheEntry
|
||||
{
|
||||
ID3D11PixelShader* shader;
|
||||
bool pending;
|
||||
|
||||
PSCacheEntry() : shader(nullptr), pending(false) {}
|
||||
void Destroy() { SAFE_RELEASE(shader); }
|
||||
};
|
||||
|
||||
class PixelShaderCompilerWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
|
||||
{
|
||||
public:
|
||||
explicit PixelShaderCompilerWorkItem(const PixelShaderUid& uid);
|
||||
~PixelShaderCompilerWorkItem() override;
|
||||
|
||||
bool Compile() override;
|
||||
void Retrieve() override;
|
||||
|
||||
private:
|
||||
PixelShaderUid m_uid;
|
||||
ID3D11PixelShader* m_shader = nullptr;
|
||||
D3DBlob* m_bytecode = nullptr;
|
||||
};
|
||||
|
||||
class UberPixelShaderCompilerWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
|
||||
{
|
||||
public:
|
||||
explicit UberPixelShaderCompilerWorkItem(const UberShader::PixelShaderUid& uid);
|
||||
~UberPixelShaderCompilerWorkItem() override;
|
||||
|
||||
bool Compile() override;
|
||||
void Retrieve() override;
|
||||
|
||||
private:
|
||||
UberShader::PixelShaderUid m_uid;
|
||||
ID3D11PixelShader* m_shader = nullptr;
|
||||
D3DBlob* m_bytecode = nullptr;
|
||||
};
|
||||
|
||||
typedef std::map<PixelShaderUid, PSCacheEntry> PSCache;
|
||||
typedef std::map<UberShader::PixelShaderUid, PSCacheEntry> UberPSCache;
|
||||
|
||||
static void LoadShaderCache();
|
||||
|
||||
static PSCache PixelShaders;
|
||||
static UberPSCache UberPixelShaders;
|
||||
static const PSCacheEntry* last_entry;
|
||||
static const PSCacheEntry* last_uber_entry;
|
||||
static PixelShaderUid last_uid;
|
||||
static UberShader::PixelShaderUid last_uber_uid;
|
||||
};
|
||||
|
||||
} // namespace DX11
|
||||
|
||||
@@ -71,15 +71,6 @@ Renderer::Renderer(int backbuffer_width, int backbuffer_height)
|
||||
g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
|
||||
SetupDeviceObjects();
|
||||
|
||||
// Setup GX pipeline state
|
||||
for (auto& sampler : m_gx_state.samplers)
|
||||
sampler.hex = RenderState::GetPointSamplerState().hex;
|
||||
|
||||
m_gx_state.zmode.testenable = false;
|
||||
m_gx_state.zmode.updateenable = false;
|
||||
m_gx_state.zmode.func = ZMode::NEVER;
|
||||
m_gx_state.raster.cullmode = GenMode::CULL_NONE;
|
||||
|
||||
// Clear EFB textures
|
||||
constexpr std::array<float, 4> clear_color{{0.f, 0.f, 0.f, 1.f}};
|
||||
D3D::context->ClearRenderTargetView(FramebufferManager::GetEFBColorTexture()->GetRTV(),
|
||||
@@ -315,11 +306,6 @@ void Renderer::SetPipeline(const AbstractPipeline* pipeline)
|
||||
void Renderer::DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
// Textures are fine, they're set directly via SetTexture.
|
||||
// Since samplers are set via gx_state, we need to fix this up here.
|
||||
for (size_t stage = 0; stage < m_gx_state.samplers.size(); stage++)
|
||||
D3D::stateman->SetSampler(stage, m_state_cache.Get(m_gx_state.samplers[stage]));
|
||||
|
||||
// Copy in uniforms.
|
||||
if (uniforms_size > 0)
|
||||
{
|
||||
@@ -640,11 +626,6 @@ void Renderer::ReinterpretPixelData(unsigned int convtype)
|
||||
RestoreAPIState();
|
||||
}
|
||||
|
||||
void Renderer::SetBlendingState(const BlendingState& state)
|
||||
{
|
||||
m_gx_state.blend.hex = state.hex;
|
||||
}
|
||||
|
||||
// This function has the final picture. We adjust the aspect ratio here.
|
||||
void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region, u64 ticks,
|
||||
float Gamma)
|
||||
@@ -685,7 +666,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
|
||||
// Enable configuration changes
|
||||
UpdateActiveConfig();
|
||||
g_texture_cache->OnConfigChanged(g_ActiveConfig);
|
||||
VertexShaderCache::RetreiveAsyncShaders();
|
||||
|
||||
// Flip/present backbuffer to frontbuffer here
|
||||
if (D3D::swapchain)
|
||||
@@ -708,12 +688,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
|
||||
D3D11_CLEAR_DEPTH, 0.f, 0);
|
||||
}
|
||||
|
||||
if (CheckForHostConfigChanges())
|
||||
{
|
||||
VertexShaderCache::Reload();
|
||||
GeometryShaderCache::Reload();
|
||||
PixelShaderCache::Reload();
|
||||
}
|
||||
CheckForHostConfigChanges();
|
||||
|
||||
// begin next frame
|
||||
RestoreAPIState();
|
||||
@@ -786,30 +761,6 @@ void Renderer::RestoreAPIState()
|
||||
BPFunctions::SetScissor();
|
||||
}
|
||||
|
||||
void Renderer::ApplyState()
|
||||
{
|
||||
D3D::stateman->SetBlendState(m_state_cache.Get(m_gx_state.blend));
|
||||
D3D::stateman->SetDepthState(m_state_cache.Get(m_gx_state.zmode));
|
||||
D3D::stateman->SetRasterizerState(m_state_cache.Get(m_gx_state.raster));
|
||||
D3D::stateman->SetPrimitiveTopology(
|
||||
StateCache::GetPrimitiveTopology(m_gx_state.raster.primitive));
|
||||
FramebufferManager::SetIntegerEFBRenderTarget(m_gx_state.blend.logicopenable);
|
||||
|
||||
for (u32 stage = 0; stage < static_cast<u32>(m_gx_state.samplers.size()); stage++)
|
||||
D3D::stateman->SetSampler(stage, m_state_cache.Get(m_gx_state.samplers[stage]));
|
||||
|
||||
ID3D11Buffer* vertexConstants = VertexShaderCache::GetConstantBuffer();
|
||||
|
||||
D3D::stateman->SetPixelConstants(PixelShaderCache::GetConstantBuffer(),
|
||||
g_ActiveConfig.bEnablePixelLighting ? vertexConstants : nullptr);
|
||||
D3D::stateman->SetVertexConstants(vertexConstants);
|
||||
D3D::stateman->SetGeometryConstants(GeometryShaderCache::GetConstantBuffer());
|
||||
}
|
||||
|
||||
void Renderer::RestoreState()
|
||||
{
|
||||
}
|
||||
|
||||
void Renderer::SetFramebuffer(const AbstractFramebuffer* framebuffer)
|
||||
{
|
||||
const DXFramebuffer* fb = static_cast<const DXFramebuffer*>(framebuffer);
|
||||
@@ -840,16 +791,6 @@ void Renderer::SetAndClearFramebuffer(const AbstractFramebuffer* framebuffer,
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::SetRasterizationState(const RasterizationState& state)
|
||||
{
|
||||
m_gx_state.raster.hex = state.hex;
|
||||
}
|
||||
|
||||
void Renderer::SetDepthState(const DepthState& state)
|
||||
{
|
||||
m_gx_state.zmode.hex = state.hex;
|
||||
}
|
||||
|
||||
void Renderer::SetTexture(u32 index, const AbstractTexture* texture)
|
||||
{
|
||||
D3D::stateman->SetTexture(
|
||||
@@ -859,7 +800,7 @@ void Renderer::SetTexture(u32 index, const AbstractTexture* texture)
|
||||
|
||||
void Renderer::SetSamplerState(u32 index, const SamplerState& state)
|
||||
{
|
||||
m_gx_state.samplers[index].hex = state.hex;
|
||||
D3D::stateman->SetSampler(index, m_state_cache.Get(state));
|
||||
}
|
||||
|
||||
void Renderer::UnbindTexture(const AbstractTexture* texture)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <d3d11.h>
|
||||
#include <string>
|
||||
#include "VideoBackends/D3D/D3DState.h"
|
||||
@@ -41,10 +40,7 @@ public:
|
||||
void SetAndClearFramebuffer(const AbstractFramebuffer* framebuffer,
|
||||
const ClearColor& color_value = {},
|
||||
float depth_value = 0.0f) override;
|
||||
void SetBlendingState(const BlendingState& state) override;
|
||||
void SetScissorRect(const MathUtil::Rectangle<int>& rc) override;
|
||||
void SetRasterizationState(const RasterizationState& state) override;
|
||||
void SetDepthState(const DepthState& state) override;
|
||||
void SetTexture(u32 index, const AbstractTexture* texture) override;
|
||||
void SetSamplerState(u32 index, const SamplerState& state) override;
|
||||
void UnbindTexture(const AbstractTexture* texture) override;
|
||||
@@ -54,10 +50,6 @@ public:
|
||||
void SetFullscreen(bool enable_fullscreen) override;
|
||||
bool IsFullscreen() const override;
|
||||
|
||||
// TODO: Fix confusing names (see ResetAPIState and RestoreAPIState)
|
||||
void ApplyState() override;
|
||||
void RestoreState() override;
|
||||
|
||||
void RenderText(const std::string& text, int left, int top, u32 color) override;
|
||||
|
||||
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
|
||||
@@ -84,14 +76,6 @@ public:
|
||||
u32 groups_x, u32 groups_y, u32 groups_z) override;
|
||||
|
||||
private:
|
||||
struct GXPipelineState
|
||||
{
|
||||
std::array<SamplerState, 8> samplers;
|
||||
BlendingState blend;
|
||||
DepthState zmode;
|
||||
RasterizationState raster;
|
||||
};
|
||||
|
||||
void SetupDeviceObjects();
|
||||
void TeardownDeviceObjects();
|
||||
void Create3DVisionTexture(int width, int height);
|
||||
@@ -106,7 +90,6 @@ private:
|
||||
void UpdateUtilityVertexBuffer(const void* vertices, u32 vertex_stride, u32 num_vertices);
|
||||
|
||||
StateCache m_state_cache;
|
||||
GXPipelineState m_gx_state;
|
||||
|
||||
std::array<ID3D11BlendState*, 4> m_clear_blend_states{};
|
||||
std::array<ID3D11DepthStencilState*, 3> m_clear_depth_states{};
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "VideoBackends/D3D/BoundingBox.h"
|
||||
#include "VideoBackends/D3D/D3DBase.h"
|
||||
#include "VideoBackends/D3D/D3DState.h"
|
||||
#include "VideoBackends/D3D/FramebufferManager.h"
|
||||
#include "VideoBackends/D3D/GeometryShaderCache.h"
|
||||
#include "VideoBackends/D3D/PixelShaderCache.h"
|
||||
#include "VideoBackends/D3D/Render.h"
|
||||
@@ -135,42 +136,23 @@ void VertexManager::Draw(u32 stride)
|
||||
|
||||
void VertexManager::vFlush()
|
||||
{
|
||||
if (!PixelShaderCache::SetShader())
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR, true, { printf("Fail to set pixel shader\n"); });
|
||||
return;
|
||||
}
|
||||
|
||||
D3DVertexFormat* vertex_format =
|
||||
static_cast<D3DVertexFormat*>(VertexLoaderManager::GetCurrentVertexFormat());
|
||||
if (!VertexShaderCache::SetShader(vertex_format))
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR, true, { printf("Fail to set pixel shader\n"); });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GeometryShaderCache::SetShader(m_current_primitive_type))
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR, true, { printf("Fail to set pixel shader\n"); });
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsBBox && BoundingBox::active)
|
||||
{
|
||||
D3D::context->OMSetRenderTargetsAndUnorderedAccessViews(
|
||||
D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, 2, 1, &BBox::GetUAV(),
|
||||
nullptr);
|
||||
}
|
||||
|
||||
u32 stride = VertexLoaderManager::GetCurrentVertexFormat()->GetVertexStride();
|
||||
|
||||
PrepareDrawBuffers(stride);
|
||||
|
||||
g_renderer->ApplyState();
|
||||
if (!m_current_pipeline_object)
|
||||
return;
|
||||
|
||||
FramebufferManager::SetIntegerEFBRenderTarget(
|
||||
m_current_pipeline_config.blending_state.logicopenable);
|
||||
g_renderer->SetPipeline(m_current_pipeline_object);
|
||||
|
||||
ID3D11Buffer* vertexConstants = VertexShaderCache::GetConstantBuffer();
|
||||
D3D::stateman->SetPixelConstants(PixelShaderCache::GetConstantBuffer(),
|
||||
g_ActiveConfig.bEnablePixelLighting ? vertexConstants : nullptr);
|
||||
D3D::stateman->SetVertexConstants(vertexConstants);
|
||||
D3D::stateman->SetGeometryConstants(GeometryShaderCache::GetConstantBuffer());
|
||||
|
||||
Draw(stride);
|
||||
|
||||
g_renderer->RestoreState();
|
||||
}
|
||||
|
||||
void VertexManager::ResetBuffer(u32 stride)
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "Common/Align.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
@@ -28,22 +27,11 @@
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
VertexShaderCache::VSCache VertexShaderCache::vshaders;
|
||||
VertexShaderCache::UberVSCache VertexShaderCache::ubervshaders;
|
||||
const VertexShaderCache::VSCacheEntry* VertexShaderCache::last_entry;
|
||||
const VertexShaderCache::VSCacheEntry* VertexShaderCache::last_uber_entry;
|
||||
VertexShaderUid VertexShaderCache::last_uid;
|
||||
UberShader::VertexShaderUid VertexShaderCache::last_uber_uid;
|
||||
|
||||
static ID3D11VertexShader* SimpleVertexShader = nullptr;
|
||||
static ID3D11VertexShader* ClearVertexShader = nullptr;
|
||||
static ID3D11InputLayout* SimpleLayout = nullptr;
|
||||
static ID3D11InputLayout* ClearLayout = nullptr;
|
||||
|
||||
LinearDiskCache<VertexShaderUid, u8> g_vs_disk_cache;
|
||||
LinearDiskCache<UberShader::VertexShaderUid, u8> g_uber_vs_disk_cache;
|
||||
std::unique_ptr<VideoCommon::AsyncShaderCompiler> g_async_compiler;
|
||||
|
||||
ID3D11VertexShader* VertexShaderCache::GetSimpleVertexShader()
|
||||
{
|
||||
return SimpleVertexShader;
|
||||
@@ -164,73 +152,12 @@ void VertexShaderCache::Init()
|
||||
D3D::SetDebugObjectName(ClearVertexShader, "clear vertex shader");
|
||||
D3D::SetDebugObjectName(ClearLayout, "clear input layout");
|
||||
|
||||
Clear();
|
||||
|
||||
SETSTAT(stats.numVertexShadersCreated, 0);
|
||||
SETSTAT(stats.numVertexShadersAlive, 0);
|
||||
|
||||
if (g_ActiveConfig.bShaderCache)
|
||||
LoadShaderCache();
|
||||
|
||||
g_async_compiler = std::make_unique<VideoCommon::AsyncShaderCompiler>();
|
||||
g_async_compiler->ResizeWorkerThreads(g_ActiveConfig.CanPrecompileUberShaders() ?
|
||||
g_ActiveConfig.GetShaderPrecompilerThreads() :
|
||||
g_ActiveConfig.GetShaderCompilerThreads());
|
||||
|
||||
if (g_ActiveConfig.CanPrecompileUberShaders())
|
||||
QueueUberShaderCompiles();
|
||||
}
|
||||
|
||||
void VertexShaderCache::LoadShaderCache()
|
||||
{
|
||||
VertexShaderCacheInserter<VertexShaderUid> inserter;
|
||||
g_vs_disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::D3D, "VS", true, true), inserter);
|
||||
|
||||
VertexShaderCacheInserter<UberShader::VertexShaderUid> uber_inserter;
|
||||
g_uber_vs_disk_cache.OpenAndRead(GetDiskShaderCacheFileName(APIType::D3D, "UberVS", false, true),
|
||||
uber_inserter);
|
||||
}
|
||||
|
||||
void VertexShaderCache::Reload()
|
||||
{
|
||||
g_async_compiler->WaitUntilCompletion();
|
||||
g_async_compiler->RetrieveWorkItems();
|
||||
|
||||
g_vs_disk_cache.Sync();
|
||||
g_vs_disk_cache.Close();
|
||||
g_uber_vs_disk_cache.Sync();
|
||||
g_uber_vs_disk_cache.Close();
|
||||
Clear();
|
||||
|
||||
if (g_ActiveConfig.bShaderCache)
|
||||
LoadShaderCache();
|
||||
|
||||
if (g_ActiveConfig.CanPrecompileUberShaders())
|
||||
QueueUberShaderCompiles();
|
||||
}
|
||||
|
||||
void VertexShaderCache::Clear()
|
||||
{
|
||||
for (auto& iter : vshaders)
|
||||
iter.second.Destroy();
|
||||
for (auto& iter : ubervshaders)
|
||||
iter.second.Destroy();
|
||||
vshaders.clear();
|
||||
ubervshaders.clear();
|
||||
|
||||
last_uid = {};
|
||||
last_uber_uid = {};
|
||||
last_entry = nullptr;
|
||||
last_uber_entry = nullptr;
|
||||
last_uid = {};
|
||||
last_uber_uid = {};
|
||||
}
|
||||
|
||||
void VertexShaderCache::Shutdown()
|
||||
{
|
||||
g_async_compiler->StopWorkerThreads();
|
||||
g_async_compiler->RetrieveWorkItems();
|
||||
|
||||
SAFE_RELEASE(vscbuf);
|
||||
|
||||
SAFE_RELEASE(SimpleVertexShader);
|
||||
@@ -238,271 +165,5 @@ void VertexShaderCache::Shutdown()
|
||||
|
||||
SAFE_RELEASE(SimpleLayout);
|
||||
SAFE_RELEASE(ClearLayout);
|
||||
|
||||
Clear();
|
||||
g_vs_disk_cache.Sync();
|
||||
g_vs_disk_cache.Close();
|
||||
g_uber_vs_disk_cache.Sync();
|
||||
g_uber_vs_disk_cache.Close();
|
||||
}
|
||||
|
||||
bool VertexShaderCache::SetShader(D3DVertexFormat* vertex_format)
|
||||
{
|
||||
if (g_ActiveConfig.bDisableSpecializedShaders)
|
||||
return SetUberShader(vertex_format);
|
||||
|
||||
VertexShaderUid uid = GetVertexShaderUid();
|
||||
if (last_entry && uid == last_uid)
|
||||
{
|
||||
if (last_entry->pending)
|
||||
return SetUberShader(vertex_format);
|
||||
|
||||
if (!last_entry->shader)
|
||||
return false;
|
||||
|
||||
D3D::stateman->SetInputLayout(vertex_format->GetInputLayout(last_entry->bytecode));
|
||||
D3D::stateman->SetVertexShader(last_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto iter = vshaders.find(uid);
|
||||
if (iter != vshaders.end())
|
||||
{
|
||||
const VSCacheEntry& entry = iter->second;
|
||||
if (entry.pending)
|
||||
return SetUberShader(vertex_format);
|
||||
|
||||
last_uid = uid;
|
||||
last_entry = &entry;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||
if (!last_entry->shader)
|
||||
return false;
|
||||
|
||||
D3D::stateman->SetInputLayout(vertex_format->GetInputLayout(last_entry->bytecode));
|
||||
D3D::stateman->SetVertexShader(last_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Background compiling?
|
||||
if (g_ActiveConfig.CanBackgroundCompileShaders())
|
||||
{
|
||||
// Create a pending entry
|
||||
VSCacheEntry entry;
|
||||
entry.pending = true;
|
||||
vshaders[uid] = entry;
|
||||
|
||||
// Queue normal shader compiling and use ubershader
|
||||
g_async_compiler->QueueWorkItem(
|
||||
g_async_compiler->CreateWorkItem<VertexShaderCompilerWorkItem>(uid));
|
||||
return SetUberShader(vertex_format);
|
||||
}
|
||||
|
||||
// Need to compile a new shader
|
||||
D3DBlob* bytecode = nullptr;
|
||||
ShaderCode code =
|
||||
GenerateVertexShaderCode(APIType::D3D, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
D3D::CompileVertexShader(code.GetBuffer(), &bytecode);
|
||||
if (!InsertByteCode(uid, bytecode))
|
||||
{
|
||||
SAFE_RELEASE(bytecode);
|
||||
return false;
|
||||
}
|
||||
|
||||
g_vs_disk_cache.Append(uid, bytecode->Data(), bytecode->Size());
|
||||
bytecode->Release();
|
||||
return SetShader(vertex_format);
|
||||
}
|
||||
|
||||
bool VertexShaderCache::SetUberShader(D3DVertexFormat* vertex_format)
|
||||
{
|
||||
D3DVertexFormat* uber_vertex_format = static_cast<D3DVertexFormat*>(
|
||||
VertexLoaderManager::GetUberVertexFormat(vertex_format->GetVertexDeclaration()));
|
||||
UberShader::VertexShaderUid uid = UberShader::GetVertexShaderUid();
|
||||
if (last_uber_entry && last_uber_uid == uid)
|
||||
{
|
||||
if (!last_uber_entry->shader)
|
||||
return false;
|
||||
|
||||
D3D::stateman->SetInputLayout(uber_vertex_format->GetInputLayout(last_uber_entry->bytecode));
|
||||
D3D::stateman->SetVertexShader(last_uber_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto iter = ubervshaders.find(uid);
|
||||
if (iter != ubervshaders.end())
|
||||
{
|
||||
const VSCacheEntry& entry = iter->second;
|
||||
last_uber_uid = uid;
|
||||
last_uber_entry = &entry;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||
if (!last_uber_entry->shader)
|
||||
return false;
|
||||
|
||||
D3D::stateman->SetInputLayout(uber_vertex_format->GetInputLayout(last_uber_entry->bytecode));
|
||||
D3D::stateman->SetVertexShader(last_uber_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Need to compile a new shader
|
||||
D3DBlob* bytecode = nullptr;
|
||||
ShaderCode code =
|
||||
UberShader::GenVertexShader(APIType::D3D, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
D3D::CompileVertexShader(code.GetBuffer(), &bytecode);
|
||||
if (!InsertByteCode(uid, bytecode))
|
||||
{
|
||||
SAFE_RELEASE(bytecode);
|
||||
return false;
|
||||
}
|
||||
|
||||
g_uber_vs_disk_cache.Append(uid, bytecode->Data(), bytecode->Size());
|
||||
bytecode->Release();
|
||||
return SetUberShader(vertex_format);
|
||||
}
|
||||
|
||||
bool VertexShaderCache::InsertByteCode(const VertexShaderUid& uid, D3DBlob* blob)
|
||||
{
|
||||
ID3D11VertexShader* shader =
|
||||
blob ? D3D::CreateVertexShaderFromByteCode(blob->Data(), blob->Size()) : nullptr;
|
||||
bool result = InsertShader(uid, shader, blob);
|
||||
SAFE_RELEASE(shader);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool VertexShaderCache::InsertByteCode(const UberShader::VertexShaderUid& uid, D3DBlob* blob)
|
||||
{
|
||||
ID3D11VertexShader* shader =
|
||||
blob ? D3D::CreateVertexShaderFromByteCode(blob->Data(), blob->Size()) : nullptr;
|
||||
bool result = InsertShader(uid, shader, blob);
|
||||
SAFE_RELEASE(shader);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool VertexShaderCache::InsertShader(const VertexShaderUid& uid, ID3D11VertexShader* shader,
|
||||
D3DBlob* blob)
|
||||
{
|
||||
auto iter = vshaders.find(uid);
|
||||
if (iter != vshaders.end() && !iter->second.pending)
|
||||
return false;
|
||||
|
||||
VSCacheEntry& newentry = vshaders[uid];
|
||||
newentry.pending = false;
|
||||
if (!shader || !blob)
|
||||
return false;
|
||||
|
||||
shader->AddRef();
|
||||
newentry.SetByteCode(blob);
|
||||
newentry.shader = shader;
|
||||
|
||||
INCSTAT(stats.numPixelShadersCreated);
|
||||
SETSTAT(stats.numPixelShadersAlive, static_cast<int>(vshaders.size()));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VertexShaderCache::InsertShader(const UberShader::VertexShaderUid& uid,
|
||||
ID3D11VertexShader* shader, D3DBlob* blob)
|
||||
{
|
||||
auto iter = ubervshaders.find(uid);
|
||||
if (iter != ubervshaders.end() && !iter->second.pending)
|
||||
return false;
|
||||
|
||||
VSCacheEntry& newentry = ubervshaders[uid];
|
||||
newentry.pending = false;
|
||||
if (!shader || !blob)
|
||||
return false;
|
||||
|
||||
shader->AddRef();
|
||||
newentry.SetByteCode(blob);
|
||||
newentry.shader = shader;
|
||||
return true;
|
||||
}
|
||||
|
||||
void VertexShaderCache::RetreiveAsyncShaders()
|
||||
{
|
||||
g_async_compiler->RetrieveWorkItems();
|
||||
}
|
||||
|
||||
void VertexShaderCache::QueueUberShaderCompiles()
|
||||
{
|
||||
UberShader::EnumerateVertexShaderUids([&](const UberShader::VertexShaderUid& uid) {
|
||||
if (ubervshaders.find(uid) != ubervshaders.end())
|
||||
return;
|
||||
|
||||
g_async_compiler->QueueWorkItem(
|
||||
g_async_compiler->CreateWorkItem<UberVertexShaderCompilerWorkItem>(uid));
|
||||
});
|
||||
}
|
||||
|
||||
void VertexShaderCache::WaitForBackgroundCompilesToComplete()
|
||||
{
|
||||
g_async_compiler->WaitUntilCompletion([](size_t completed, size_t total) {
|
||||
Host_UpdateProgressDialog(GetStringT("Compiling shaders...").c_str(),
|
||||
static_cast<int>(completed), static_cast<int>(total));
|
||||
});
|
||||
g_async_compiler->RetrieveWorkItems();
|
||||
Host_UpdateProgressDialog("", -1, -1);
|
||||
|
||||
// Switch from precompile -> runtime compiler threads.
|
||||
g_async_compiler->ResizeWorkerThreads(g_ActiveConfig.GetShaderCompilerThreads());
|
||||
}
|
||||
|
||||
VertexShaderCache::VertexShaderCompilerWorkItem::VertexShaderCompilerWorkItem(
|
||||
const VertexShaderUid& uid)
|
||||
{
|
||||
std::memcpy(&m_uid, &uid, sizeof(uid));
|
||||
}
|
||||
|
||||
VertexShaderCache::VertexShaderCompilerWorkItem::~VertexShaderCompilerWorkItem()
|
||||
{
|
||||
SAFE_RELEASE(m_bytecode);
|
||||
SAFE_RELEASE(m_vs);
|
||||
}
|
||||
|
||||
bool VertexShaderCache::VertexShaderCompilerWorkItem::Compile()
|
||||
{
|
||||
ShaderCode code =
|
||||
GenerateVertexShaderCode(APIType::D3D, ShaderHostConfig::GetCurrent(), m_uid.GetUidData());
|
||||
|
||||
if (D3D::CompileVertexShader(code.GetBuffer(), &m_bytecode))
|
||||
m_vs = D3D::CreateVertexShaderFromByteCode(m_bytecode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VertexShaderCache::VertexShaderCompilerWorkItem::Retrieve()
|
||||
{
|
||||
if (InsertShader(m_uid, m_vs, m_bytecode))
|
||||
g_vs_disk_cache.Append(m_uid, m_bytecode->Data(), m_bytecode->Size());
|
||||
}
|
||||
|
||||
VertexShaderCache::UberVertexShaderCompilerWorkItem::UberVertexShaderCompilerWorkItem(
|
||||
const UberShader::VertexShaderUid& uid)
|
||||
{
|
||||
std::memcpy(&m_uid, &uid, sizeof(uid));
|
||||
}
|
||||
|
||||
VertexShaderCache::UberVertexShaderCompilerWorkItem::~UberVertexShaderCompilerWorkItem()
|
||||
{
|
||||
SAFE_RELEASE(m_bytecode);
|
||||
SAFE_RELEASE(m_vs);
|
||||
}
|
||||
|
||||
bool VertexShaderCache::UberVertexShaderCompilerWorkItem::Compile()
|
||||
{
|
||||
ShaderCode code =
|
||||
UberShader::GenVertexShader(APIType::D3D, ShaderHostConfig::GetCurrent(), m_uid.GetUidData());
|
||||
|
||||
if (D3D::CompileVertexShader(code.GetBuffer(), &m_bytecode))
|
||||
m_vs = D3D::CreateVertexShaderFromByteCode(m_bytecode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VertexShaderCache::UberVertexShaderCompilerWorkItem::Retrieve()
|
||||
{
|
||||
if (InsertShader(m_uid, m_vs, m_bytecode))
|
||||
g_uber_vs_disk_cache.Append(m_uid, m_bytecode->Data(), m_bytecode->Size());
|
||||
}
|
||||
|
||||
} // namespace DX11
|
||||
|
||||
@@ -21,14 +21,7 @@ class VertexShaderCache
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Reload();
|
||||
static void Clear();
|
||||
static void Shutdown();
|
||||
static bool SetShader(D3DVertexFormat* vertex_format);
|
||||
static bool SetUberShader(D3DVertexFormat* vertex_format);
|
||||
static void RetreiveAsyncShaders();
|
||||
static void QueueUberShaderCompiles();
|
||||
static void WaitForBackgroundCompilesToComplete();
|
||||
|
||||
static ID3D11Buffer*& GetConstantBuffer();
|
||||
|
||||
@@ -36,76 +29,6 @@ public:
|
||||
static ID3D11VertexShader* GetClearVertexShader();
|
||||
static ID3D11InputLayout* GetSimpleInputLayout();
|
||||
static ID3D11InputLayout* GetClearInputLayout();
|
||||
|
||||
static bool InsertByteCode(const VertexShaderUid& uid, D3DBlob* blob);
|
||||
static bool InsertByteCode(const UberShader::VertexShaderUid& uid, D3DBlob* blob);
|
||||
static bool InsertShader(const VertexShaderUid& uid, ID3D11VertexShader* shader, D3DBlob* blob);
|
||||
static bool InsertShader(const UberShader::VertexShaderUid& uid, ID3D11VertexShader* shader,
|
||||
D3DBlob* blob);
|
||||
|
||||
private:
|
||||
struct VSCacheEntry
|
||||
{
|
||||
ID3D11VertexShader* shader;
|
||||
D3DBlob* bytecode; // needed to initialize the input layout
|
||||
bool pending;
|
||||
|
||||
VSCacheEntry() : shader(nullptr), bytecode(nullptr), pending(false) {}
|
||||
void SetByteCode(D3DBlob* blob)
|
||||
{
|
||||
SAFE_RELEASE(bytecode);
|
||||
bytecode = blob;
|
||||
blob->AddRef();
|
||||
}
|
||||
void Destroy()
|
||||
{
|
||||
SAFE_RELEASE(shader);
|
||||
SAFE_RELEASE(bytecode);
|
||||
}
|
||||
};
|
||||
|
||||
class VertexShaderCompilerWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
|
||||
{
|
||||
public:
|
||||
explicit VertexShaderCompilerWorkItem(const VertexShaderUid& uid);
|
||||
~VertexShaderCompilerWorkItem() override;
|
||||
|
||||
bool Compile() override;
|
||||
void Retrieve() override;
|
||||
|
||||
private:
|
||||
VertexShaderUid m_uid;
|
||||
D3DBlob* m_bytecode = nullptr;
|
||||
ID3D11VertexShader* m_vs = nullptr;
|
||||
};
|
||||
|
||||
class UberVertexShaderCompilerWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
|
||||
{
|
||||
public:
|
||||
explicit UberVertexShaderCompilerWorkItem(const UberShader::VertexShaderUid& uid);
|
||||
~UberVertexShaderCompilerWorkItem() override;
|
||||
|
||||
bool Compile() override;
|
||||
void Retrieve() override;
|
||||
|
||||
private:
|
||||
UberShader::VertexShaderUid m_uid;
|
||||
D3DBlob* m_bytecode = nullptr;
|
||||
ID3D11VertexShader* m_vs = nullptr;
|
||||
};
|
||||
|
||||
typedef std::map<VertexShaderUid, VSCacheEntry> VSCache;
|
||||
typedef std::map<UberShader::VertexShaderUid, VSCacheEntry> UberVSCache;
|
||||
|
||||
static void LoadShaderCache();
|
||||
static void SetInputLayout();
|
||||
|
||||
static VSCache vshaders;
|
||||
static UberVSCache ubervshaders;
|
||||
static const VSCacheEntry* last_entry;
|
||||
static const VSCacheEntry* last_uber_entry;
|
||||
static VertexShaderUid last_uid;
|
||||
static UberShader::VertexShaderUid last_uber_uid;
|
||||
};
|
||||
|
||||
} // namespace DX11
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "VideoBackends/D3D/VertexShaderCache.h"
|
||||
#include "VideoBackends/D3D/VideoBackend.h"
|
||||
|
||||
#include "VideoCommon/ShaderCache.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
||||
@@ -148,6 +149,7 @@ bool VideoBackend::Initialize(void* window_handle)
|
||||
|
||||
// internal interfaces
|
||||
g_renderer = std::make_unique<Renderer>(backbuffer_width, backbuffer_height);
|
||||
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
|
||||
g_texture_cache = std::make_unique<TextureCache>();
|
||||
g_vertex_manager = std::make_unique<VertexManager>();
|
||||
g_perf_query = std::make_unique<PerfQuery>();
|
||||
@@ -155,7 +157,9 @@ bool VideoBackend::Initialize(void* window_handle)
|
||||
VertexShaderCache::Init();
|
||||
PixelShaderCache::Init();
|
||||
GeometryShaderCache::Init();
|
||||
VertexShaderCache::WaitForBackgroundCompilesToComplete();
|
||||
if (!g_shader_cache->Initialize())
|
||||
return false;
|
||||
|
||||
D3D::InitUtils();
|
||||
BBox::Init();
|
||||
return true;
|
||||
@@ -163,6 +167,7 @@ bool VideoBackend::Initialize(void* window_handle)
|
||||
|
||||
void VideoBackend::Shutdown()
|
||||
{
|
||||
g_shader_cache->Shutdown();
|
||||
g_renderer->Shutdown();
|
||||
|
||||
D3D::ShutdownUtils();
|
||||
@@ -174,6 +179,7 @@ void VideoBackend::Shutdown()
|
||||
g_perf_query.reset();
|
||||
g_vertex_manager.reset();
|
||||
g_texture_cache.reset();
|
||||
g_shader_cache.reset();
|
||||
g_renderer.reset();
|
||||
|
||||
ShutdownShared();
|
||||
|
||||
@@ -3,7 +3,6 @@ set(SRCS
|
||||
NullTexture.cpp
|
||||
Render.cpp
|
||||
VertexManager.cpp
|
||||
ShaderCache.cpp
|
||||
)
|
||||
|
||||
set(LIBS
|
||||
|
||||
@@ -39,14 +39,12 @@
|
||||
<ClCompile Include="NullBackend.cpp" />
|
||||
<ClCompile Include="NullTexture.cpp" />
|
||||
<ClCompile Include="Render.cpp" />
|
||||
<ClCompile Include="ShaderCache.cpp" />
|
||||
<ClCompile Include="VertexManager.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="NullTexture.h" />
|
||||
<ClInclude Include="PerfQuery.h" />
|
||||
<ClInclude Include="Render.h" />
|
||||
<ClInclude Include="ShaderCache.h" />
|
||||
<ClInclude Include="TextureCache.h" />
|
||||
<ClInclude Include="VertexManager.h" />
|
||||
<ClInclude Include="VideoBackend.h" />
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "VideoBackends/Null/PerfQuery.h"
|
||||
#include "VideoBackends/Null/Render.h"
|
||||
#include "VideoBackends/Null/ShaderCache.h"
|
||||
#include "VideoBackends/Null/TextureCache.h"
|
||||
#include "VideoBackends/Null/VertexManager.h"
|
||||
#include "VideoBackends/Null/VideoBackend.h"
|
||||
@@ -63,21 +62,15 @@ bool VideoBackend::Initialize(void* window_handle)
|
||||
g_perf_query = std::make_unique<PerfQuery>();
|
||||
g_framebuffer_manager = std::make_unique<FramebufferManagerBase>();
|
||||
g_texture_cache = std::make_unique<TextureCache>();
|
||||
|
||||
VertexShaderCache::s_instance = std::make_unique<VertexShaderCache>();
|
||||
GeometryShaderCache::s_instance = std::make_unique<GeometryShaderCache>();
|
||||
PixelShaderCache::s_instance = std::make_unique<PixelShaderCache>();
|
||||
return true;
|
||||
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
|
||||
return g_shader_cache->Initialize();
|
||||
}
|
||||
|
||||
void VideoBackend::Shutdown()
|
||||
{
|
||||
g_shader_cache->Shutdown();
|
||||
g_renderer->Shutdown();
|
||||
|
||||
PixelShaderCache::s_instance.reset();
|
||||
VertexShaderCache::s_instance.reset();
|
||||
GeometryShaderCache::s_instance.reset();
|
||||
|
||||
g_texture_cache.reset();
|
||||
g_perf_query.reset();
|
||||
g_vertex_manager.reset();
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
// Copyright 2015 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "VideoBackends/Null/ShaderCache.h"
|
||||
|
||||
#include "VideoCommon/Debugger.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
|
||||
namespace Null
|
||||
{
|
||||
template <typename Uid>
|
||||
ShaderCache<Uid>::ShaderCache()
|
||||
{
|
||||
Clear();
|
||||
|
||||
SETSTAT(stats.numPixelShadersCreated, 0);
|
||||
SETSTAT(stats.numPixelShadersAlive, 0);
|
||||
}
|
||||
|
||||
template <typename Uid>
|
||||
ShaderCache<Uid>::~ShaderCache()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
template <typename Uid>
|
||||
void ShaderCache<Uid>::Clear()
|
||||
{
|
||||
m_shaders.clear();
|
||||
m_last_entry = nullptr;
|
||||
}
|
||||
|
||||
template <typename Uid>
|
||||
bool ShaderCache<Uid>::SetShader(PrimitiveType primitive_type)
|
||||
{
|
||||
Uid uid = GetUid(primitive_type, APIType::OpenGL);
|
||||
|
||||
// Check if the shader is already set
|
||||
if (m_last_entry)
|
||||
{
|
||||
if (uid == m_last_uid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
m_last_uid = uid;
|
||||
|
||||
// Check if the shader is already in the cache
|
||||
auto iter = m_shaders.find(uid);
|
||||
if (iter != m_shaders.end())
|
||||
{
|
||||
const std::string& entry = iter->second;
|
||||
m_last_entry = &entry;
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Need to compile a new shader
|
||||
ShaderCode code = GenerateCode(APIType::OpenGL, uid);
|
||||
m_shaders.emplace(uid, code.GetBuffer());
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
template class ShaderCache<VertexShaderUid>;
|
||||
template class ShaderCache<GeometryShaderUid>;
|
||||
template class ShaderCache<PixelShaderUid>;
|
||||
|
||||
std::unique_ptr<VertexShaderCache> VertexShaderCache::s_instance;
|
||||
std::unique_ptr<GeometryShaderCache> GeometryShaderCache::s_instance;
|
||||
std::unique_ptr<PixelShaderCache> PixelShaderCache::s_instance;
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
// Copyright 2015 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "VideoCommon/GeometryShaderGen.h"
|
||||
#include "VideoCommon/PixelShaderGen.h"
|
||||
#include "VideoCommon/VertexShaderGen.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
|
||||
namespace Null
|
||||
{
|
||||
template <typename Uid>
|
||||
class ShaderCache
|
||||
{
|
||||
public:
|
||||
ShaderCache();
|
||||
virtual ~ShaderCache();
|
||||
|
||||
void Clear();
|
||||
bool SetShader(PrimitiveType primitive_type);
|
||||
|
||||
protected:
|
||||
virtual Uid GetUid(PrimitiveType primitive_type, APIType api_type) = 0;
|
||||
virtual ShaderCode GenerateCode(APIType api_type, Uid uid) = 0;
|
||||
|
||||
private:
|
||||
std::map<Uid, std::string> m_shaders;
|
||||
const std::string* m_last_entry = nullptr;
|
||||
Uid m_last_uid;
|
||||
};
|
||||
|
||||
class VertexShaderCache : public ShaderCache<VertexShaderUid>
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<VertexShaderCache> s_instance;
|
||||
|
||||
protected:
|
||||
VertexShaderUid GetUid(PrimitiveType primitive_type, APIType api_type) override
|
||||
{
|
||||
return GetVertexShaderUid();
|
||||
}
|
||||
ShaderCode GenerateCode(APIType api_type, VertexShaderUid uid) override
|
||||
{
|
||||
return GenerateVertexShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
}
|
||||
};
|
||||
|
||||
class GeometryShaderCache : public ShaderCache<GeometryShaderUid>
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<GeometryShaderCache> s_instance;
|
||||
|
||||
protected:
|
||||
GeometryShaderUid GetUid(PrimitiveType primitive_type, APIType api_type) override
|
||||
{
|
||||
return GetGeometryShaderUid(primitive_type);
|
||||
}
|
||||
ShaderCode GenerateCode(APIType api_type, GeometryShaderUid uid) override
|
||||
{
|
||||
return GenerateGeometryShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
}
|
||||
};
|
||||
|
||||
class PixelShaderCache : public ShaderCache<PixelShaderUid>
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<PixelShaderCache> s_instance;
|
||||
|
||||
protected:
|
||||
PixelShaderUid GetUid(PrimitiveType primitive_type, APIType api_type) override
|
||||
{
|
||||
return GetPixelShaderUid();
|
||||
}
|
||||
ShaderCode GenerateCode(APIType api_type, PixelShaderUid uid) override
|
||||
{
|
||||
return GeneratePixelShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace NULL
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "VideoBackends/Null/VertexManager.h"
|
||||
|
||||
#include "VideoBackends/Null/ShaderCache.h"
|
||||
|
||||
#include "VideoCommon/IndexGenerator.h"
|
||||
#include "VideoCommon/NativeVertexFormat.h"
|
||||
#include "VideoCommon/VertexLoaderManager.h"
|
||||
@@ -41,9 +39,6 @@ void VertexManager::ResetBuffer(u32 stride)
|
||||
|
||||
void VertexManager::vFlush()
|
||||
{
|
||||
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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,16 +11,6 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Common/GL/GLUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
|
||||
#include "VideoCommon/AsyncShaderCompiler.h"
|
||||
#include "VideoCommon/GeometryShaderGen.h"
|
||||
#include "VideoCommon/PixelShaderGen.h"
|
||||
#include "VideoCommon/UberShaderPixel.h"
|
||||
#include "VideoCommon/UberShaderVertex.h"
|
||||
#include "VideoCommon/VertexShaderGen.h"
|
||||
|
||||
class cInterfaceBase;
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
@@ -28,41 +18,6 @@ class OGLShader;
|
||||
class GLVertexFormat;
|
||||
class StreamBuffer;
|
||||
|
||||
class SHADERUID
|
||||
{
|
||||
public:
|
||||
VertexShaderUid vuid;
|
||||
PixelShaderUid puid;
|
||||
GeometryShaderUid guid;
|
||||
|
||||
bool operator<(const SHADERUID& r) const
|
||||
{
|
||||
return std::tie(vuid, puid, guid) < std::tie(r.vuid, r.puid, r.guid);
|
||||
}
|
||||
|
||||
bool operator==(const SHADERUID& r) const
|
||||
{
|
||||
return std::tie(vuid, puid, guid) == std::tie(r.vuid, r.puid, r.guid);
|
||||
}
|
||||
};
|
||||
class UBERSHADERUID
|
||||
{
|
||||
public:
|
||||
UberShader::VertexShaderUid vuid;
|
||||
UberShader::PixelShaderUid puid;
|
||||
GeometryShaderUid guid;
|
||||
|
||||
bool operator<(const UBERSHADERUID& r) const
|
||||
{
|
||||
return std::tie(vuid, puid, guid) < std::tie(r.vuid, r.puid, r.guid);
|
||||
}
|
||||
|
||||
bool operator==(const UBERSHADERUID& r) const
|
||||
{
|
||||
return std::tie(vuid, puid, guid) == std::tie(r.vuid, r.puid, r.guid);
|
||||
}
|
||||
};
|
||||
|
||||
struct SHADER
|
||||
{
|
||||
void Destroy()
|
||||
@@ -112,18 +67,6 @@ struct PipelineProgram
|
||||
class ProgramShaderCache
|
||||
{
|
||||
public:
|
||||
struct PCacheEntry
|
||||
{
|
||||
SHADER shader;
|
||||
bool in_cache;
|
||||
bool pending;
|
||||
|
||||
void Destroy() { shader.Destroy(); }
|
||||
};
|
||||
|
||||
static PCacheEntry GetShaderProgram();
|
||||
static SHADER* SetShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format);
|
||||
static SHADER* SetUberShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format);
|
||||
static void BindVertexFormat(const GLVertexFormat* vertex_format);
|
||||
static void InvalidateVertexFormat();
|
||||
static void InvalidateLastProgram();
|
||||
@@ -141,11 +84,8 @@ public:
|
||||
static void UploadConstants();
|
||||
|
||||
static void Init();
|
||||
static void Reload();
|
||||
static void Shutdown();
|
||||
static void CreateHeader();
|
||||
static void RetrieveAsyncShaders();
|
||||
static void PrecompileUberShaders();
|
||||
|
||||
static const PipelineProgram* GetPipelineProgram(const OGLShader* vertex_shader,
|
||||
const OGLShader* geometry_shader,
|
||||
@@ -153,103 +93,15 @@ public:
|
||||
static void ReleasePipelineProgram(const PipelineProgram* prog);
|
||||
|
||||
private:
|
||||
template <typename UIDType>
|
||||
class ProgramShaderCacheInserter : public LinearDiskCacheReader<UIDType, u8>
|
||||
{
|
||||
public:
|
||||
ProgramShaderCacheInserter(std::map<UIDType, PCacheEntry>& shader_map)
|
||||
: m_shader_map(shader_map)
|
||||
{
|
||||
}
|
||||
|
||||
void Read(const UIDType& key, const u8* value, u32 value_size) override
|
||||
{
|
||||
if (m_shader_map.find(key) != m_shader_map.end())
|
||||
return;
|
||||
|
||||
PCacheEntry& entry = m_shader_map[key];
|
||||
if (!CreateCacheEntryFromBinary(&entry, value, value_size))
|
||||
{
|
||||
m_shader_map.erase(key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<UIDType, PCacheEntry>& m_shader_map;
|
||||
};
|
||||
|
||||
class SharedContextAsyncShaderCompiler : public VideoCommon::AsyncShaderCompiler
|
||||
{
|
||||
protected:
|
||||
bool WorkerThreadInitMainThread(void** param) override;
|
||||
bool WorkerThreadInitWorkerThread(void* param) override;
|
||||
void WorkerThreadExit(void* param) override;
|
||||
};
|
||||
|
||||
struct SharedContextData
|
||||
{
|
||||
std::unique_ptr<cInterfaceBase> context;
|
||||
GLuint prerender_FBO;
|
||||
GLuint prerender_FBO_tex;
|
||||
GLuint prerender_FBO_depth;
|
||||
GLuint prerender_VBO;
|
||||
GLuint prerender_VAO;
|
||||
GLuint prerender_IBO;
|
||||
};
|
||||
|
||||
class ShaderCompileWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
|
||||
{
|
||||
public:
|
||||
explicit ShaderCompileWorkItem(const SHADERUID& uid);
|
||||
|
||||
bool Compile() override;
|
||||
void Retrieve() override;
|
||||
|
||||
private:
|
||||
SHADERUID m_uid;
|
||||
SHADER m_program;
|
||||
};
|
||||
|
||||
class UberShaderCompileWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
|
||||
{
|
||||
public:
|
||||
explicit UberShaderCompileWorkItem(const UBERSHADERUID& uid);
|
||||
|
||||
bool Compile() override;
|
||||
void Retrieve() override;
|
||||
|
||||
private:
|
||||
UBERSHADERUID m_uid;
|
||||
SHADER m_program;
|
||||
};
|
||||
|
||||
typedef std::map<SHADERUID, PCacheEntry> PCache;
|
||||
typedef std::map<UBERSHADERUID, PCacheEntry> UberPCache;
|
||||
typedef std::unordered_map<PipelineProgramKey, std::unique_ptr<PipelineProgram>,
|
||||
PipelineProgramKeyHash>
|
||||
PipelineProgramMap;
|
||||
|
||||
static void CreateAttributelessVAO();
|
||||
static GLuint CreateProgramFromBinary(const u8* value, u32 value_size);
|
||||
static bool CreateCacheEntryFromBinary(PCacheEntry* entry, const u8* value, u32 value_size);
|
||||
static void LoadProgramBinaries();
|
||||
static void SaveProgramBinaries();
|
||||
static void DestroyShaders();
|
||||
static void CreatePrerenderArrays(SharedContextData* data);
|
||||
static void DestroyPrerenderArrays(SharedContextData* data);
|
||||
static void DrawPrerenderArray(const SHADER& shader, PrimitiveType primitive_type);
|
||||
|
||||
static PCache pshaders;
|
||||
static UberPCache ubershaders;
|
||||
static PipelineProgramMap pipelineprograms;
|
||||
static std::mutex pipelineprogramlock;
|
||||
static PCacheEntry* last_entry;
|
||||
static PCacheEntry* last_uber_entry;
|
||||
static SHADERUID last_uid;
|
||||
static UBERSHADERUID last_uber_uid;
|
||||
|
||||
static std::unique_ptr<SharedContextAsyncShaderCompiler> s_async_compiler;
|
||||
static u32 s_ubo_buffer_size;
|
||||
static s32 s_ubo_align;
|
||||
|
||||
|
||||
@@ -1465,7 +1465,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
|
||||
|
||||
// Clean out old stuff from caches. It's not worth it to clean out the shader caches.
|
||||
g_texture_cache->Cleanup(frameCount);
|
||||
ProgramShaderCache::RetrieveAsyncShaders();
|
||||
|
||||
RestoreAPIState();
|
||||
|
||||
@@ -1479,8 +1478,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
|
||||
g_sampler_cache->Clear();
|
||||
|
||||
// Invalidate shader cache when the host config changes.
|
||||
if (CheckForHostConfigChanges())
|
||||
ProgramShaderCache::Reload();
|
||||
CheckForHostConfigChanges();
|
||||
|
||||
// For testing zbuffer targets.
|
||||
// Renderer::SetZBufferRender();
|
||||
@@ -1602,21 +1600,6 @@ void Renderer::ApplyDepthState(const DepthState& state)
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::SetRasterizationState(const RasterizationState& state)
|
||||
{
|
||||
ApplyRasterizationState(state);
|
||||
}
|
||||
|
||||
void Renderer::SetDepthState(const DepthState& state)
|
||||
{
|
||||
ApplyDepthState(state);
|
||||
}
|
||||
|
||||
void Renderer::SetBlendingState(const BlendingState& state)
|
||||
{
|
||||
ApplyBlendingState(state);
|
||||
}
|
||||
|
||||
void Renderer::SetPipeline(const AbstractPipeline* pipeline)
|
||||
{
|
||||
// Not all shader changes currently go through SetPipeline, so we can't
|
||||
|
||||
@@ -105,10 +105,7 @@ public:
|
||||
void SetAndClearFramebuffer(const AbstractFramebuffer* framebuffer,
|
||||
const ClearColor& color_value = {},
|
||||
float depth_value = 0.0f) override;
|
||||
void SetBlendingState(const BlendingState& state) override;
|
||||
void SetScissorRect(const MathUtil::Rectangle<int>& rc) override;
|
||||
void SetRasterizationState(const RasterizationState& state) override;
|
||||
void SetDepthState(const DepthState& state) override;
|
||||
void SetTexture(u32 index, const AbstractTexture* texture) override;
|
||||
void SetSamplerState(u32 index, const SamplerState& state) override;
|
||||
void UnbindTexture(const AbstractTexture* texture) override;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user