2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 13:50:06 -06:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2011-01-25 09:43:08 -07:00
|
|
|
#include <d3d11.h>
|
2014-02-19 04:14:09 -07:00
|
|
|
#include <map>
|
2011-01-25 09:43:08 -07:00
|
|
|
|
2017-07-19 23:25:31 -06:00
|
|
|
#include "VideoCommon/AsyncShaderCompiler.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/PixelShaderGen.h"
|
2017-07-19 23:25:31 -06:00
|
|
|
#include "VideoCommon/UberShaderPixel.h"
|
2011-09-07 18:09:44 -06:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
namespace DX11
|
|
|
|
{
|
2017-07-19 23:25:31 -06:00
|
|
|
class D3DBlob;
|
|
|
|
|
2010-06-13 13:50:06 -06:00
|
|
|
class PixelShaderCache
|
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
static void Init();
|
2017-06-24 03:29:03 -06:00
|
|
|
static void Reload();
|
2016-06-24 02:43:46 -06:00
|
|
|
static void Clear();
|
|
|
|
static void Shutdown();
|
2017-07-19 23:25:31 -06: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);
|
2017-07-26 21:15:38 -06:00
|
|
|
static void QueueUberShaderCompiles();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-07-19 23:25:31 -06:00
|
|
|
static ID3D11Buffer* GetConstantBuffer();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
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();
|
2010-11-27 04:11:05 -07:00
|
|
|
|
2010-06-13 13:50:06 -06:00
|
|
|
private:
|
2016-06-24 02:43:46 -06:00
|
|
|
struct PSCacheEntry
|
|
|
|
{
|
|
|
|
ID3D11PixelShader* shader;
|
2017-07-19 23:25:31 -06:00
|
|
|
bool pending;
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2017-07-19 23:25:31 -06:00
|
|
|
PSCacheEntry() : shader(nullptr), pending(false) {}
|
2016-06-24 02:43:46 -06:00
|
|
|
void Destroy() { SAFE_RELEASE(shader); }
|
|
|
|
};
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2017-07-19 23:25:31 -06:00
|
|
|
class PixelShaderCompilerWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
|
|
|
|
{
|
|
|
|
public:
|
2017-09-02 15:32:26 -06:00
|
|
|
explicit PixelShaderCompilerWorkItem(const PixelShaderUid& uid);
|
2017-07-19 23:25:31 -06: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:
|
2017-09-02 15:32:26 -06:00
|
|
|
explicit UberPixelShaderCompilerWorkItem(const UberShader::PixelShaderUid& uid);
|
2017-07-19 23:25:31 -06:00
|
|
|
~UberPixelShaderCompilerWorkItem() override;
|
|
|
|
|
|
|
|
bool Compile() override;
|
|
|
|
void Retrieve() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
UberShader::PixelShaderUid m_uid;
|
|
|
|
ID3D11PixelShader* m_shader = nullptr;
|
|
|
|
D3DBlob* m_bytecode = nullptr;
|
|
|
|
};
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
typedef std::map<PixelShaderUid, PSCacheEntry> PSCache;
|
2017-07-19 23:25:31 -06:00
|
|
|
typedef std::map<UberShader::PixelShaderUid, PSCacheEntry> UberPSCache;
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2017-06-24 03:29:03 -06:00
|
|
|
static void LoadShaderCache();
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
static PSCache PixelShaders;
|
2017-07-19 23:25:31 -06:00
|
|
|
static UberPSCache UberPixelShaders;
|
2016-06-24 02:43:46 -06:00
|
|
|
static const PSCacheEntry* last_entry;
|
2017-07-19 23:25:31 -06:00
|
|
|
static const PSCacheEntry* last_uber_entry;
|
2016-06-24 02:43:46 -06:00
|
|
|
static PixelShaderUid last_uid;
|
2017-07-19 23:25:31 -06:00
|
|
|
static UberShader::PixelShaderUid last_uber_uid;
|
2010-06-13 13:50:06 -06:00
|
|
|
};
|
2011-01-29 13:16:51 -07:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
} // namespace DX11
|