dolphin/Source/Core/VideoBackends/D3D/PixelShaderCache.h

100 lines
2.9 KiB
C
Raw Normal View History

// Copyright 2008 Dolphin Emulator Project
2015-05-17 23:08:10 +00:00
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <d3d11.h>
#include <map>
2017-07-20 05:25:31 +00:00
#include "VideoCommon/AsyncShaderCompiler.h"
#include "VideoCommon/PixelShaderGen.h"
2017-07-20 05:25:31 +00:00
#include "VideoCommon/UberShaderPixel.h"
2011-09-08 00:09:44 +00:00
namespace DX11
{
2017-07-20 05:25:31 +00:00
class D3DBlob;
class PixelShaderCache
{
public:
static void Init();
static void Reload();
static void Clear();
static void Shutdown();
2017-07-20 05:25:31 +00:00
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();
2017-07-20 05:25:31 +00:00
static ID3D11Buffer* GetConstantBuffer();
static ID3D11PixelShader* GetColorMatrixProgram(bool multisampled);
static ID3D11PixelShader* GetColorCopyProgram(bool multisampled);
static ID3D11PixelShader* GetDepthMatrixProgram(bool multisampled);
static ID3D11PixelShader* GetClearProgram();
static ID3D11PixelShader* GetAnaglyphProgram();
static ID3D11PixelShader* GetDepthResolveProgram();
static ID3D11PixelShader* ReinterpRGBA6ToRGB8(bool multisampled);
static ID3D11PixelShader* ReinterpRGB8ToRGBA6(bool multisampled);
static void InvalidateMSAAShaders();
private:
struct PSCacheEntry
{
ID3D11PixelShader* shader;
2017-07-20 05:25:31 +00:00
bool pending;
2017-07-20 05:25:31 +00:00
PSCacheEntry() : shader(nullptr), pending(false) {}
void Destroy() { SAFE_RELEASE(shader); }
};
2017-07-20 05:25:31 +00:00
class PixelShaderCompilerWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
{
public:
explicit PixelShaderCompilerWorkItem(const PixelShaderUid& uid);
2017-07-20 05:25:31 +00:00
~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);
2017-07-20 05:25:31 +00:00
~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;
2017-07-20 05:25:31 +00:00
typedef std::map<UberShader::PixelShaderUid, PSCacheEntry> UberPSCache;
static void LoadShaderCache();
static PSCache PixelShaders;
2017-07-20 05:25:31 +00:00
static UberPSCache UberPixelShaders;
static const PSCacheEntry* last_entry;
2017-07-20 05:25:31 +00:00
static const PSCacheEntry* last_uber_entry;
static PixelShaderUid last_uid;
2017-07-20 05:25:31 +00:00
static UberShader::PixelShaderUid last_uber_uid;
};
} // namespace DX11