2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <map>
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoBackends/D3D/D3DBlob.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2017-07-20 05:25:31 +00:00
|
|
|
#include "VideoCommon/AsyncShaderCompiler.h"
|
|
|
|
#include "VideoCommon/UberShaderVertex.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/VertexShaderGen.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
namespace DX11
|
|
|
|
{
|
2017-07-20 05:25:31 +00:00
|
|
|
class D3DVertexFormat;
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
class VertexShaderCache
|
|
|
|
{
|
|
|
|
public:
|
2016-06-24 08:43:46 +00:00
|
|
|
static void Init();
|
2017-06-24 09:29:03 +00:00
|
|
|
static void Reload();
|
2016-06-24 08:43:46 +00:00
|
|
|
static void Clear();
|
|
|
|
static void Shutdown();
|
2017-07-20 05:25:31 +00:00
|
|
|
static bool SetShader(D3DVertexFormat* vertex_format);
|
|
|
|
static bool SetUberShader(D3DVertexFormat* vertex_format);
|
|
|
|
static void RetreiveAsyncShaders();
|
2017-07-27 03:15:38 +00:00
|
|
|
static void QueueUberShaderCompiles();
|
|
|
|
static void WaitForBackgroundCompilesToComplete();
|
2011-01-24 11:57:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static ID3D11Buffer*& GetConstantBuffer();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static ID3D11VertexShader* GetSimpleVertexShader();
|
|
|
|
static ID3D11VertexShader* GetClearVertexShader();
|
|
|
|
static ID3D11InputLayout* GetSimpleInputLayout();
|
|
|
|
static ID3D11InputLayout* GetClearInputLayout();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2017-07-20 05:25:31 +00:00
|
|
|
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);
|
2010-06-13 19:50:06 +00:00
|
|
|
|
|
|
|
private:
|
2016-06-24 08:43:46 +00:00
|
|
|
struct VSCacheEntry
|
|
|
|
{
|
|
|
|
ID3D11VertexShader* shader;
|
|
|
|
D3DBlob* bytecode; // needed to initialize the input layout
|
2017-07-20 05:25:31 +00:00
|
|
|
bool pending;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2017-07-20 05:25:31 +00:00
|
|
|
VSCacheEntry() : shader(nullptr), bytecode(nullptr), pending(false) {}
|
2016-06-24 08:43:46 +00:00
|
|
|
void SetByteCode(D3DBlob* blob)
|
|
|
|
{
|
|
|
|
SAFE_RELEASE(bytecode);
|
|
|
|
bytecode = blob;
|
|
|
|
blob->AddRef();
|
|
|
|
}
|
|
|
|
void Destroy()
|
|
|
|
{
|
|
|
|
SAFE_RELEASE(shader);
|
|
|
|
SAFE_RELEASE(bytecode);
|
|
|
|
}
|
|
|
|
};
|
2017-07-20 05:25:31 +00:00
|
|
|
|
|
|
|
class VertexShaderCompilerWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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:
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
typedef std::map<VertexShaderUid, VSCacheEntry> VSCache;
|
2017-07-20 05:25:31 +00:00
|
|
|
typedef std::map<UberShader::VertexShaderUid, VSCacheEntry> UberVSCache;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2017-06-24 09:29:03 +00:00
|
|
|
static void LoadShaderCache();
|
2017-07-20 05:25:31 +00:00
|
|
|
static void SetInputLayout();
|
2017-06-24 09:29:03 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static VSCache vshaders;
|
2017-07-20 05:25:31 +00:00
|
|
|
static UberVSCache ubervshaders;
|
2016-06-24 08:43:46 +00:00
|
|
|
static const VSCacheEntry* last_entry;
|
2017-07-20 05:25:31 +00:00
|
|
|
static const VSCacheEntry* last_uber_entry;
|
2016-06-24 08:43:46 +00:00
|
|
|
static VertexShaderUid last_uid;
|
2017-07-20 05:25:31 +00:00
|
|
|
static UberShader::VertexShaderUid last_uber_uid;
|
2010-06-13 19:50:06 +00:00
|
|
|
};
|
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
} // namespace DX11
|