mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 14:39:01 +01:00
Merge pull request #6042 from stenzek/videocommon-pipelines
VideoCommon pipelines ("Abstract Pipeline")
This commit is contained in:
commit
b66f96c617
@ -10,8 +10,6 @@
|
||||
#include "Common/Logging/Log.h"
|
||||
|
||||
std::unique_ptr<cInterfaceBase> GLInterface;
|
||||
static GLuint attributelessVAO = 0;
|
||||
static GLuint attributelessVBO = 0;
|
||||
|
||||
void InitInterface()
|
||||
{
|
||||
@ -29,7 +27,7 @@ GLuint OpenGL_CompileProgram(const std::string& vertexShader, const std::string&
|
||||
const char* shader = vertexShader.c_str();
|
||||
glShaderSource(vertexShaderID, 1, &shader, nullptr);
|
||||
glCompileShader(vertexShaderID);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
GLint Result = GL_FALSE;
|
||||
char stringBuffer[1024];
|
||||
GLsizei stringBufferUsage = 0;
|
||||
@ -56,7 +54,7 @@ GLuint OpenGL_CompileProgram(const std::string& vertexShader, const std::string&
|
||||
shader = fragmentShader.c_str();
|
||||
glShaderSource(fragmentShaderID, 1, &shader, nullptr);
|
||||
glCompileShader(fragmentShaderID);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &Result);
|
||||
glGetShaderInfoLog(fragmentShaderID, 1024, &stringBufferUsage, stringBuffer);
|
||||
|
||||
@ -80,7 +78,7 @@ GLuint OpenGL_CompileProgram(const std::string& vertexShader, const std::string&
|
||||
glAttachShader(programID, vertexShaderID);
|
||||
glAttachShader(programID, fragmentShaderID);
|
||||
glLinkProgram(programID);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
glGetProgramiv(programID, GL_LINK_STATUS, &Result);
|
||||
glGetProgramInfoLog(programID, 1024, &stringBufferUsage, stringBuffer);
|
||||
|
||||
@ -102,45 +100,3 @@ GLuint OpenGL_CompileProgram(const std::string& vertexShader, const std::string&
|
||||
|
||||
return programID;
|
||||
}
|
||||
|
||||
void OpenGL_CreateAttributelessVAO()
|
||||
{
|
||||
glGenVertexArrays(1, &attributelessVAO);
|
||||
_dbg_assert_msg_(VIDEO, attributelessVAO != 0,
|
||||
"Attributeless VAO should have been created successfully.")
|
||||
|
||||
// In a compatibility context, we require a valid, bound array buffer.
|
||||
glGenBuffers(1, &attributelessVBO);
|
||||
_dbg_assert_msg_(VIDEO, attributelessVBO != 0,
|
||||
"Attributeless VBO should have been created successfully.")
|
||||
|
||||
// Initialize the buffer with nothing. 16 floats is an arbitrary size that may work around
|
||||
// driver issues.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, attributelessVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 16, nullptr, GL_STATIC_DRAW);
|
||||
|
||||
// We must also define vertex attribute 0.
|
||||
glBindVertexArray(attributelessVAO);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
glEnableVertexAttribArray(0);
|
||||
}
|
||||
|
||||
void OpenGL_BindAttributelessVAO()
|
||||
{
|
||||
_dbg_assert_msg_(VIDEO, attributelessVAO != 0,
|
||||
"Attributeless VAO should have already been created.")
|
||||
glBindVertexArray(attributelessVAO);
|
||||
}
|
||||
|
||||
void OpenGL_DeleteAttributelessVAO()
|
||||
{
|
||||
_dbg_assert_msg_(VIDEO, attributelessVAO != 0,
|
||||
"Attributeless VAO should have already been created.") if (attributelessVAO != 0)
|
||||
{
|
||||
glDeleteVertexArrays(1, &attributelessVAO);
|
||||
glDeleteBuffers(1, &attributelessVBO);
|
||||
|
||||
attributelessVAO = 0;
|
||||
attributelessVBO = 0;
|
||||
}
|
||||
}
|
||||
|
@ -17,19 +17,3 @@ void InitInterface();
|
||||
|
||||
// Helpers
|
||||
GLuint OpenGL_CompileProgram(const std::string& vertexShader, const std::string& fragmentShader);
|
||||
|
||||
// Creates and deletes a VAO and VBO suitable for attributeless rendering.
|
||||
// Called by the Renderer.
|
||||
void OpenGL_CreateAttributelessVAO();
|
||||
void OpenGL_DeleteAttributelessVAO();
|
||||
|
||||
// Binds the VAO suitable for attributeless rendering.
|
||||
void OpenGL_BindAttributelessVAO();
|
||||
|
||||
// this should be removed in future, but as long as glsl is unstable, we should really read this
|
||||
// messages
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
#define DEBUG_GLSL 1
|
||||
#else
|
||||
#define DEBUG_GLSL 0
|
||||
#endif
|
||||
|
@ -13,6 +13,10 @@ set(SRCS
|
||||
D3DTexture.h
|
||||
D3DUtil.cpp
|
||||
D3DUtil.h
|
||||
DXPipeline.cpp
|
||||
DXPipeline.h
|
||||
DXShader.cpp
|
||||
DXShader.h
|
||||
DXTexture.cpp
|
||||
DXTexture.h
|
||||
FramebufferManager.cpp
|
||||
|
@ -43,6 +43,8 @@
|
||||
<ClCompile Include="D3DState.cpp" />
|
||||
<ClCompile Include="D3DTexture.cpp" />
|
||||
<ClCompile Include="D3DUtil.cpp" />
|
||||
<ClCompile Include="DXPipeline.cpp" />
|
||||
<ClCompile Include="DXShader.cpp" />
|
||||
<ClCompile Include="DXTexture.cpp" />
|
||||
<ClCompile Include="FramebufferManager.cpp" />
|
||||
<ClCompile Include="GeometryShaderCache.cpp" />
|
||||
@ -64,6 +66,8 @@
|
||||
<ClInclude Include="D3DState.h" />
|
||||
<ClInclude Include="D3DTexture.h" />
|
||||
<ClInclude Include="D3DUtil.h" />
|
||||
<ClInclude Include="DXPipeline.h" />
|
||||
<ClInclude Include="DXShader.h" />
|
||||
<ClInclude Include="DXTexture.h" />
|
||||
<ClInclude Include="FramebufferManager.h" />
|
||||
<ClInclude Include="GeometryShaderCache.h" />
|
||||
|
@ -64,6 +64,12 @@
|
||||
<ClCompile Include="DXTexture.cpp">
|
||||
<Filter>Render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DXShader.cpp">
|
||||
<Filter>Render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DXPipeline.cpp">
|
||||
<Filter>Render</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="D3DBase.h">
|
||||
@ -118,5 +124,11 @@
|
||||
<ClInclude Include="DXTexture.h">
|
||||
<Filter>Render</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DXShader.h">
|
||||
<Filter>Render</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DXPipeline.h">
|
||||
<Filter>Render</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -511,6 +511,16 @@ const char* PixelShaderVersionString()
|
||||
return "ps_4_0";
|
||||
}
|
||||
|
||||
const char* ComputeShaderVersionString()
|
||||
{
|
||||
if (s_featlevel == D3D_FEATURE_LEVEL_11_0)
|
||||
return "cs_5_0";
|
||||
else if (s_featlevel == D3D_FEATURE_LEVEL_10_1)
|
||||
return "cs_4_1";
|
||||
else /*if(featlevel == D3D_FEATURE_LEVEL_10_0)*/
|
||||
return "cs_4_0";
|
||||
}
|
||||
|
||||
D3DTexture2D* GetBackBuffer()
|
||||
{
|
||||
return s_backbuf;
|
||||
|
@ -69,6 +69,7 @@ D3DTexture2D* GetBackBuffer();
|
||||
const char* PixelShaderVersionString();
|
||||
const char* GeometryShaderVersionString();
|
||||
const char* VertexShaderVersionString();
|
||||
const char* ComputeShaderVersionString();
|
||||
bool BGRATexturesSupported();
|
||||
bool AllowTearingSupported();
|
||||
|
||||
|
@ -188,6 +188,66 @@ bool CompilePixelShader(const std::string& code, D3DBlob** blob, const D3D_SHADE
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
// bytecode->shader
|
||||
ID3D11ComputeShader* CreateComputeShaderFromByteCode(const void* bytecode, size_t len)
|
||||
{
|
||||
ID3D11ComputeShader* shader;
|
||||
HRESULT hr = D3D::device->CreateComputeShader(bytecode, len, nullptr, &shader);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
PanicAlert("CreateComputeShaderFromByteCode failed at %s %d\n", __FILE__, __LINE__);
|
||||
return nullptr;
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
// code->bytecode
|
||||
bool CompileComputeShader(const std::string& code, D3DBlob** blob, const D3D_SHADER_MACRO* pDefines)
|
||||
{
|
||||
ID3D10Blob* shaderBuffer = nullptr;
|
||||
ID3D10Blob* errorBuffer = nullptr;
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
UINT flags = D3D10_SHADER_DEBUG;
|
||||
#else
|
||||
UINT flags = D3D10_SHADER_OPTIMIZATION_LEVEL3;
|
||||
#endif
|
||||
HRESULT hr =
|
||||
PD3DCompile(code.c_str(), code.length(), nullptr, pDefines, nullptr, "main",
|
||||
D3D::ComputeShaderVersionString(), flags, 0, &shaderBuffer, &errorBuffer);
|
||||
|
||||
if (errorBuffer)
|
||||
{
|
||||
INFO_LOG(VIDEO, "Compute shader compiler messages:\n%s",
|
||||
(const char*)errorBuffer->GetBufferPointer());
|
||||
}
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
static int num_failures = 0;
|
||||
std::string filename = StringFromFormat("%sbad_cs_%04i.txt",
|
||||
File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
||||
std::ofstream file;
|
||||
File::OpenFStream(file, filename, std::ios_base::out);
|
||||
file << code;
|
||||
file.close();
|
||||
|
||||
PanicAlert("Failed to compile compute shader: %s\nDebug info (%s):\n%s", filename.c_str(),
|
||||
D3D::ComputeShaderVersionString(),
|
||||
reinterpret_cast<const char*>(errorBuffer->GetBufferPointer()));
|
||||
|
||||
*blob = nullptr;
|
||||
errorBuffer->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
*blob = new D3DBlob(shaderBuffer);
|
||||
shaderBuffer->Release();
|
||||
}
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
ID3D11VertexShader* CompileAndCreateVertexShader(const std::string& code)
|
||||
{
|
||||
D3DBlob* blob = nullptr;
|
||||
@ -226,6 +286,19 @@ ID3D11PixelShader* CompileAndCreatePixelShader(const std::string& code)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ID3D11ComputeShader* CompileAndCreateComputeShader(const std::string& code)
|
||||
{
|
||||
D3DBlob* blob = nullptr;
|
||||
CompileComputeShader(code, &blob);
|
||||
if (blob)
|
||||
{
|
||||
ID3D11ComputeShader* shader = CreateComputeShaderFromByteCode(blob);
|
||||
blob->Release();
|
||||
return shader;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace DX11
|
||||
|
@ -19,6 +19,7 @@ namespace D3D
|
||||
ID3D11VertexShader* CreateVertexShaderFromByteCode(const void* bytecode, size_t len);
|
||||
ID3D11GeometryShader* CreateGeometryShaderFromByteCode(const void* bytecode, size_t len);
|
||||
ID3D11PixelShader* CreatePixelShaderFromByteCode(const void* bytecode, size_t len);
|
||||
ID3D11ComputeShader* CreateComputeShaderFromByteCode(const void* bytecode, size_t len);
|
||||
|
||||
// The returned bytecode buffers should be Release()d.
|
||||
bool CompileVertexShader(const std::string& code, D3DBlob** blob);
|
||||
@ -26,12 +27,15 @@ bool CompileGeometryShader(const std::string& code, D3DBlob** blob,
|
||||
const D3D_SHADER_MACRO* pDefines = nullptr);
|
||||
bool CompilePixelShader(const std::string& code, D3DBlob** blob,
|
||||
const D3D_SHADER_MACRO* pDefines = nullptr);
|
||||
bool CompileComputeShader(const std::string& code, D3DBlob** blob,
|
||||
const D3D_SHADER_MACRO* pDefines = nullptr);
|
||||
|
||||
// Utility functions
|
||||
ID3D11VertexShader* CompileAndCreateVertexShader(const std::string& code);
|
||||
ID3D11GeometryShader* CompileAndCreateGeometryShader(const std::string& code,
|
||||
const D3D_SHADER_MACRO* pDefines = nullptr);
|
||||
ID3D11PixelShader* CompileAndCreatePixelShader(const std::string& code);
|
||||
ID3D11ComputeShader* CompileAndCreateComputeShader(const std::string& code);
|
||||
|
||||
inline ID3D11VertexShader* CreateVertexShaderFromByteCode(D3DBlob* bytecode)
|
||||
{
|
||||
@ -45,21 +49,29 @@ inline ID3D11PixelShader* CreatePixelShaderFromByteCode(D3DBlob* bytecode)
|
||||
{
|
||||
return CreatePixelShaderFromByteCode(bytecode->Data(), bytecode->Size());
|
||||
}
|
||||
inline ID3D11ComputeShader* CreateComputeShaderFromByteCode(D3DBlob* bytecode)
|
||||
{
|
||||
return CreateComputeShaderFromByteCode(bytecode->Data(), bytecode->Size());
|
||||
}
|
||||
|
||||
inline ID3D11VertexShader* CompileAndCreateVertexShader(D3DBlob* code)
|
||||
{
|
||||
return CompileAndCreateVertexShader((const char*)code->Data());
|
||||
return CompileAndCreateVertexShader(reinterpret_cast<const char*>(code->Data()));
|
||||
}
|
||||
|
||||
inline ID3D11GeometryShader*
|
||||
CompileAndCreateGeometryShader(D3DBlob* code, const D3D_SHADER_MACRO* pDefines = nullptr)
|
||||
{
|
||||
return CompileAndCreateGeometryShader((const char*)code->Data(), pDefines);
|
||||
return CompileAndCreateGeometryShader(reinterpret_cast<const char*>(code->Data()), pDefines);
|
||||
}
|
||||
|
||||
inline ID3D11PixelShader* CompileAndCreatePixelShader(D3DBlob* code)
|
||||
{
|
||||
return CompileAndCreatePixelShader((const char*)code->Data());
|
||||
return CompileAndCreatePixelShader(reinterpret_cast<const char*>(code->Data()));
|
||||
}
|
||||
inline ID3D11ComputeShader* CompileAndCreateComputeShader(D3DBlob* code)
|
||||
{
|
||||
return CompileAndCreateComputeShader(reinterpret_cast<const char*>(code->Data()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,97 +20,13 @@ namespace D3D
|
||||
{
|
||||
StateManager* stateman;
|
||||
|
||||
template <typename T>
|
||||
AutoState<T>::AutoState(const T* object) : state(object)
|
||||
{
|
||||
((IUnknown*)state)->AddRef();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AutoState<T>::AutoState(const AutoState<T>& source)
|
||||
{
|
||||
state = source.GetPtr();
|
||||
((T*)state)->AddRef();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AutoState<T>::~AutoState()
|
||||
{
|
||||
if (state)
|
||||
((T*)state)->Release();
|
||||
state = nullptr;
|
||||
}
|
||||
|
||||
StateManager::StateManager()
|
||||
: m_currentBlendState(nullptr), m_currentDepthState(nullptr), m_currentRasterizerState(nullptr),
|
||||
m_dirtyFlags(~0u), m_pending(), m_current()
|
||||
{
|
||||
}
|
||||
|
||||
void StateManager::PushBlendState(const ID3D11BlendState* state)
|
||||
{
|
||||
m_blendStates.push(AutoBlendState(state));
|
||||
}
|
||||
void StateManager::PushDepthState(const ID3D11DepthStencilState* state)
|
||||
{
|
||||
m_depthStates.push(AutoDepthStencilState(state));
|
||||
}
|
||||
void StateManager::PushRasterizerState(const ID3D11RasterizerState* state)
|
||||
{
|
||||
m_rasterizerStates.push(AutoRasterizerState(state));
|
||||
}
|
||||
void StateManager::PopBlendState()
|
||||
{
|
||||
m_blendStates.pop();
|
||||
}
|
||||
void StateManager::PopDepthState()
|
||||
{
|
||||
m_depthStates.pop();
|
||||
}
|
||||
void StateManager::PopRasterizerState()
|
||||
{
|
||||
m_rasterizerStates.pop();
|
||||
}
|
||||
StateManager::StateManager() = default;
|
||||
StateManager::~StateManager() = default;
|
||||
|
||||
void StateManager::Apply()
|
||||
{
|
||||
if (!m_blendStates.empty())
|
||||
{
|
||||
if (m_currentBlendState != m_blendStates.top().GetPtr())
|
||||
{
|
||||
m_currentBlendState = (ID3D11BlendState*)m_blendStates.top().GetPtr();
|
||||
D3D::context->OMSetBlendState(m_currentBlendState, nullptr, 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
else
|
||||
ERROR_LOG(VIDEO, "Tried to apply without blend state!");
|
||||
|
||||
if (!m_depthStates.empty())
|
||||
{
|
||||
if (m_currentDepthState != m_depthStates.top().GetPtr())
|
||||
{
|
||||
m_currentDepthState = (ID3D11DepthStencilState*)m_depthStates.top().GetPtr();
|
||||
D3D::context->OMSetDepthStencilState(m_currentDepthState, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
ERROR_LOG(VIDEO, "Tried to apply without depth state!");
|
||||
|
||||
if (!m_rasterizerStates.empty())
|
||||
{
|
||||
if (m_currentRasterizerState != m_rasterizerStates.top().GetPtr())
|
||||
{
|
||||
m_currentRasterizerState = (ID3D11RasterizerState*)m_rasterizerStates.top().GetPtr();
|
||||
D3D::context->RSSetState(m_currentRasterizerState);
|
||||
}
|
||||
}
|
||||
else
|
||||
ERROR_LOG(VIDEO, "Tried to apply without rasterizer state!");
|
||||
|
||||
if (!m_dirtyFlags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int textureMaskShift = LeastSignificantSetBit((u32)DirtyFlag_Texture0);
|
||||
int samplerMaskShift = LeastSignificantSetBit((u32)DirtyFlag_Sampler0);
|
||||
@ -232,6 +148,22 @@ void StateManager::Apply()
|
||||
}
|
||||
}
|
||||
|
||||
if (m_dirtyFlags & DirtyFlag_BlendState)
|
||||
{
|
||||
D3D::context->OMSetBlendState(m_pending.blendState, nullptr, 0xFFFFFFFF);
|
||||
m_current.blendState = m_pending.blendState;
|
||||
}
|
||||
if (m_dirtyFlags & DirtyFlag_DepthState)
|
||||
{
|
||||
D3D::context->OMSetDepthStencilState(m_pending.depthState, 0);
|
||||
m_current.depthState = m_pending.depthState;
|
||||
}
|
||||
if (m_dirtyFlags & DirtyFlag_RasterizerState)
|
||||
{
|
||||
D3D::context->RSSetState(m_pending.rasterizerState);
|
||||
m_current.rasterizerState = m_pending.rasterizerState;
|
||||
}
|
||||
|
||||
m_dirtyFlags = 0;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Common/BitField.h"
|
||||
@ -14,10 +13,6 @@
|
||||
#include "VideoBackends/D3D/D3DBase.h"
|
||||
#include "VideoCommon/RenderState.h"
|
||||
|
||||
struct ID3D11BlendState;
|
||||
struct ID3D11DepthStencilState;
|
||||
struct ID3D11RasterizerState;
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
class StateCache
|
||||
@ -44,37 +39,35 @@ private:
|
||||
|
||||
namespace D3D
|
||||
{
|
||||
template <typename T>
|
||||
class AutoState
|
||||
{
|
||||
public:
|
||||
AutoState(const T* object);
|
||||
AutoState(const AutoState<T>& source);
|
||||
~AutoState();
|
||||
|
||||
const inline T* GetPtr() const { return state; }
|
||||
private:
|
||||
const T* state;
|
||||
};
|
||||
|
||||
typedef AutoState<ID3D11BlendState> AutoBlendState;
|
||||
typedef AutoState<ID3D11DepthStencilState> AutoDepthStencilState;
|
||||
typedef AutoState<ID3D11RasterizerState> AutoRasterizerState;
|
||||
|
||||
class StateManager
|
||||
{
|
||||
public:
|
||||
StateManager();
|
||||
~StateManager();
|
||||
|
||||
// call any of these to change the affected states
|
||||
void PushBlendState(const ID3D11BlendState* state);
|
||||
void PushDepthState(const ID3D11DepthStencilState* state);
|
||||
void PushRasterizerState(const ID3D11RasterizerState* state);
|
||||
void SetBlendState(ID3D11BlendState* state)
|
||||
{
|
||||
if (m_current.blendState != state)
|
||||
m_dirtyFlags |= DirtyFlag_BlendState;
|
||||
|
||||
// call these after drawing
|
||||
void PopBlendState();
|
||||
void PopDepthState();
|
||||
void PopRasterizerState();
|
||||
m_pending.blendState = state;
|
||||
}
|
||||
|
||||
void SetDepthState(ID3D11DepthStencilState* state)
|
||||
{
|
||||
if (m_current.depthState != state)
|
||||
m_dirtyFlags |= DirtyFlag_DepthState;
|
||||
|
||||
m_pending.depthState = state;
|
||||
}
|
||||
|
||||
void SetRasterizerState(ID3D11RasterizerState* state)
|
||||
{
|
||||
if (m_current.rasterizerState != state)
|
||||
m_dirtyFlags |= DirtyFlag_RasterizerState;
|
||||
|
||||
m_pending.rasterizerState = state;
|
||||
}
|
||||
|
||||
void SetTexture(size_t index, ID3D11ShaderResourceView* texture)
|
||||
{
|
||||
@ -117,6 +110,14 @@ public:
|
||||
m_pending.geometryConstants = buffer;
|
||||
}
|
||||
|
||||
void SetComputeConstants(ID3D11Buffer* buffer)
|
||||
{
|
||||
if (m_current.computeConstants != buffer)
|
||||
m_dirtyFlags |= DirtyFlag_ComputeConstants;
|
||||
|
||||
m_pending.computeConstants = buffer;
|
||||
}
|
||||
|
||||
void SetVertexBuffer(ID3D11Buffer* buffer, u32 stride, u32 offset)
|
||||
{
|
||||
if (m_current.vertexBuffer != buffer || m_current.vertexBufferStride != stride ||
|
||||
@ -184,6 +185,14 @@ public:
|
||||
m_pending.geometryShader = shader;
|
||||
}
|
||||
|
||||
void SetComputeShader(ID3D11ComputeShader* shader)
|
||||
{
|
||||
if (m_current.computeShader != shader)
|
||||
m_dirtyFlags |= DirtyFlag_ComputeShader;
|
||||
|
||||
m_pending.computeShader = shader;
|
||||
}
|
||||
|
||||
// removes currently set texture from all slots, returns mask of previously bound slots
|
||||
u32 UnsetTexture(ID3D11ShaderResourceView* srv);
|
||||
void SetTextureByMask(u32 textureSlotMask, ID3D11ShaderResourceView* srv);
|
||||
@ -193,14 +202,6 @@ public:
|
||||
void Apply();
|
||||
|
||||
private:
|
||||
std::stack<AutoBlendState> m_blendStates;
|
||||
std::stack<AutoDepthStencilState> m_depthStates;
|
||||
std::stack<AutoRasterizerState> m_rasterizerStates;
|
||||
|
||||
ID3D11BlendState* m_currentBlendState;
|
||||
ID3D11DepthStencilState* m_currentDepthState;
|
||||
ID3D11RasterizerState* m_currentRasterizerState;
|
||||
|
||||
enum DirtyFlags
|
||||
{
|
||||
DirtyFlag_Texture0 = 1 << 0,
|
||||
@ -224,18 +225,23 @@ private:
|
||||
DirtyFlag_PixelConstants = 1 << 16,
|
||||
DirtyFlag_VertexConstants = 1 << 17,
|
||||
DirtyFlag_GeometryConstants = 1 << 18,
|
||||
DirtyFlag_ComputeConstants = 1 << 19,
|
||||
|
||||
DirtyFlag_VertexBuffer = 1 << 19,
|
||||
DirtyFlag_IndexBuffer = 1 << 20,
|
||||
DirtyFlag_VertexBuffer = 1 << 20,
|
||||
DirtyFlag_IndexBuffer = 1 << 21,
|
||||
|
||||
DirtyFlag_PixelShader = 1 << 21,
|
||||
DirtyFlag_VertexShader = 1 << 22,
|
||||
DirtyFlag_GeometryShader = 1 << 23,
|
||||
DirtyFlag_PixelShader = 1 << 22,
|
||||
DirtyFlag_VertexShader = 1 << 23,
|
||||
DirtyFlag_GeometryShader = 1 << 24,
|
||||
DirtyFlag_ComputeShader = 1 << 25,
|
||||
|
||||
DirtyFlag_InputAssembler = 1 << 24,
|
||||
DirtyFlag_InputAssembler = 1 << 26,
|
||||
DirtyFlag_BlendState = 1 << 27,
|
||||
DirtyFlag_DepthState = 1 << 28,
|
||||
DirtyFlag_RasterizerState = 1 << 29,
|
||||
};
|
||||
|
||||
u32 m_dirtyFlags;
|
||||
u32 m_dirtyFlags = ~0u;
|
||||
|
||||
struct Resources
|
||||
{
|
||||
@ -244,6 +250,7 @@ private:
|
||||
std::array<ID3D11Buffer*, 2> pixelConstants;
|
||||
ID3D11Buffer* vertexConstants;
|
||||
ID3D11Buffer* geometryConstants;
|
||||
ID3D11Buffer* computeConstants;
|
||||
ID3D11Buffer* vertexBuffer;
|
||||
ID3D11Buffer* indexBuffer;
|
||||
u32 vertexBufferStride;
|
||||
@ -253,10 +260,14 @@ private:
|
||||
ID3D11PixelShader* pixelShader;
|
||||
ID3D11VertexShader* vertexShader;
|
||||
ID3D11GeometryShader* geometryShader;
|
||||
ID3D11ComputeShader* computeShader;
|
||||
ID3D11BlendState* blendState;
|
||||
ID3D11DepthStencilState* depthState;
|
||||
ID3D11RasterizerState* rasterizerState;
|
||||
};
|
||||
|
||||
Resources m_pending;
|
||||
Resources m_current;
|
||||
Resources m_pending = {};
|
||||
Resources m_current = {};
|
||||
};
|
||||
|
||||
extern StateManager* stateman;
|
||||
|
@ -406,8 +406,8 @@ int CD3DFont::DrawTextScaled(float x, float y, float size, float spacing, u32 dw
|
||||
pVertices = (D3D::FONT2DVERTEX*)vbmap.pData;
|
||||
|
||||
// set general pipeline state
|
||||
D3D::stateman->PushBlendState(m_blendstate);
|
||||
D3D::stateman->PushRasterizerState(m_raststate);
|
||||
D3D::stateman->SetBlendState(m_blendstate);
|
||||
D3D::stateman->SetRasterizerState(m_raststate);
|
||||
|
||||
D3D::stateman->SetPixelShader(m_pshader);
|
||||
D3D::stateman->SetVertexShader(m_vshader);
|
||||
@ -478,8 +478,6 @@ int CD3DFont::DrawTextScaled(float x, float y, float size, float spacing, u32 dw
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->Draw(3 * dwNumTriangles, 0);
|
||||
}
|
||||
D3D::stateman->PopBlendState();
|
||||
D3D::stateman->PopRasterizerState();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
96
Source/Core/VideoBackends/D3D/DXPipeline.cpp
Normal file
96
Source/Core/VideoBackends/D3D/DXPipeline.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
|
||||
#include "VideoBackends/D3D/D3DBase.h"
|
||||
#include "VideoBackends/D3D/D3DState.h"
|
||||
#include "VideoBackends/D3D/DXPipeline.h"
|
||||
#include "VideoBackends/D3D/DXShader.h"
|
||||
#include "VideoBackends/D3D/DXTexture.h"
|
||||
#include "VideoBackends/D3D/Render.h"
|
||||
#include "VideoBackends/D3D/VertexManager.h"
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
DXPipeline::DXPipeline(ID3D11InputLayout* input_layout, ID3D11VertexShader* vertex_shader,
|
||||
ID3D11GeometryShader* geometry_shader, ID3D11PixelShader* pixel_shader,
|
||||
ID3D11RasterizerState* rasterizer_state,
|
||||
ID3D11DepthStencilState* depth_state, ID3D11BlendState* blend_state,
|
||||
D3D11_PRIMITIVE_TOPOLOGY primitive_topology)
|
||||
: m_input_layout(input_layout), m_vertex_shader(vertex_shader),
|
||||
m_geometry_shader(geometry_shader), m_pixel_shader(pixel_shader),
|
||||
m_rasterizer_state(rasterizer_state), m_depth_state(depth_state), m_blend_state(blend_state),
|
||||
m_primitive_topology(primitive_topology)
|
||||
{
|
||||
if (m_input_layout)
|
||||
m_input_layout->AddRef();
|
||||
if (m_vertex_shader)
|
||||
m_vertex_shader->AddRef();
|
||||
if (m_geometry_shader)
|
||||
m_geometry_shader->AddRef();
|
||||
if (m_pixel_shader)
|
||||
m_pixel_shader->AddRef();
|
||||
if (m_rasterizer_state)
|
||||
m_rasterizer_state->AddRef();
|
||||
if (m_depth_state)
|
||||
m_depth_state->AddRef();
|
||||
if (m_blend_state)
|
||||
m_blend_state->AddRef();
|
||||
}
|
||||
|
||||
DXPipeline::~DXPipeline()
|
||||
{
|
||||
if (m_input_layout)
|
||||
m_input_layout->Release();
|
||||
if (m_vertex_shader)
|
||||
m_vertex_shader->Release();
|
||||
if (m_geometry_shader)
|
||||
m_geometry_shader->Release();
|
||||
if (m_pixel_shader)
|
||||
m_pixel_shader->Release();
|
||||
if (m_rasterizer_state)
|
||||
m_rasterizer_state->Release();
|
||||
if (m_depth_state)
|
||||
m_depth_state->Release();
|
||||
if (m_blend_state)
|
||||
m_blend_state->Release();
|
||||
}
|
||||
|
||||
std::unique_ptr<DXPipeline> DXPipeline::Create(const AbstractPipelineConfig& config)
|
||||
{
|
||||
StateCache& state_cache = static_cast<Renderer*>(g_renderer.get())->GetStateCache();
|
||||
ID3D11RasterizerState* rasterizer_state = state_cache.Get(config.rasterization_state);
|
||||
ID3D11DepthStencilState* depth_state = state_cache.Get(config.depth_state);
|
||||
ID3D11BlendState* blend_state = state_cache.Get(config.blending_state);
|
||||
D3D11_PRIMITIVE_TOPOLOGY primitive_topology =
|
||||
StateCache::GetPrimitiveTopology(config.rasterization_state.primitive);
|
||||
if (!rasterizer_state || !depth_state || !blend_state)
|
||||
{
|
||||
SAFE_RELEASE(rasterizer_state);
|
||||
SAFE_RELEASE(depth_state);
|
||||
SAFE_RELEASE(blend_state);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const DXShader* vertex_shader = static_cast<const DXShader*>(config.vertex_shader);
|
||||
const DXShader* geometry_shader = static_cast<const DXShader*>(config.geometry_shader);
|
||||
const DXShader* pixel_shader = static_cast<const DXShader*>(config.pixel_shader);
|
||||
_assert_(vertex_shader != nullptr && pixel_shader != nullptr);
|
||||
|
||||
ID3D11InputLayout* input_layout =
|
||||
const_cast<D3DVertexFormat*>(static_cast<const D3DVertexFormat*>(config.vertex_format))
|
||||
->GetInputLayout(vertex_shader->GetByteCode());
|
||||
|
||||
return std::make_unique<DXPipeline>(input_layout, vertex_shader->GetD3DVertexShader(),
|
||||
geometry_shader ? geometry_shader->GetD3DGeometryShader() :
|
||||
nullptr,
|
||||
pixel_shader->GetD3DPixelShader(), rasterizer_state,
|
||||
depth_state, blend_state, primitive_topology);
|
||||
}
|
||||
} // namespace DX11
|
43
Source/Core/VideoBackends/D3D/DXPipeline.h
Normal file
43
Source/Core/VideoBackends/D3D/DXPipeline.h
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <memory>
|
||||
#include "VideoCommon/AbstractPipeline.h"
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
class DXPipeline final : public AbstractPipeline
|
||||
{
|
||||
public:
|
||||
DXPipeline(ID3D11InputLayout* input_layout, ID3D11VertexShader* vertex_shader,
|
||||
ID3D11GeometryShader* geometry_shader, ID3D11PixelShader* pixel_shader,
|
||||
ID3D11RasterizerState* rasterizer_state, ID3D11DepthStencilState* depth_state,
|
||||
ID3D11BlendState* blend_state, D3D11_PRIMITIVE_TOPOLOGY primitive_topology);
|
||||
~DXPipeline() override;
|
||||
|
||||
ID3D11InputLayout* GetInputLayout() const { return m_input_layout; }
|
||||
ID3D11VertexShader* GetVertexShader() const { return m_vertex_shader; }
|
||||
ID3D11GeometryShader* GetGeometryShader() const { return m_geometry_shader; }
|
||||
ID3D11PixelShader* GetPixelShader() const { return m_pixel_shader; }
|
||||
ID3D11RasterizerState* GetRasterizerState() const { return m_rasterizer_state; }
|
||||
ID3D11DepthStencilState* GetDepthState() const { return m_depth_state; }
|
||||
ID3D11BlendState* GetBlendState() const { return m_blend_state; }
|
||||
D3D11_PRIMITIVE_TOPOLOGY GetPrimitiveTopology() const { return m_primitive_topology; }
|
||||
bool HasGeometryShader() const { return m_geometry_shader != nullptr; }
|
||||
static std::unique_ptr<DXPipeline> Create(const AbstractPipelineConfig& config);
|
||||
|
||||
private:
|
||||
ID3D11InputLayout* m_input_layout;
|
||||
ID3D11VertexShader* m_vertex_shader;
|
||||
ID3D11GeometryShader* m_geometry_shader;
|
||||
ID3D11PixelShader* m_pixel_shader;
|
||||
ID3D11RasterizerState* m_rasterizer_state;
|
||||
ID3D11DepthStencilState* m_depth_state;
|
||||
ID3D11BlendState* m_blend_state;
|
||||
D3D11_PRIMITIVE_TOPOLOGY m_primitive_topology;
|
||||
};
|
||||
} // namespace DX11
|
183
Source/Core/VideoBackends/D3D/DXShader.cpp
Normal file
183
Source/Core/VideoBackends/D3D/DXShader.cpp
Normal file
@ -0,0 +1,183 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Common/Assert.h"
|
||||
|
||||
#include "VideoBackends/D3D/D3DBase.h"
|
||||
#include "VideoBackends/D3D/D3DShader.h"
|
||||
#include "VideoBackends/D3D/DXShader.h"
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
DXShader::DXShader(D3DBlob* bytecode, ID3D11VertexShader* vs)
|
||||
: AbstractShader(ShaderStage::Vertex), m_bytecode(bytecode), m_shader(vs)
|
||||
{
|
||||
}
|
||||
|
||||
DXShader::DXShader(D3DBlob* bytecode, ID3D11GeometryShader* gs)
|
||||
: AbstractShader(ShaderStage::Geometry), m_bytecode(bytecode), m_shader(gs)
|
||||
{
|
||||
}
|
||||
|
||||
DXShader::DXShader(D3DBlob* bytecode, ID3D11PixelShader* ps)
|
||||
: AbstractShader(ShaderStage::Pixel), m_bytecode(bytecode), m_shader(ps)
|
||||
{
|
||||
}
|
||||
|
||||
DXShader::DXShader(D3DBlob* bytecode, ID3D11ComputeShader* cs)
|
||||
: AbstractShader(ShaderStage::Compute), m_bytecode(bytecode), m_shader(cs)
|
||||
{
|
||||
}
|
||||
|
||||
DXShader::~DXShader()
|
||||
{
|
||||
m_shader->Release();
|
||||
m_bytecode->Release();
|
||||
}
|
||||
|
||||
D3DBlob* DXShader::GetByteCode() const
|
||||
{
|
||||
return m_bytecode;
|
||||
}
|
||||
|
||||
ID3D11VertexShader* DXShader::GetD3DVertexShader() const
|
||||
{
|
||||
_dbg_assert_(VIDEO, m_stage == ShaderStage::Vertex);
|
||||
return static_cast<ID3D11VertexShader*>(m_shader);
|
||||
}
|
||||
|
||||
ID3D11GeometryShader* DXShader::GetD3DGeometryShader() const
|
||||
{
|
||||
_dbg_assert_(VIDEO, m_stage == ShaderStage::Geometry);
|
||||
return static_cast<ID3D11GeometryShader*>(m_shader);
|
||||
}
|
||||
|
||||
ID3D11PixelShader* DXShader::GetD3DPixelShader() const
|
||||
{
|
||||
_dbg_assert_(VIDEO, m_stage == ShaderStage::Pixel);
|
||||
return static_cast<ID3D11PixelShader*>(m_shader);
|
||||
}
|
||||
|
||||
ID3D11ComputeShader* DXShader::GetD3DComputeShader() const
|
||||
{
|
||||
_dbg_assert_(VIDEO, m_stage == ShaderStage::Compute);
|
||||
return static_cast<ID3D11ComputeShader*>(m_shader);
|
||||
}
|
||||
|
||||
bool DXShader::HasBinary() const
|
||||
{
|
||||
_assert_(m_bytecode);
|
||||
return true;
|
||||
}
|
||||
|
||||
AbstractShader::BinaryData DXShader::GetBinary() const
|
||||
{
|
||||
return BinaryData(m_bytecode->Data(), m_bytecode->Data() + m_bytecode->Size());
|
||||
}
|
||||
|
||||
std::unique_ptr<DXShader> DXShader::CreateFromBlob(ShaderStage stage, D3DBlob* bytecode)
|
||||
{
|
||||
switch (stage)
|
||||
{
|
||||
case ShaderStage::Vertex:
|
||||
{
|
||||
ID3D11VertexShader* vs = D3D::CreateVertexShaderFromByteCode(bytecode);
|
||||
if (vs)
|
||||
return std::make_unique<DXShader>(bytecode, vs);
|
||||
}
|
||||
break;
|
||||
|
||||
case ShaderStage::Geometry:
|
||||
{
|
||||
ID3D11GeometryShader* gs = D3D::CreateGeometryShaderFromByteCode(bytecode);
|
||||
if (gs)
|
||||
return std::make_unique<DXShader>(bytecode, gs);
|
||||
}
|
||||
break;
|
||||
|
||||
case ShaderStage::Pixel:
|
||||
{
|
||||
ID3D11PixelShader* ps = D3D::CreatePixelShaderFromByteCode(bytecode);
|
||||
if (ps)
|
||||
return std::make_unique<DXShader>(bytecode, ps);
|
||||
}
|
||||
break;
|
||||
|
||||
case ShaderStage::Compute:
|
||||
{
|
||||
ID3D11ComputeShader* cs = D3D::CreateComputeShaderFromByteCode(bytecode);
|
||||
if (cs)
|
||||
return std::make_unique<DXShader>(bytecode, cs);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<DXShader> DXShader::CreateFromSource(ShaderStage stage, const char* source,
|
||||
size_t length)
|
||||
{
|
||||
D3DBlob* bytecode;
|
||||
switch (stage)
|
||||
{
|
||||
case ShaderStage::Vertex:
|
||||
{
|
||||
if (!D3D::CompileVertexShader(std::string(source, length), &bytecode))
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case ShaderStage::Geometry:
|
||||
{
|
||||
if (!D3D::CompileGeometryShader(std::string(source, length), &bytecode))
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case ShaderStage::Pixel:
|
||||
{
|
||||
if (!D3D::CompilePixelShader(std::string(source, length), &bytecode))
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case ShaderStage::Compute:
|
||||
{
|
||||
if (!D3D::CompileComputeShader(std::string(source, length), &bytecode))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<DXShader> shader = CreateFromBlob(stage, bytecode);
|
||||
if (!shader)
|
||||
{
|
||||
bytecode->Release();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
std::unique_ptr<DXShader> DXShader::CreateFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length)
|
||||
{
|
||||
D3DBlob* bytecode = new D3DBlob(static_cast<unsigned int>(length), static_cast<const u8*>(data));
|
||||
std::unique_ptr<DXShader> shader = CreateFromBlob(stage, bytecode);
|
||||
if (!shader)
|
||||
{
|
||||
bytecode->Release();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
} // namespace DX11
|
48
Source/Core/VideoBackends/D3D/DXShader.h
Normal file
48
Source/Core/VideoBackends/D3D/DXShader.h
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <d3d11.h>
|
||||
#include <memory>
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
#include "VideoBackends/D3D/D3DBlob.h"
|
||||
#include "VideoCommon/AbstractShader.h"
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
class DXShader final : public AbstractShader
|
||||
{
|
||||
public:
|
||||
// Note: vs/gs/ps/cs references are transferred.
|
||||
DXShader(D3DBlob* bytecode, ID3D11VertexShader* vs);
|
||||
DXShader(D3DBlob* bytecode, ID3D11GeometryShader* gs);
|
||||
DXShader(D3DBlob* bytecode, ID3D11PixelShader* ps);
|
||||
DXShader(D3DBlob* bytecode, ID3D11ComputeShader* cs);
|
||||
~DXShader() override;
|
||||
|
||||
D3DBlob* GetByteCode() const;
|
||||
ID3D11VertexShader* GetD3DVertexShader() const;
|
||||
ID3D11GeometryShader* GetD3DGeometryShader() const;
|
||||
ID3D11PixelShader* GetD3DPixelShader() const;
|
||||
ID3D11ComputeShader* GetD3DComputeShader() const;
|
||||
|
||||
bool HasBinary() const override;
|
||||
BinaryData GetBinary() const override;
|
||||
|
||||
// Creates a new shader object. The reference to bytecode is not transfered upon failure.
|
||||
static std::unique_ptr<DXShader> CreateFromBlob(ShaderStage stage, D3DBlob* bytecode);
|
||||
static std::unique_ptr<DXShader> CreateFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length);
|
||||
static std::unique_ptr<DXShader> CreateFromSource(ShaderStage stage, const char* source,
|
||||
size_t length);
|
||||
|
||||
private:
|
||||
ID3D11DeviceChild* m_shader;
|
||||
D3DBlob* m_bytecode;
|
||||
};
|
||||
|
||||
} // namespace DX11
|
@ -119,10 +119,11 @@ D3DVertexFormat::~D3DVertexFormat()
|
||||
SAFE_RELEASE(m_layout);
|
||||
}
|
||||
|
||||
void D3DVertexFormat::SetInputLayout(D3DBlob* vs_bytecode)
|
||||
ID3D11InputLayout* D3DVertexFormat::GetInputLayout(D3DBlob* vs_bytecode)
|
||||
{
|
||||
if (!m_layout)
|
||||
{
|
||||
if (m_layout)
|
||||
return m_layout;
|
||||
|
||||
// CreateInputLayout requires a shader input, but it only looks at the
|
||||
// signature of the shader, so we don't need to recompute it if the shader
|
||||
// changes.
|
||||
@ -131,8 +132,7 @@ void D3DVertexFormat::SetInputLayout(D3DBlob* vs_bytecode)
|
||||
if (FAILED(hr))
|
||||
PanicAlert("Failed to create input layout, %s %d\n", __FILE__, __LINE__);
|
||||
DX11::D3D::SetDebugObjectName(m_layout, "input layout used to emulate the GX pipeline");
|
||||
}
|
||||
DX11::D3D::stateman->SetInputLayout(m_layout);
|
||||
return m_layout;
|
||||
}
|
||||
|
||||
} // namespace DX11
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <strsafe.h>
|
||||
#include <tuple>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MathUtil.h"
|
||||
@ -23,6 +24,8 @@
|
||||
#include "VideoBackends/D3D/D3DBase.h"
|
||||
#include "VideoBackends/D3D/D3DState.h"
|
||||
#include "VideoBackends/D3D/D3DUtil.h"
|
||||
#include "VideoBackends/D3D/DXPipeline.h"
|
||||
#include "VideoBackends/D3D/DXShader.h"
|
||||
#include "VideoBackends/D3D/DXTexture.h"
|
||||
#include "VideoBackends/D3D/FramebufferManager.h"
|
||||
#include "VideoBackends/D3D/GeometryShaderCache.h"
|
||||
@ -41,6 +44,12 @@
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
// Reserve 512KB for vertices, and 64KB for uniforms.
|
||||
// This should be sufficient for our usages, and if more is required,
|
||||
// we split it into multiple draws.
|
||||
constexpr u32 UTILITY_VBO_SIZE = 512 * 1024;
|
||||
constexpr u32 UTILITY_UBO_SIZE = 64 * 1024;
|
||||
|
||||
// Nvidia stereo blitting struct defined in "nvstereo.h" from the Nvidia SDK
|
||||
typedef struct _Nv_Stereo_Image_Header
|
||||
{
|
||||
@ -165,6 +174,16 @@ void Renderer::SetupDeviceObjects()
|
||||
D3D::SetDebugObjectName(m_reset_rast_state, "rasterizer state for Renderer::ResetAPIState");
|
||||
|
||||
m_screenshot_texture = nullptr;
|
||||
|
||||
CD3D11_BUFFER_DESC vbo_desc(UTILITY_VBO_SIZE, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC,
|
||||
D3D11_CPU_ACCESS_WRITE);
|
||||
hr = D3D::device->CreateBuffer(&vbo_desc, nullptr, &m_utility_vertex_buffer);
|
||||
CHECK(SUCCEEDED(hr), "Create utility VBO");
|
||||
|
||||
CD3D11_BUFFER_DESC ubo_desc(UTILITY_UBO_SIZE, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC,
|
||||
D3D11_CPU_ACCESS_WRITE);
|
||||
hr = D3D::device->CreateBuffer(&ubo_desc, nullptr, &m_utility_uniform_buffer);
|
||||
CHECK(SUCCEEDED(hr), "Create utility UBO");
|
||||
}
|
||||
|
||||
// Kill off all device objects
|
||||
@ -184,6 +203,8 @@ void Renderer::TeardownDeviceObjects()
|
||||
SAFE_RELEASE(m_reset_rast_state);
|
||||
SAFE_RELEASE(m_screenshot_texture);
|
||||
SAFE_RELEASE(m_3d_vision_texture);
|
||||
SAFE_RELEASE(m_utility_vertex_buffer);
|
||||
SAFE_RELEASE(m_utility_uniform_buffer);
|
||||
}
|
||||
|
||||
void Renderer::Create3DVisionTexture(int width, int height)
|
||||
@ -229,6 +250,109 @@ void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
|
||||
D3D::DrawTextScaled(static_cast<float>(left), static_cast<float>(top), 20.f, 0.0f, color, text);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromSource(ShaderStage stage,
|
||||
const char* source, size_t length)
|
||||
{
|
||||
return DXShader::CreateFromSource(stage, source, length);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
|
||||
const void* data, size_t length)
|
||||
{
|
||||
return DXShader::CreateFromBinary(stage, data, length);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
{
|
||||
return DXPipeline::Create(config);
|
||||
}
|
||||
|
||||
void Renderer::UpdateUtilityUniformBuffer(const void* uniforms, u32 uniforms_size)
|
||||
{
|
||||
_dbg_assert_(VIDEO, uniforms_size > 0 && uniforms_size < UTILITY_UBO_SIZE);
|
||||
D3D11_MAPPED_SUBRESOURCE mapped;
|
||||
HRESULT hr = D3D::context->Map(m_utility_uniform_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
CHECK(SUCCEEDED(hr), "Map utility UBO");
|
||||
std::memcpy(mapped.pData, uniforms, uniforms_size);
|
||||
D3D::context->Unmap(m_utility_uniform_buffer, 0);
|
||||
}
|
||||
|
||||
void Renderer::UpdateUtilityVertexBuffer(const void* vertices, u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mapped;
|
||||
HRESULT hr = D3D::context->Map(m_utility_vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
CHECK(SUCCEEDED(hr), "Map utility VBO");
|
||||
std::memcpy(mapped.pData, vertices, num_vertices * vertex_stride);
|
||||
D3D::context->Unmap(m_utility_vertex_buffer, 0);
|
||||
}
|
||||
|
||||
void Renderer::SetPipeline(const AbstractPipeline* pipeline)
|
||||
{
|
||||
const DXPipeline* dx_pipeline = static_cast<const DXPipeline*>(pipeline);
|
||||
|
||||
D3D::stateman->SetRasterizerState(dx_pipeline->GetRasterizerState());
|
||||
D3D::stateman->SetDepthState(dx_pipeline->GetDepthState());
|
||||
D3D::stateman->SetBlendState(dx_pipeline->GetBlendState());
|
||||
D3D::stateman->SetPrimitiveTopology(dx_pipeline->GetPrimitiveTopology());
|
||||
D3D::stateman->SetInputLayout(dx_pipeline->GetInputLayout());
|
||||
D3D::stateman->SetVertexShader(dx_pipeline->GetVertexShader());
|
||||
D3D::stateman->SetGeometryShader(dx_pipeline->GetGeometryShader());
|
||||
D3D::stateman->SetPixelShader(dx_pipeline->GetPixelShader());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
UpdateUtilityUniformBuffer(uniforms, uniforms_size);
|
||||
D3D::stateman->SetVertexConstants(m_utility_uniform_buffer);
|
||||
D3D::stateman->SetPixelConstants(m_utility_uniform_buffer);
|
||||
D3D::stateman->SetGeometryConstants(m_utility_uniform_buffer);
|
||||
}
|
||||
|
||||
// If the vertices are larger than our buffer, we need to break it up into multiple draws.
|
||||
const char* vertices_ptr = static_cast<const char*>(vertices);
|
||||
while (num_vertices > 0)
|
||||
{
|
||||
u32 vertices_this_draw = num_vertices;
|
||||
if (vertices_ptr)
|
||||
{
|
||||
vertices_this_draw = std::min(vertices_this_draw, UTILITY_VBO_SIZE / vertex_stride);
|
||||
_dbg_assert_(VIDEO, vertices_this_draw > 0);
|
||||
UpdateUtilityVertexBuffer(vertices_ptr, vertex_stride, vertices_this_draw);
|
||||
D3D::stateman->SetVertexBuffer(m_utility_vertex_buffer, vertex_stride, 0);
|
||||
}
|
||||
|
||||
// Apply pending state and draw.
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->Draw(vertices_this_draw, 0);
|
||||
vertices_ptr += vertex_stride * vertices_this_draw;
|
||||
num_vertices -= vertices_this_draw;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::DispatchComputeShader(const AbstractShader* shader, const void* uniforms,
|
||||
u32 uniforms_size, u32 groups_x, u32 groups_y, u32 groups_z)
|
||||
{
|
||||
D3D::stateman->SetComputeShader(static_cast<const DXShader*>(shader)->GetD3DComputeShader());
|
||||
|
||||
if (uniforms_size > 0)
|
||||
{
|
||||
UpdateUtilityUniformBuffer(uniforms, uniforms_size);
|
||||
D3D::stateman->SetComputeConstants(m_utility_uniform_buffer);
|
||||
}
|
||||
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->Dispatch(groups_x, groups_y, groups_z);
|
||||
}
|
||||
|
||||
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
||||
{
|
||||
TargetRectangle result;
|
||||
@ -405,8 +529,8 @@ void Renderer::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num
|
||||
}
|
||||
else // if (type == EFBAccessType::PokeZ)
|
||||
{
|
||||
D3D::stateman->PushBlendState(m_clear_blend_states[3]);
|
||||
D3D::stateman->PushDepthState(m_clear_depth_states[1]);
|
||||
D3D::stateman->SetBlendState(m_clear_blend_states[3]);
|
||||
D3D::stateman->SetDepthState(m_clear_depth_states[1]);
|
||||
|
||||
D3D11_VIEWPORT vp =
|
||||
CD3D11_VIEWPORT(0.0f, 0.0f, (float)GetTargetWidth(), (float)GetTargetHeight());
|
||||
@ -417,12 +541,6 @@ void Renderer::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num
|
||||
|
||||
D3D::DrawEFBPokeQuads(type, points, num_points);
|
||||
|
||||
if (type == EFBAccessType::PokeZ)
|
||||
{
|
||||
D3D::stateman->PopDepthState();
|
||||
D3D::stateman->PopBlendState();
|
||||
}
|
||||
|
||||
RestoreAPIState();
|
||||
}
|
||||
|
||||
@ -446,21 +564,21 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
|
||||
ResetAPIState();
|
||||
|
||||
if (colorEnable && alphaEnable)
|
||||
D3D::stateman->PushBlendState(m_clear_blend_states[0]);
|
||||
D3D::stateman->SetBlendState(m_clear_blend_states[0]);
|
||||
else if (colorEnable)
|
||||
D3D::stateman->PushBlendState(m_clear_blend_states[1]);
|
||||
D3D::stateman->SetBlendState(m_clear_blend_states[1]);
|
||||
else if (alphaEnable)
|
||||
D3D::stateman->PushBlendState(m_clear_blend_states[2]);
|
||||
D3D::stateman->SetBlendState(m_clear_blend_states[2]);
|
||||
else
|
||||
D3D::stateman->PushBlendState(m_clear_blend_states[3]);
|
||||
D3D::stateman->SetBlendState(m_clear_blend_states[3]);
|
||||
|
||||
// TODO: Should we enable Z testing here?
|
||||
// if (!bpmem.zmode.testenable) D3D::stateman->PushDepthState(s_clear_depth_states[0]);
|
||||
// else
|
||||
if (zEnable)
|
||||
D3D::stateman->PushDepthState(m_clear_depth_states[1]);
|
||||
D3D::stateman->SetDepthState(m_clear_depth_states[1]);
|
||||
else /*if (!zEnable)*/
|
||||
D3D::stateman->PushDepthState(m_clear_depth_states[2]);
|
||||
D3D::stateman->SetDepthState(m_clear_depth_states[2]);
|
||||
|
||||
// Update the view port for clearing the picture
|
||||
TargetRectangle targetRc = Renderer::ConvertEFBRectangle(rc);
|
||||
@ -474,9 +592,6 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
|
||||
u32 rgbaColor = (color & 0xFF00FF00) | ((color >> 16) & 0xFF) | ((color << 16) & 0xFF0000);
|
||||
D3D::drawClearQuad(rgbaColor, 1.0f - (z & 0xFFFFFF) / 16777216.0f);
|
||||
|
||||
D3D::stateman->PopDepthState();
|
||||
D3D::stateman->PopBlendState();
|
||||
|
||||
RestoreAPIState();
|
||||
}
|
||||
|
||||
@ -646,26 +761,23 @@ void Renderer::UpdateBackbufferSize()
|
||||
// ALWAYS call RestoreAPIState for each ResetAPIState call you're doing
|
||||
void Renderer::ResetAPIState()
|
||||
{
|
||||
D3D::stateman->PushBlendState(m_reset_blend_state);
|
||||
D3D::stateman->PushDepthState(m_reset_depth_state);
|
||||
D3D::stateman->PushRasterizerState(m_reset_rast_state);
|
||||
D3D::stateman->SetBlendState(m_reset_blend_state);
|
||||
D3D::stateman->SetDepthState(m_reset_depth_state);
|
||||
D3D::stateman->SetRasterizerState(m_reset_rast_state);
|
||||
}
|
||||
|
||||
void Renderer::RestoreAPIState()
|
||||
{
|
||||
// Gets us back into a more game-like state.
|
||||
D3D::stateman->PopBlendState();
|
||||
D3D::stateman->PopDepthState();
|
||||
D3D::stateman->PopRasterizerState();
|
||||
BPFunctions::SetViewport();
|
||||
BPFunctions::SetScissor();
|
||||
}
|
||||
|
||||
void Renderer::ApplyState()
|
||||
{
|
||||
D3D::stateman->PushBlendState(m_state_cache.Get(m_gx_state.blend));
|
||||
D3D::stateman->PushDepthState(m_state_cache.Get(m_gx_state.zmode));
|
||||
D3D::stateman->PushRasterizerState(m_state_cache.Get(m_gx_state.raster));
|
||||
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);
|
||||
@ -683,9 +795,6 @@ void Renderer::ApplyState()
|
||||
|
||||
void Renderer::RestoreState()
|
||||
{
|
||||
D3D::stateman->PopBlendState();
|
||||
D3D::stateman->PopDepthState();
|
||||
D3D::stateman->PopRasterizerState();
|
||||
}
|
||||
|
||||
void Renderer::SetRasterizationState(const RasterizationState& state)
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <d3d11.h>
|
||||
#include <string>
|
||||
#include "VideoBackends/D3D/D3DState.h"
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
@ -25,7 +26,13 @@ public:
|
||||
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
|
||||
std::unique_ptr<AbstractStagingTexture>
|
||||
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, const char* source,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
|
||||
void SetPipeline(const AbstractPipeline* pipeline) override;
|
||||
void SetBlendingState(const BlendingState& state) override;
|
||||
void SetScissorRect(const MathUtil::Rectangle<int>& rc) override;
|
||||
void SetRasterizationState(const RasterizationState& state) override;
|
||||
@ -63,6 +70,11 @@ public:
|
||||
|
||||
void ReinterpretPixelData(unsigned int convtype) override;
|
||||
|
||||
void DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices) override;
|
||||
void DispatchComputeShader(const AbstractShader* shader, const void* uniforms, u32 uniforms_size,
|
||||
u32 groups_x, u32 groups_y, u32 groups_z) override;
|
||||
|
||||
private:
|
||||
struct GXPipelineState
|
||||
{
|
||||
@ -82,6 +94,9 @@ private:
|
||||
void BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D* src_texture,
|
||||
u32 src_width, u32 src_height, float Gamma);
|
||||
|
||||
void UpdateUtilityUniformBuffer(const void* uniforms, u32 uniforms_size);
|
||||
void UpdateUtilityVertexBuffer(const void* vertices, u32 vertex_stride, u32 num_vertices);
|
||||
|
||||
StateCache m_state_cache;
|
||||
GXPipelineState m_gx_state;
|
||||
|
||||
@ -94,6 +109,9 @@ private:
|
||||
ID3D11Texture2D* m_screenshot_texture = nullptr;
|
||||
D3DTexture2D* m_3d_vision_texture = nullptr;
|
||||
|
||||
ID3D11Buffer* m_utility_vertex_buffer = nullptr;
|
||||
ID3D11Buffer* m_utility_uniform_buffer = nullptr;
|
||||
|
||||
u32 m_last_multisamples = 1;
|
||||
bool m_last_stereo_mode = false;
|
||||
bool m_last_fullscreen_state = false;
|
||||
|
@ -23,7 +23,7 @@ class D3DVertexFormat : public NativeVertexFormat
|
||||
public:
|
||||
D3DVertexFormat(const PortableVertexDeclaration& vtx_decl);
|
||||
~D3DVertexFormat();
|
||||
void SetInputLayout(D3DBlob* vs_bytecode);
|
||||
ID3D11InputLayout* GetInputLayout(D3DBlob* vs_bytecode);
|
||||
|
||||
private:
|
||||
std::array<D3D11_INPUT_ELEMENT_DESC, 32> m_elems{};
|
||||
|
@ -260,7 +260,7 @@ bool VertexShaderCache::SetShader(D3DVertexFormat* vertex_format)
|
||||
if (!last_entry->shader)
|
||||
return false;
|
||||
|
||||
vertex_format->SetInputLayout(last_entry->bytecode);
|
||||
D3D::stateman->SetInputLayout(vertex_format->GetInputLayout(last_entry->bytecode));
|
||||
D3D::stateman->SetVertexShader(last_entry->shader);
|
||||
return true;
|
||||
}
|
||||
@ -279,7 +279,7 @@ bool VertexShaderCache::SetShader(D3DVertexFormat* vertex_format)
|
||||
if (!last_entry->shader)
|
||||
return false;
|
||||
|
||||
vertex_format->SetInputLayout(last_entry->bytecode);
|
||||
D3D::stateman->SetInputLayout(vertex_format->GetInputLayout(last_entry->bytecode));
|
||||
D3D::stateman->SetVertexShader(last_entry->shader);
|
||||
return true;
|
||||
}
|
||||
@ -324,7 +324,7 @@ bool VertexShaderCache::SetUberShader(D3DVertexFormat* vertex_format)
|
||||
if (!last_uber_entry->shader)
|
||||
return false;
|
||||
|
||||
uber_vertex_format->SetInputLayout(last_uber_entry->bytecode);
|
||||
D3D::stateman->SetInputLayout(uber_vertex_format->GetInputLayout(last_uber_entry->bytecode));
|
||||
D3D::stateman->SetVertexShader(last_uber_entry->shader);
|
||||
return true;
|
||||
}
|
||||
@ -340,7 +340,7 @@ bool VertexShaderCache::SetUberShader(D3DVertexFormat* vertex_format)
|
||||
if (!last_uber_entry->shader)
|
||||
return false;
|
||||
|
||||
uber_vertex_format->SetInputLayout(last_uber_entry->bytecode);
|
||||
D3D::stateman->SetInputLayout(uber_vertex_format->GetInputLayout(last_uber_entry->bytecode));
|
||||
D3D::stateman->SetVertexShader(last_uber_entry->shader);
|
||||
return true;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "VideoBackends/Null/NullTexture.h"
|
||||
#include "VideoBackends/Null/Render.h"
|
||||
|
||||
#include "VideoCommon/AbstractPipeline.h"
|
||||
#include "VideoCommon/AbstractShader.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
||||
namespace Null
|
||||
@ -33,6 +35,40 @@ std::unique_ptr<AbstractStagingTexture> Renderer::CreateStagingTexture(StagingTe
|
||||
return std::make_unique<NullStagingTexture>(type, config);
|
||||
}
|
||||
|
||||
class NullShader final : public AbstractShader
|
||||
{
|
||||
public:
|
||||
explicit NullShader(ShaderStage stage) : AbstractShader(stage) {}
|
||||
~NullShader() = default;
|
||||
|
||||
bool HasBinary() const override { return false; }
|
||||
BinaryData GetBinary() const override { return {}; }
|
||||
};
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromSource(ShaderStage stage,
|
||||
const char* source, size_t length)
|
||||
{
|
||||
return std::make_unique<NullShader>(stage);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
|
||||
const void* data, size_t length)
|
||||
{
|
||||
return std::make_unique<NullShader>(stage);
|
||||
}
|
||||
|
||||
class NullPipeline final : public AbstractPipeline
|
||||
{
|
||||
public:
|
||||
NullPipeline() : AbstractPipeline() {}
|
||||
~NullPipeline() override = default;
|
||||
};
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
{
|
||||
return std::make_unique<NullPipeline>();
|
||||
}
|
||||
|
||||
void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
|
||||
{
|
||||
NOTICE_LOG(VIDEO, "RenderText: %s", text.c_str());
|
||||
|
@ -18,6 +18,12 @@ public:
|
||||
std::unique_ptr<AbstractStagingTexture>
|
||||
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
|
||||
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, const char* source,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
|
||||
void RenderText(const std::string& pstr, int left, int top, u32 color) override;
|
||||
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; }
|
||||
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}
|
||||
|
@ -3,6 +3,8 @@ set(SRCS
|
||||
FramebufferManager.cpp
|
||||
main.cpp
|
||||
NativeVertexFormat.cpp
|
||||
OGLPipeline.cpp
|
||||
OGLShader.cpp
|
||||
OGLTexture.cpp
|
||||
PerfQuery.cpp
|
||||
PostProcessing.cpp
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "VideoBackends/OGL/Render.h"
|
||||
#include "VideoBackends/OGL/SamplerCache.h"
|
||||
#include "VideoBackends/OGL/TextureConverter.h"
|
||||
#include "VideoBackends/OGL/VertexManager.h"
|
||||
|
||||
#include "VideoCommon/OnScreenDisplay.h"
|
||||
#include "VideoCommon/VertexShaderGen.h"
|
||||
@ -395,6 +396,8 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms
|
||||
glEnableVertexAttribArray(SHADER_COLOR1_ATTRIB);
|
||||
glVertexAttribIPointer(SHADER_COLOR1_ATTRIB, 1, GL_INT, sizeof(EfbPokeData),
|
||||
(void*)offsetof(EfbPokeData, data));
|
||||
glBindBuffer(GL_ARRAY_BUFFER,
|
||||
static_cast<VertexManager*>(g_vertex_manager.get())->GetVertexBufferHandle());
|
||||
|
||||
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
@ -563,8 +566,6 @@ void FramebufferManager::ReinterpretPixelData(unsigned int convtype)
|
||||
{
|
||||
g_renderer->ResetAPIState();
|
||||
|
||||
OpenGL_BindAttributelessVAO();
|
||||
|
||||
GLuint src_texture = 0;
|
||||
|
||||
// We aren't allowed to render and sample the same texture in one draw call,
|
||||
@ -582,6 +583,7 @@ void FramebufferManager::ReinterpretPixelData(unsigned int convtype)
|
||||
g_sampler_cache->BindNearestSampler(9);
|
||||
|
||||
m_pixel_format_shaders[convtype ? 1 : 0].Bind();
|
||||
ProgramShaderCache::BindVertexFormat(nullptr);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindTexture(m_textureType, 0);
|
||||
|
||||
@ -607,6 +609,8 @@ void FramebufferManager::PokeEFB(EFBAccessType type, const EfbPokeData* points,
|
||||
glViewport(0, 0, m_targetWidth, m_targetHeight);
|
||||
glDrawArrays(GL_POINTS, 0, (GLsizei)num_points);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER,
|
||||
static_cast<VertexManager*>(g_vertex_manager.get())->GetVertexBufferHandle());
|
||||
g_renderer->RestoreAPIState();
|
||||
|
||||
// TODO: Could just update the EFB cache with the new value
|
||||
|
@ -36,6 +36,8 @@
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemGroup>
|
||||
<ClCompile Include="OGLPipeline.cpp" />
|
||||
<ClCompile Include="OGLShader.cpp" />
|
||||
<ClCompile Include="OGLTexture.cpp" />
|
||||
<ClCompile Include="BoundingBox.cpp" />
|
||||
<ClCompile Include="FramebufferManager.cpp" />
|
||||
@ -53,6 +55,8 @@
|
||||
<ClCompile Include="VertexManager.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="OGLPipeline.h" />
|
||||
<ClInclude Include="OGLShader.h" />
|
||||
<ClInclude Include="OGLTexture.h" />
|
||||
<ClInclude Include="BoundingBox.h" />
|
||||
<ClInclude Include="FramebufferManager.h" />
|
||||
|
@ -56,6 +56,12 @@
|
||||
<ClCompile Include="OGLTexture.cpp">
|
||||
<Filter>Render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="OGLShader.cpp">
|
||||
<Filter>Render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="OGLPipeline.cpp">
|
||||
<Filter>Render</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="VertexManager.h">
|
||||
@ -99,6 +105,12 @@
|
||||
<ClInclude Include="OGLTexture.h">
|
||||
<Filter>Render</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="OGLShader.h">
|
||||
<Filter>Render</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="OGLPipeline.h">
|
||||
<Filter>Render</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
|
62
Source/Core/VideoBackends/OGL/OGLPipeline.cpp
Normal file
62
Source/Core/VideoBackends/OGL/OGLPipeline.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Common/Assert.h"
|
||||
|
||||
#include "VideoBackends/OGL/OGLPipeline.h"
|
||||
#include "VideoBackends/OGL/OGLShader.h"
|
||||
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
||||
#include "VideoBackends/OGL/Render.h"
|
||||
#include "VideoBackends/OGL/VertexManager.h"
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
static GLenum MapToGLPrimitive(PrimitiveType primitive_type)
|
||||
{
|
||||
switch (primitive_type)
|
||||
{
|
||||
case PrimitiveType::Points:
|
||||
return GL_POINTS;
|
||||
case PrimitiveType::Lines:
|
||||
return GL_LINES;
|
||||
case PrimitiveType::Triangles:
|
||||
return GL_TRIANGLES;
|
||||
case PrimitiveType::TriangleStrip:
|
||||
return GL_TRIANGLE_STRIP;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
OGLPipeline::OGLPipeline(const GLVertexFormat* vertex_format,
|
||||
const RasterizationState& rasterization_state,
|
||||
const DepthState& depth_state, const BlendingState& blending_state,
|
||||
const PipelineProgram* program, GLuint gl_primitive)
|
||||
: m_vertex_format(vertex_format), m_rasterization_state(rasterization_state),
|
||||
m_depth_state(depth_state), m_blending_state(blending_state), m_program(program),
|
||||
m_gl_primitive(gl_primitive)
|
||||
{
|
||||
}
|
||||
|
||||
OGLPipeline::~OGLPipeline()
|
||||
{
|
||||
// We don't want to destroy the shaders.
|
||||
ProgramShaderCache::ReleasePipelineProgram(m_program);
|
||||
}
|
||||
|
||||
std::unique_ptr<OGLPipeline> OGLPipeline::Create(const AbstractPipelineConfig& config)
|
||||
{
|
||||
const PipelineProgram* program =
|
||||
ProgramShaderCache::GetPipelineProgram(static_cast<const OGLShader*>(config.vertex_shader),
|
||||
static_cast<const OGLShader*>(config.geometry_shader),
|
||||
static_cast<const OGLShader*>(config.pixel_shader));
|
||||
if (!program)
|
||||
return nullptr;
|
||||
|
||||
const GLVertexFormat* vertex_format = static_cast<const GLVertexFormat*>(config.vertex_format);
|
||||
GLenum gl_primitive = MapToGLPrimitive(config.rasterization_state.primitive);
|
||||
return std::make_unique<OGLPipeline>(vertex_format, config.rasterization_state,
|
||||
config.depth_state, config.blending_state, program,
|
||||
gl_primitive);
|
||||
}
|
||||
} // namespace OGL
|
43
Source/Core/VideoBackends/OGL/OGLPipeline.h
Normal file
43
Source/Core/VideoBackends/OGL/OGLPipeline.h
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Common/GL/GLUtil.h"
|
||||
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
||||
#include "VideoCommon/AbstractPipeline.h"
|
||||
#include "VideoCommon/RenderState.h"
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
class OGLPipeline final : public AbstractPipeline
|
||||
{
|
||||
public:
|
||||
explicit OGLPipeline(const GLVertexFormat* vertex_format,
|
||||
const RasterizationState& rasterization_state, const DepthState& depth_state,
|
||||
const BlendingState& blending_state, const PipelineProgram* program,
|
||||
GLenum gl_primitive);
|
||||
~OGLPipeline() override;
|
||||
|
||||
const GLVertexFormat* GetVertexFormat() const { return m_vertex_format; }
|
||||
const RasterizationState& GetRasterizationState() const { return m_rasterization_state; }
|
||||
const DepthState& GetDepthState() const { return m_depth_state; }
|
||||
const BlendingState& GetBlendingState() const { return m_blending_state; }
|
||||
const PipelineProgram* GetProgram() const { return m_program; }
|
||||
bool HasVertexInput() const { return m_vertex_format != nullptr; }
|
||||
GLenum GetGLPrimitive() const { return m_gl_primitive; }
|
||||
static std::unique_ptr<OGLPipeline> Create(const AbstractPipelineConfig& config);
|
||||
|
||||
private:
|
||||
const GLVertexFormat* m_vertex_format;
|
||||
RasterizationState m_rasterization_state;
|
||||
DepthState m_depth_state;
|
||||
BlendingState m_blending_state;
|
||||
const PipelineProgram* m_program;
|
||||
GLenum m_gl_primitive;
|
||||
};
|
||||
|
||||
} // namespace OGL
|
77
Source/Core/VideoBackends/OGL/OGLShader.cpp
Normal file
77
Source/Core/VideoBackends/OGL/OGLShader.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "VideoBackends/OGL/OGLShader.h"
|
||||
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
static GLenum GetGLShaderTypeForStage(ShaderStage stage)
|
||||
{
|
||||
switch (stage)
|
||||
{
|
||||
case ShaderStage::Vertex:
|
||||
return GL_VERTEX_SHADER;
|
||||
case ShaderStage::Geometry:
|
||||
return GL_GEOMETRY_SHADER;
|
||||
case ShaderStage::Pixel:
|
||||
return GL_FRAGMENT_SHADER;
|
||||
case ShaderStage::Compute:
|
||||
return GL_COMPUTE_SHADER;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
OGLShader::OGLShader(ShaderStage stage, GLenum gl_type, GLuint shader_id)
|
||||
: AbstractShader(stage), m_type(gl_type), m_id(shader_id)
|
||||
{
|
||||
}
|
||||
|
||||
OGLShader::OGLShader(GLuint compute_program_id)
|
||||
: AbstractShader(ShaderStage::Compute), m_type(GL_COMPUTE_SHADER), m_id(compute_program_id)
|
||||
{
|
||||
}
|
||||
|
||||
OGLShader::~OGLShader()
|
||||
{
|
||||
if (m_stage != ShaderStage::Compute)
|
||||
glDeleteShader(m_id);
|
||||
else
|
||||
glDeleteProgram(m_compute_program_id);
|
||||
}
|
||||
|
||||
bool OGLShader::HasBinary() const
|
||||
{
|
||||
// NOTE: GL shaders do not have binaries, programs do.
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractShader::BinaryData OGLShader::GetBinary() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::unique_ptr<OGLShader> OGLShader::CreateFromSource(ShaderStage stage, const char* source,
|
||||
size_t length)
|
||||
{
|
||||
if (stage != ShaderStage::Compute)
|
||||
{
|
||||
GLenum shader_type = GetGLShaderTypeForStage(stage);
|
||||
GLuint shader_id =
|
||||
ProgramShaderCache::CompileSingleShader(shader_type, std::string(source, length));
|
||||
if (!shader_id)
|
||||
return nullptr;
|
||||
|
||||
return std::make_unique<OGLShader>(stage, shader_type, shader_id);
|
||||
}
|
||||
|
||||
// Compute shaders.
|
||||
SHADER prog;
|
||||
if (!ProgramShaderCache::CompileComputeShader(prog, std::string(source, length)))
|
||||
return nullptr;
|
||||
return std::make_unique<OGLShader>(prog.glprogid);
|
||||
}
|
||||
|
||||
} // namespace OGL
|
38
Source/Core/VideoBackends/OGL/OGLShader.h
Normal file
38
Source/Core/VideoBackends/OGL/OGLShader.h
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/GL/GLUtil.h"
|
||||
#include "VideoCommon/AbstractShader.h"
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
class OGLShader final : public AbstractShader
|
||||
{
|
||||
public:
|
||||
explicit OGLShader(ShaderStage stage, GLenum gl_type, GLuint shader_id);
|
||||
explicit OGLShader(GLuint compute_program_id);
|
||||
~OGLShader() override;
|
||||
|
||||
GLenum GetGLShaderType() const { return m_type; }
|
||||
GLuint GetGLShaderID() const { return m_id; }
|
||||
GLuint GetGLComputeProgramID() const { return m_compute_program_id; }
|
||||
bool HasBinary() const override;
|
||||
BinaryData GetBinary() const override;
|
||||
|
||||
static std::unique_ptr<OGLShader> CreateFromSource(ShaderStage stage, const char* source,
|
||||
size_t length);
|
||||
|
||||
private:
|
||||
GLenum m_type;
|
||||
GLuint m_id;
|
||||
GLuint m_compute_program_id;
|
||||
};
|
||||
|
||||
} // namespace OGL
|
@ -5,7 +5,6 @@
|
||||
#include "VideoBackends/OGL/PostProcessing.h"
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/GL/GLUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
@ -47,7 +46,7 @@ void OpenGLPostProcessing::BlitFromTexture(TargetRectangle src, TargetRectangle
|
||||
|
||||
glViewport(dst.left, dst.bottom, dst.GetWidth(), dst.GetHeight());
|
||||
|
||||
OpenGL_BindAttributelessVAO();
|
||||
ProgramShaderCache::BindVertexFormat(nullptr);
|
||||
|
||||
m_shader.Bind();
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/GL/GLInterfaceBase.h"
|
||||
@ -20,6 +21,7 @@
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Host.h"
|
||||
|
||||
#include "VideoBackends/OGL/OGLShader.h"
|
||||
#include "VideoBackends/OGL/Render.h"
|
||||
#include "VideoBackends/OGL/StreamBuffer.h"
|
||||
#include "VideoBackends/OGL/VertexManager.h"
|
||||
@ -40,13 +42,14 @@
|
||||
namespace OGL
|
||||
{
|
||||
static constexpr u32 UBO_LENGTH = 32 * 1024 * 1024;
|
||||
static constexpr u32 INVALID_VAO = std::numeric_limits<u32>::max();
|
||||
|
||||
std::unique_ptr<ProgramShaderCache::SharedContextAsyncShaderCompiler>
|
||||
ProgramShaderCache::s_async_compiler;
|
||||
u32 ProgramShaderCache::s_ubo_buffer_size;
|
||||
s32 ProgramShaderCache::s_ubo_align;
|
||||
u32 ProgramShaderCache::s_last_VAO = INVALID_VAO;
|
||||
GLuint ProgramShaderCache::s_attributeless_VBO = 0;
|
||||
GLuint ProgramShaderCache::s_attributeless_VAO = 0;
|
||||
GLuint ProgramShaderCache::s_last_VAO = 0;
|
||||
|
||||
static std::unique_ptr<StreamBuffer> s_buffer;
|
||||
static int num_failures = 0;
|
||||
@ -56,6 +59,7 @@ static LinearDiskCache<UBERSHADERUID, u8> s_uber_program_disk_cache;
|
||||
static GLuint CurrentProgram = 0;
|
||||
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
||||
ProgramShaderCache::UberPCache ProgramShaderCache::ubershaders;
|
||||
ProgramShaderCache::PipelineProgramMap ProgramShaderCache::pipelineprograms;
|
||||
ProgramShaderCache::PCacheEntry* ProgramShaderCache::last_entry;
|
||||
ProgramShaderCache::PCacheEntry* ProgramShaderCache::last_uber_entry;
|
||||
SHADERUID ProgramShaderCache::last_uid;
|
||||
@ -187,6 +191,47 @@ void SHADER::DestroyShaders()
|
||||
}
|
||||
}
|
||||
|
||||
bool PipelineProgramKey::operator!=(const PipelineProgramKey& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
bool PipelineProgramKey::operator==(const PipelineProgramKey& rhs) const
|
||||
{
|
||||
return std::tie(vertex_shader, geometry_shader, pixel_shader) ==
|
||||
std::tie(rhs.vertex_shader, rhs.geometry_shader, rhs.pixel_shader);
|
||||
}
|
||||
|
||||
bool PipelineProgramKey::operator<(const PipelineProgramKey& rhs) const
|
||||
{
|
||||
return std::tie(vertex_shader, geometry_shader, pixel_shader) <
|
||||
std::tie(rhs.vertex_shader, rhs.geometry_shader, rhs.pixel_shader);
|
||||
}
|
||||
|
||||
std::size_t PipelineProgramKeyHash::operator()(const PipelineProgramKey& key) const
|
||||
{
|
||||
// We would really want std::hash_combine for this..
|
||||
std::hash<const void*> hasher;
|
||||
return hasher(key.vertex_shader) + hasher(key.geometry_shader) + hasher(key.pixel_shader);
|
||||
}
|
||||
|
||||
StreamBuffer* ProgramShaderCache::GetUniformBuffer()
|
||||
{
|
||||
return s_buffer.get();
|
||||
}
|
||||
|
||||
u32 ProgramShaderCache::GetUniformBufferAlignment()
|
||||
{
|
||||
return s_ubo_align;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::InvalidateConstants()
|
||||
{
|
||||
VertexShaderManager::dirty = true;
|
||||
GeometryShaderManager::dirty = true;
|
||||
PixelShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::UploadConstants()
|
||||
{
|
||||
if (PixelShaderManager::dirty || VertexShaderManager::dirty || GeometryShaderManager::dirty)
|
||||
@ -484,8 +529,7 @@ bool ProgramShaderCache::CheckShaderCompileResult(GLuint id, GLenum type, const
|
||||
glGetShaderiv(id, GL_COMPILE_STATUS, &compileStatus);
|
||||
GLsizei length = 0;
|
||||
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
|
||||
|
||||
if (compileStatus != GL_TRUE || (length > 1 && DEBUG_GLSL))
|
||||
if (compileStatus != GL_TRUE || length > 1)
|
||||
{
|
||||
std::string info_log;
|
||||
info_log.resize(length);
|
||||
@ -508,7 +552,10 @@ bool ProgramShaderCache::CheckShaderCompileResult(GLuint id, GLenum type, const
|
||||
break;
|
||||
}
|
||||
|
||||
ERROR_LOG(VIDEO, "%s Shader info log:\n%s", prefix, info_log.c_str());
|
||||
if (compileStatus != GL_TRUE)
|
||||
ERROR_LOG(VIDEO, "%s failed compilation:\n%s", prefix, info_log.c_str());
|
||||
else
|
||||
WARN_LOG(VIDEO, "%s compiled with warnings:\n%s", prefix, info_log.c_str());
|
||||
|
||||
std::string filename = StringFromFormat(
|
||||
"%sbad_%s_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), prefix, num_failures++);
|
||||
@ -542,12 +589,16 @@ bool ProgramShaderCache::CheckProgramLinkResult(GLuint id, const std::string& vc
|
||||
glGetProgramiv(id, GL_LINK_STATUS, &linkStatus);
|
||||
GLsizei length = 0;
|
||||
glGetProgramiv(id, GL_INFO_LOG_LENGTH, &length);
|
||||
if (linkStatus != GL_TRUE || (length > 1 && DEBUG_GLSL))
|
||||
if (linkStatus != GL_TRUE || length > 1)
|
||||
{
|
||||
std::string info_log;
|
||||
info_log.resize(length);
|
||||
glGetProgramInfoLog(id, length, &length, &info_log[0]);
|
||||
ERROR_LOG(VIDEO, "Program info log:\n%s", info_log.c_str());
|
||||
|
||||
if (linkStatus != GL_TRUE)
|
||||
ERROR_LOG(VIDEO, "Program failed linking:\n%s", info_log.c_str());
|
||||
else
|
||||
WARN_LOG(VIDEO, "Program linked with warnings:\n%s", info_log.c_str());
|
||||
|
||||
std::string filename =
|
||||
StringFromFormat("%sbad_p_%d.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
||||
@ -608,6 +659,7 @@ void ProgramShaderCache::Init()
|
||||
LoadProgramBinaries();
|
||||
|
||||
CreateHeader();
|
||||
CreateAttributelessVAO();
|
||||
|
||||
CurrentProgram = 0;
|
||||
last_entry = nullptr;
|
||||
@ -657,7 +709,6 @@ void ProgramShaderCache::Reload()
|
||||
if (g_ActiveConfig.CanPrecompileUberShaders())
|
||||
PrecompileUberShaders();
|
||||
|
||||
InvalidateVertexFormat();
|
||||
CurrentProgram = 0;
|
||||
last_entry = nullptr;
|
||||
last_uber_entry = nullptr;
|
||||
@ -681,14 +732,42 @@ void ProgramShaderCache::Shutdown()
|
||||
s_program_disk_cache.Close();
|
||||
s_uber_program_disk_cache.Close();
|
||||
|
||||
InvalidateVertexFormat();
|
||||
DestroyShaders();
|
||||
s_buffer.reset();
|
||||
|
||||
glBindVertexArray(0);
|
||||
glDeleteBuffers(1, &s_attributeless_VBO);
|
||||
glDeleteVertexArrays(1, &s_attributeless_VAO);
|
||||
s_attributeless_VBO = 0;
|
||||
s_attributeless_VAO = 0;
|
||||
s_last_VAO = 0;
|
||||
|
||||
// All pipeline programs should have been released.
|
||||
_dbg_assert_(VIDEO, pipelineprograms.empty());
|
||||
pipelineprograms.clear();
|
||||
}
|
||||
|
||||
void ProgramShaderCache::CreateAttributelessVAO()
|
||||
{
|
||||
glGenVertexArrays(1, &s_attributeless_VAO);
|
||||
|
||||
// In a compatibility context, we require a valid, bound array buffer.
|
||||
glGenBuffers(1, &s_attributeless_VBO);
|
||||
|
||||
// Initialize the buffer with nothing. 16 floats is an arbitrary size that may work around driver
|
||||
// issues.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, s_attributeless_VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 16, nullptr, GL_STATIC_DRAW);
|
||||
|
||||
// We must also define vertex attribute 0.
|
||||
glBindVertexArray(s_attributeless_VAO);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
glEnableVertexAttribArray(0);
|
||||
}
|
||||
|
||||
void ProgramShaderCache::BindVertexFormat(const GLVertexFormat* vertex_format)
|
||||
{
|
||||
u32 new_VAO = vertex_format ? vertex_format->VAO : 0;
|
||||
u32 new_VAO = vertex_format ? vertex_format->VAO : s_attributeless_VAO;
|
||||
if (s_last_VAO == new_VAO)
|
||||
return;
|
||||
|
||||
@ -698,15 +777,12 @@ void ProgramShaderCache::BindVertexFormat(const GLVertexFormat* vertex_format)
|
||||
|
||||
void ProgramShaderCache::InvalidateVertexFormat()
|
||||
{
|
||||
s_last_VAO = INVALID_VAO;
|
||||
s_last_VAO = 0;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::BindLastVertexFormat()
|
||||
void ProgramShaderCache::InvalidateLastProgram()
|
||||
{
|
||||
if (s_last_VAO != INVALID_VAO)
|
||||
glBindVertexArray(s_last_VAO);
|
||||
else
|
||||
glBindVertexArray(0);
|
||||
CurrentProgram = 0;
|
||||
}
|
||||
|
||||
GLuint ProgramShaderCache::CreateProgramFromBinary(const u8* value, u32 value_size)
|
||||
@ -837,6 +913,58 @@ void ProgramShaderCache::DestroyShaders()
|
||||
ubershaders.clear();
|
||||
}
|
||||
|
||||
const PipelineProgram* ProgramShaderCache::GetPipelineProgram(const OGLShader* vertex_shader,
|
||||
const OGLShader* geometry_shader,
|
||||
const OGLShader* pixel_shader)
|
||||
{
|
||||
PipelineProgramKey key = {vertex_shader, geometry_shader, pixel_shader};
|
||||
auto iter = pipelineprograms.find(key);
|
||||
if (iter != pipelineprograms.end())
|
||||
{
|
||||
iter->second->reference_count++;
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<PipelineProgram> prog = std::make_unique<PipelineProgram>();
|
||||
prog->key = key;
|
||||
|
||||
// Attach shaders.
|
||||
_assert_(vertex_shader && vertex_shader->GetStage() == ShaderStage::Vertex);
|
||||
_assert_(pixel_shader && pixel_shader->GetStage() == ShaderStage::Pixel);
|
||||
prog->shader.glprogid = glCreateProgram();
|
||||
glAttachShader(prog->shader.glprogid, vertex_shader->GetGLShaderID());
|
||||
glAttachShader(prog->shader.glprogid, pixel_shader->GetGLShaderID());
|
||||
if (geometry_shader)
|
||||
{
|
||||
_assert_(geometry_shader->GetStage() == ShaderStage::Geometry);
|
||||
glAttachShader(prog->shader.glprogid, geometry_shader->GetGLShaderID());
|
||||
}
|
||||
|
||||
// Link program.
|
||||
prog->shader.SetProgramBindings(false);
|
||||
glLinkProgram(prog->shader.glprogid);
|
||||
if (!ProgramShaderCache::CheckProgramLinkResult(prog->shader.glprogid, {}, {}, {}))
|
||||
{
|
||||
prog->shader.Destroy();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto ip = pipelineprograms.emplace(key, std::move(prog));
|
||||
return ip.first->second.get();
|
||||
}
|
||||
|
||||
void ProgramShaderCache::ReleasePipelineProgram(const PipelineProgram* prog)
|
||||
{
|
||||
auto iter = pipelineprograms.find(prog->key);
|
||||
_assert_(iter != pipelineprograms.end() && prog == iter->second.get());
|
||||
|
||||
if (--iter->second->reference_count == 0)
|
||||
{
|
||||
iter->second->shader.Destroy();
|
||||
pipelineprograms.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
void ProgramShaderCache::CreateHeader()
|
||||
{
|
||||
GlslVersion v = g_ogl_config.eSupportedGLSLVersion;
|
||||
@ -1345,5 +1473,4 @@ void ProgramShaderCache::DrawPrerenderArray(const SHADER& shader, PrimitiveType
|
||||
glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
|
||||
glDeleteSync(sync);
|
||||
}
|
||||
|
||||
} // namespace OGL
|
||||
|
@ -4,8 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Common/GL/GLUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
@ -21,7 +23,9 @@ class cInterfaceBase;
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
class OGLShader;
|
||||
class GLVertexFormat;
|
||||
class StreamBuffer;
|
||||
|
||||
class SHADERUID
|
||||
{
|
||||
@ -81,6 +85,29 @@ struct SHADER
|
||||
void DestroyShaders();
|
||||
};
|
||||
|
||||
struct PipelineProgramKey
|
||||
{
|
||||
const OGLShader* vertex_shader;
|
||||
const OGLShader* geometry_shader;
|
||||
const OGLShader* pixel_shader;
|
||||
|
||||
bool operator==(const PipelineProgramKey& rhs) const;
|
||||
bool operator!=(const PipelineProgramKey& rhs) const;
|
||||
bool operator<(const PipelineProgramKey& rhs) const;
|
||||
};
|
||||
|
||||
struct PipelineProgramKeyHash
|
||||
{
|
||||
std::size_t operator()(const PipelineProgramKey& key) const;
|
||||
};
|
||||
|
||||
struct PipelineProgram
|
||||
{
|
||||
PipelineProgramKey key;
|
||||
SHADER shader;
|
||||
std::atomic_size_t reference_count{1};
|
||||
};
|
||||
|
||||
class ProgramShaderCache
|
||||
{
|
||||
public:
|
||||
@ -98,7 +125,7 @@ public:
|
||||
static SHADER* SetUberShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format);
|
||||
static void BindVertexFormat(const GLVertexFormat* vertex_format);
|
||||
static void InvalidateVertexFormat();
|
||||
static void BindLastVertexFormat();
|
||||
static void InvalidateLastProgram();
|
||||
|
||||
static bool CompileShader(SHADER& shader, const std::string& vcode, const std::string& pcode,
|
||||
const std::string& gcode = "");
|
||||
@ -107,6 +134,9 @@ public:
|
||||
static bool CheckShaderCompileResult(GLuint id, GLenum type, const std::string& code);
|
||||
static bool CheckProgramLinkResult(GLuint id, const std::string& vcode, const std::string& pcode,
|
||||
const std::string& gcode);
|
||||
static StreamBuffer* GetUniformBuffer();
|
||||
static u32 GetUniformBufferAlignment();
|
||||
static void InvalidateConstants();
|
||||
static void UploadConstants();
|
||||
|
||||
static void Init();
|
||||
@ -116,6 +146,11 @@ public:
|
||||
static void RetrieveAsyncShaders();
|
||||
static void PrecompileUberShaders();
|
||||
|
||||
static const PipelineProgram* GetPipelineProgram(const OGLShader* vertex_shader,
|
||||
const OGLShader* geometry_shader,
|
||||
const OGLShader* pixel_shader);
|
||||
static void ReleasePipelineProgram(const PipelineProgram* prog);
|
||||
|
||||
private:
|
||||
template <typename UIDType>
|
||||
class ProgramShaderCacheInserter : public LinearDiskCacheReader<UIDType, u8>
|
||||
@ -190,7 +225,11 @@ private:
|
||||
|
||||
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();
|
||||
@ -202,6 +241,7 @@ private:
|
||||
|
||||
static PCache pshaders;
|
||||
static UberPCache ubershaders;
|
||||
static PipelineProgramMap pipelineprograms;
|
||||
static PCacheEntry* last_entry;
|
||||
static PCacheEntry* last_uber_entry;
|
||||
static SHADERUID last_uid;
|
||||
@ -210,7 +250,10 @@ private:
|
||||
static std::unique_ptr<SharedContextAsyncShaderCompiler> s_async_compiler;
|
||||
static u32 s_ubo_buffer_size;
|
||||
static s32 s_ubo_align;
|
||||
static u32 s_last_VAO;
|
||||
|
||||
static GLuint s_attributeless_VBO;
|
||||
static GLuint s_attributeless_VAO;
|
||||
static GLuint s_last_VAO;
|
||||
};
|
||||
|
||||
} // namespace OGL
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
||||
#include "VideoBackends/OGL/RasterFont.h"
|
||||
#include "VideoBackends/OGL/VertexManager.h"
|
||||
|
||||
// globals
|
||||
|
||||
@ -181,6 +182,9 @@ RasterFont::RasterFont()
|
||||
glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB);
|
||||
glVertexAttribPointer(SHADER_TEXTURE0_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat) * 4,
|
||||
(GLfloat*)nullptr + 2);
|
||||
glBindBuffer(GL_ARRAY_BUFFER,
|
||||
static_cast<VertexManager*>(g_vertex_manager.get())->GetVertexBufferHandle());
|
||||
ProgramShaderCache::InvalidateVertexFormat();
|
||||
}
|
||||
|
||||
RasterFont::~RasterFont()
|
||||
@ -278,5 +282,9 @@ void RasterFont::printMultilineText(const std::string& text, double start_x, dou
|
||||
GLfloat((color >> 8) & 0xff) / 255.f, GLfloat((color >> 0) & 0xff) / 255.f,
|
||||
GLfloat((color >> 24) & 0xff) / 255.f);
|
||||
glDrawArrays(GL_TRIANGLES, 0, usage / 4);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER,
|
||||
static_cast<VertexManager*>(g_vertex_manager.get())->GetVertexBufferHandle());
|
||||
ProgramShaderCache::InvalidateVertexFormat();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/Atomic.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/GL/GLInterfaceBase.h"
|
||||
@ -27,11 +28,14 @@
|
||||
|
||||
#include "VideoBackends/OGL/BoundingBox.h"
|
||||
#include "VideoBackends/OGL/FramebufferManager.h"
|
||||
#include "VideoBackends/OGL/OGLPipeline.h"
|
||||
#include "VideoBackends/OGL/OGLShader.h"
|
||||
#include "VideoBackends/OGL/OGLTexture.h"
|
||||
#include "VideoBackends/OGL/PostProcessing.h"
|
||||
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
||||
#include "VideoBackends/OGL/RasterFont.h"
|
||||
#include "VideoBackends/OGL/SamplerCache.h"
|
||||
#include "VideoBackends/OGL/StreamBuffer.h"
|
||||
#include "VideoBackends/OGL/TextureCache.h"
|
||||
#include "VideoBackends/OGL/VertexManager.h"
|
||||
|
||||
@ -816,8 +820,6 @@ void Renderer::Shutdown()
|
||||
|
||||
s_raster_font.reset();
|
||||
m_post_processor.reset();
|
||||
|
||||
OpenGL_DeleteAttributelessVAO();
|
||||
}
|
||||
|
||||
void Renderer::Init()
|
||||
@ -828,8 +830,6 @@ void Renderer::Init()
|
||||
|
||||
m_post_processor = std::make_unique<OpenGLPostProcessing>();
|
||||
s_raster_font = std::make_unique<RasterFont>();
|
||||
|
||||
OpenGL_CreateAttributelessVAO();
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
|
||||
@ -851,6 +851,23 @@ void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
|
||||
m_backbuffer_width, m_backbuffer_height, color);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromSource(ShaderStage stage,
|
||||
const char* source, size_t length)
|
||||
{
|
||||
return OGLShader::CreateFromSource(stage, source, length);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
|
||||
const void* data, size_t length)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
{
|
||||
return OGLPipeline::Create(config);
|
||||
}
|
||||
|
||||
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
||||
{
|
||||
TargetRectangle result;
|
||||
@ -1221,7 +1238,7 @@ void Renderer::ReinterpretPixelData(unsigned int convtype)
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::SetBlendingState(const BlendingState& state)
|
||||
void Renderer::ApplyBlendingState(const BlendingState& state)
|
||||
{
|
||||
bool useDualSource =
|
||||
state.usedualsrc && g_ActiveConfig.backend_info.bSupportsDualSourceBlend &&
|
||||
@ -1494,13 +1511,9 @@ void Renderer::RestoreAPIState()
|
||||
BPFunctions::SetViewport();
|
||||
BPFunctions::SetDepthMode();
|
||||
BPFunctions::SetBlendMode();
|
||||
|
||||
ProgramShaderCache::BindLastVertexFormat();
|
||||
const VertexManager* const vm = static_cast<VertexManager*>(g_vertex_manager.get());
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vm->GetVertexBufferHandle());
|
||||
}
|
||||
|
||||
void Renderer::SetRasterizationState(const RasterizationState& state)
|
||||
void Renderer::ApplyRasterizationState(const RasterizationState& state)
|
||||
{
|
||||
// none, ccw, cw, ccw
|
||||
if (state.cullmode != GenMode::CULL_NONE)
|
||||
@ -1515,7 +1528,7 @@ void Renderer::SetRasterizationState(const RasterizationState& state)
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::SetDepthState(const DepthState& state)
|
||||
void Renderer::ApplyDepthState(const DepthState& state)
|
||||
{
|
||||
const GLenum glCmpFuncs[8] = {GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL,
|
||||
GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS};
|
||||
@ -1536,6 +1549,33 @@ void Renderer::SetDepthState(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
|
||||
// test if the pipeline hasn't changed and skip these applications. Yet.
|
||||
m_graphics_pipeline = static_cast<const OGLPipeline*>(pipeline);
|
||||
ApplyRasterizationState(m_graphics_pipeline->GetRasterizationState());
|
||||
ApplyDepthState(m_graphics_pipeline->GetDepthState());
|
||||
ApplyBlendingState(m_graphics_pipeline->GetBlendingState());
|
||||
ProgramShaderCache::BindVertexFormat(m_graphics_pipeline->GetVertexFormat());
|
||||
m_graphics_pipeline->GetProgram()->shader.Bind();
|
||||
}
|
||||
|
||||
void Renderer::SetTexture(u32 index, const AbstractTexture* texture)
|
||||
{
|
||||
if (m_bound_textures[index] == texture)
|
||||
@ -1568,4 +1608,52 @@ void Renderer::SetInterlacingMode()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Renderer::DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
// Copy in uniforms.
|
||||
if (uniforms_size > 0)
|
||||
UploadUtilityUniforms(uniforms, uniforms_size);
|
||||
|
||||
// Draw from base index if there is vertex data.
|
||||
if (vertices)
|
||||
{
|
||||
StreamBuffer* vbuf = static_cast<VertexManager*>(g_vertex_manager.get())->GetVertexBuffer();
|
||||
auto buf = vbuf->Map(vertex_stride * num_vertices, vertex_stride);
|
||||
std::memcpy(buf.first, vertices, vertex_stride * num_vertices);
|
||||
vbuf->Unmap(vertex_stride * num_vertices);
|
||||
glDrawArrays(m_graphics_pipeline->GetGLPrimitive(), buf.second / vertex_stride, num_vertices);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(m_graphics_pipeline->GetGLPrimitive(), 0, num_vertices);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::UploadUtilityUniforms(const void* uniforms, u32 uniforms_size)
|
||||
{
|
||||
_dbg_assert_(VIDEO, uniforms_size > 0);
|
||||
|
||||
auto buf = ProgramShaderCache::GetUniformBuffer()->Map(
|
||||
uniforms_size, ProgramShaderCache::GetUniformBufferAlignment());
|
||||
std::memcpy(buf.first, uniforms, uniforms_size);
|
||||
ProgramShaderCache::GetUniformBuffer()->Unmap(uniforms_size);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 1, ProgramShaderCache::GetUniformBuffer()->m_buffer,
|
||||
buf.second, uniforms_size);
|
||||
|
||||
// This is rather horrible, but because of how the UBOs are bound, this forces it to rebind.
|
||||
ProgramShaderCache::InvalidateConstants();
|
||||
}
|
||||
|
||||
void Renderer::DispatchComputeShader(const AbstractShader* shader, const void* uniforms,
|
||||
u32 uniforms_size, u32 groups_x, u32 groups_y, u32 groups_z)
|
||||
{
|
||||
glUseProgram(static_cast<const OGLShader*>(shader)->GetGLComputeProgramID());
|
||||
if (uniforms_size > 0)
|
||||
UploadUtilityUniforms(uniforms, uniforms_size);
|
||||
|
||||
glDispatchCompute(groups_x, groups_y, groups_z);
|
||||
ProgramShaderCache::InvalidateLastProgram();
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ struct XFBSourceBase;
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
class OGLPipeline;
|
||||
void ClearEFBCache();
|
||||
|
||||
enum GlslVersion
|
||||
@ -89,7 +90,13 @@ public:
|
||||
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
|
||||
std::unique_ptr<AbstractStagingTexture>
|
||||
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, const char* source,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
|
||||
void SetPipeline(const AbstractPipeline* pipeline) override;
|
||||
void SetBlendingState(const BlendingState& state) override;
|
||||
void SetScissorRect(const MathUtil::Rectangle<int>& rc) override;
|
||||
void SetRasterizationState(const RasterizationState& state) override;
|
||||
@ -121,6 +128,12 @@ public:
|
||||
|
||||
void ReinterpretPixelData(unsigned int convtype) override;
|
||||
|
||||
void DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices) override;
|
||||
|
||||
void DispatchComputeShader(const AbstractShader* shader, const void* uniforms, u32 uniforms_size,
|
||||
u32 groups_x, u32 groups_y, u32 groups_z) override;
|
||||
|
||||
private:
|
||||
void UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc,
|
||||
const TargetRectangle& targetPixelRc, const void* data);
|
||||
@ -134,6 +147,12 @@ private:
|
||||
void CheckForSurfaceChange();
|
||||
void CheckForSurfaceResize();
|
||||
|
||||
void ApplyBlendingState(const BlendingState& state);
|
||||
void ApplyRasterizationState(const RasterizationState& state);
|
||||
void ApplyDepthState(const DepthState& state);
|
||||
void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size);
|
||||
|
||||
std::array<const AbstractTexture*, 8> m_bound_textures{};
|
||||
const OGLPipeline* m_graphics_pipeline = nullptr;
|
||||
};
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ void TextureCache::ConvertTexture(TCacheEntry* destination, TCacheEntry* source,
|
||||
glBindTexture(GL_TEXTURE_BUFFER, m_palette_resolv_texture);
|
||||
g_sampler_cache->BindNearestSampler(10);
|
||||
|
||||
OpenGL_BindAttributelessVAO();
|
||||
ProgramShaderCache::BindVertexFormat(nullptr);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
FramebufferManager::SetFramebuffer(0);
|
||||
@ -496,8 +496,6 @@ void TextureCache::CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy,
|
||||
|
||||
FramebufferManager::SetFramebuffer(destination_texture->GetFramebuffer());
|
||||
|
||||
OpenGL_BindAttributelessVAO();
|
||||
|
||||
glActiveTexture(GL_TEXTURE9);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, read_texture);
|
||||
if (scale_by_half)
|
||||
@ -539,6 +537,7 @@ void TextureCache::CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy,
|
||||
glUniform4f(shader.position_uniform, static_cast<float>(R.left), static_cast<float>(R.top),
|
||||
static_cast<float>(R.right), static_cast<float>(R.bottom));
|
||||
|
||||
ProgramShaderCache::BindVertexFormat(nullptr);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
FramebufferManager::SetFramebuffer(0);
|
||||
|
@ -111,8 +111,6 @@ static void EncodeToRamUsingShader(GLuint srcTexture, u8* destAddr, u32 dst_line
|
||||
FramebufferManager::SetFramebuffer(
|
||||
static_cast<OGLTexture*>(s_encoding_render_texture.get())->GetFramebuffer());
|
||||
|
||||
OpenGL_BindAttributelessVAO();
|
||||
|
||||
// set source texture
|
||||
glActiveTexture(GL_TEXTURE9);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, srcTexture);
|
||||
@ -128,6 +126,7 @@ static void EncodeToRamUsingShader(GLuint srcTexture, u8* destAddr, u32 dst_line
|
||||
|
||||
glViewport(0, 0, (GLsizei)(dst_line_size / 4), (GLsizei)dstHeight);
|
||||
|
||||
ProgramShaderCache::BindVertexFormat(nullptr);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
MathUtil::Rectangle<int> copy_rect(0, 0, dst_line_size / 4, dstHeight);
|
||||
|
@ -61,6 +61,16 @@ void VertexManager::DestroyDeviceObjects()
|
||||
s_indexBuffer.reset();
|
||||
}
|
||||
|
||||
StreamBuffer* VertexManager::GetVertexBuffer() const
|
||||
{
|
||||
return s_vertexBuffer.get();
|
||||
}
|
||||
|
||||
OGL::StreamBuffer* VertexManager::GetIndexBuffer() const
|
||||
{
|
||||
return s_indexBuffer.get();
|
||||
}
|
||||
|
||||
GLuint VertexManager::GetVertexBufferHandle() const
|
||||
{
|
||||
return m_vertex_buffers;
|
||||
@ -95,6 +105,11 @@ void VertexManager::ResetBuffer(u32 stride)
|
||||
}
|
||||
else
|
||||
{
|
||||
// The index buffer is part of the VAO state, therefore we need to bind it first.
|
||||
const GLVertexFormat* vertex_format =
|
||||
static_cast<GLVertexFormat*>(VertexLoaderManager::GetCurrentVertexFormat());
|
||||
ProgramShaderCache::BindVertexFormat(vertex_format);
|
||||
|
||||
auto buffer = s_vertexBuffer->Map(MAXVBUFFERSIZE, stride);
|
||||
m_cur_buffer_pointer = m_base_buffer_pointer = buffer.first;
|
||||
m_end_buffer_pointer = buffer.first + MAXVBUFFERSIZE;
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
class StreamBuffer;
|
||||
class GLVertexFormat : public NativeVertexFormat
|
||||
{
|
||||
public:
|
||||
@ -37,6 +38,8 @@ public:
|
||||
void CreateDeviceObjects() override;
|
||||
void DestroyDeviceObjects() override;
|
||||
|
||||
StreamBuffer* GetVertexBuffer() const;
|
||||
StreamBuffer* GetIndexBuffer() const;
|
||||
GLuint GetVertexBufferHandle() const;
|
||||
GLuint GetIndexBufferHandle() const;
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "VideoBackends/Software/SWOGLWindow.h"
|
||||
#include "VideoBackends/Software/SWTexture.h"
|
||||
|
||||
#include "VideoCommon/AbstractPipeline.h"
|
||||
#include "VideoCommon/AbstractShader.h"
|
||||
#include "VideoCommon/BoundingBox.h"
|
||||
#include "VideoCommon/OnScreenDisplay.h"
|
||||
#include "VideoCommon/VideoBackendBase.h"
|
||||
@ -42,6 +44,40 @@ void SWRenderer::RenderText(const std::string& pstr, int left, int top, u32 colo
|
||||
SWOGLWindow::s_instance->PrintText(pstr, left, top, color);
|
||||
}
|
||||
|
||||
class SWShader final : public AbstractShader
|
||||
{
|
||||
public:
|
||||
explicit SWShader(ShaderStage stage) : AbstractShader(stage) {}
|
||||
~SWShader() = default;
|
||||
|
||||
bool HasBinary() const override { return false; }
|
||||
BinaryData GetBinary() const override { return {}; }
|
||||
};
|
||||
|
||||
std::unique_ptr<AbstractShader>
|
||||
SWRenderer::CreateShaderFromSource(ShaderStage stage, const char* source, size_t length)
|
||||
{
|
||||
return std::make_unique<SWShader>(stage);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> SWRenderer::CreateShaderFromBinary(ShaderStage stage,
|
||||
const void* data, size_t length)
|
||||
{
|
||||
return std::make_unique<SWShader>(stage);
|
||||
}
|
||||
|
||||
class SWPipeline final : public AbstractPipeline
|
||||
{
|
||||
public:
|
||||
SWPipeline() : AbstractPipeline() {}
|
||||
~SWPipeline() override = default;
|
||||
};
|
||||
|
||||
std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
{
|
||||
return std::make_unique<SWPipeline>();
|
||||
}
|
||||
|
||||
// Called on the GPU thread
|
||||
void SWRenderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region, u64 ticks,
|
||||
float Gamma)
|
||||
|
@ -17,6 +17,12 @@ public:
|
||||
std::unique_ptr<AbstractStagingTexture>
|
||||
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
|
||||
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, const char* source,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
|
||||
void RenderText(const std::string& pstr, int left, int top, u32 color) override;
|
||||
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
|
||||
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}
|
||||
|
@ -19,6 +19,8 @@ set(SRCS
|
||||
Util.cpp
|
||||
VertexFormat.cpp
|
||||
VertexManager.cpp
|
||||
VKPipeline.cpp
|
||||
VKShader.cpp
|
||||
VKTexture.cpp
|
||||
VulkanContext.cpp
|
||||
VulkanLoader.cpp
|
||||
|
@ -26,7 +26,8 @@ enum STAGING_BUFFER_TYPE
|
||||
// Descriptor set layouts
|
||||
enum DESCRIPTOR_SET_LAYOUT
|
||||
{
|
||||
DESCRIPTOR_SET_LAYOUT_UNIFORM_BUFFERS,
|
||||
DESCRIPTOR_SET_LAYOUT_SINGLE_UNIFORM_BUFFER,
|
||||
DESCRIPTOR_SET_LAYOUT_PER_STAGE_UNIFORM_BUFFERS,
|
||||
DESCRIPTOR_SET_LAYOUT_PIXEL_SHADER_SAMPLERS,
|
||||
DESCRIPTOR_SET_LAYOUT_SHADER_STORAGE_BUFFERS,
|
||||
DESCRIPTOR_SET_LAYOUT_TEXEL_BUFFERS,
|
||||
@ -69,6 +70,7 @@ enum PIPELINE_LAYOUT
|
||||
PIPELINE_LAYOUT_BBOX,
|
||||
PIPELINE_LAYOUT_PUSH_CONSTANT,
|
||||
PIPELINE_LAYOUT_TEXTURE_CONVERSION,
|
||||
PIPELINE_LAYOUT_UTILITY,
|
||||
PIPELINE_LAYOUT_COMPUTE,
|
||||
NUM_PIPELINE_LAYOUTS
|
||||
};
|
||||
@ -128,7 +130,7 @@ constexpr u32 MINIMUM_DRAW_CALLS_PER_COMMAND_BUFFER_FOR_READBACK = 10;
|
||||
union MultisamplingState
|
||||
{
|
||||
BitField<0, 5, u32> samples; // 1-16
|
||||
BitField<0, 1, u32> per_sample_shading; // SSAA
|
||||
BitField<5, 1, u32> per_sample_shading; // SSAA
|
||||
u32 hex;
|
||||
};
|
||||
|
||||
|
@ -106,7 +106,10 @@ void ObjectCache::DestroySamplers()
|
||||
|
||||
bool ObjectCache::CreateDescriptorSetLayouts()
|
||||
{
|
||||
static const VkDescriptorSetLayoutBinding ubo_set_bindings[] = {
|
||||
static const VkDescriptorSetLayoutBinding single_ubo_set_bindings[] = {
|
||||
0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1,
|
||||
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT};
|
||||
static const VkDescriptorSetLayoutBinding per_stage_ubo_set_bindings[] = {
|
||||
{UBO_DESCRIPTOR_SET_BINDING_PS, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1,
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT},
|
||||
{UBO_DESCRIPTOR_SET_BINDING_VS, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1,
|
||||
@ -138,7 +141,9 @@ bool ObjectCache::CreateDescriptorSetLayouts()
|
||||
|
||||
static const VkDescriptorSetLayoutCreateInfo create_infos[NUM_DESCRIPTOR_SET_LAYOUTS] = {
|
||||
{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0,
|
||||
static_cast<u32>(ArraySize(ubo_set_bindings)), ubo_set_bindings},
|
||||
static_cast<u32>(ArraySize(single_ubo_set_bindings)), single_ubo_set_bindings},
|
||||
{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0,
|
||||
static_cast<u32>(ArraySize(per_stage_ubo_set_bindings)), per_stage_ubo_set_bindings},
|
||||
{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0,
|
||||
static_cast<u32>(ArraySize(sampler_set_bindings)), sampler_set_bindings},
|
||||
{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0,
|
||||
@ -177,16 +182,19 @@ bool ObjectCache::CreatePipelineLayouts()
|
||||
|
||||
// Descriptor sets for each pipeline layout
|
||||
VkDescriptorSetLayout standard_sets[] = {
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_UNIFORM_BUFFERS],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_PER_STAGE_UNIFORM_BUFFERS],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_PIXEL_SHADER_SAMPLERS]};
|
||||
VkDescriptorSetLayout bbox_sets[] = {
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_UNIFORM_BUFFERS],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_PER_STAGE_UNIFORM_BUFFERS],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_PIXEL_SHADER_SAMPLERS],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_SHADER_STORAGE_BUFFERS]};
|
||||
VkDescriptorSetLayout texture_conversion_sets[] = {
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_UNIFORM_BUFFERS],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_PER_STAGE_UNIFORM_BUFFERS],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_PIXEL_SHADER_SAMPLERS],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_TEXEL_BUFFERS]};
|
||||
VkDescriptorSetLayout utility_sets[] = {
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_SINGLE_UNIFORM_BUFFER],
|
||||
m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_PIXEL_SHADER_SAMPLERS]};
|
||||
VkDescriptorSetLayout compute_sets[] = {m_descriptor_set_layouts[DESCRIPTOR_SET_LAYOUT_COMPUTE]};
|
||||
VkPushConstantRange push_constant_range = {
|
||||
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, PUSH_CONSTANT_BUFFER_SIZE};
|
||||
@ -212,6 +220,10 @@ bool ObjectCache::CreatePipelineLayouts()
|
||||
static_cast<u32>(ArraySize(texture_conversion_sets)), texture_conversion_sets, 1,
|
||||
&push_constant_range},
|
||||
|
||||
// Texture Conversion
|
||||
{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0,
|
||||
static_cast<u32>(ArraySize(utility_sets)), utility_sets, 0, nullptr},
|
||||
|
||||
// Compute
|
||||
{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0,
|
||||
static_cast<u32>(ArraySize(compute_sets)), compute_sets, 1, &compute_push_constant_range}};
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
@ -23,9 +24,12 @@
|
||||
#include "VideoBackends/Vulkan/RasterFont.h"
|
||||
#include "VideoBackends/Vulkan/Renderer.h"
|
||||
#include "VideoBackends/Vulkan/StateTracker.h"
|
||||
#include "VideoBackends/Vulkan/StreamBuffer.h"
|
||||
#include "VideoBackends/Vulkan/SwapChain.h"
|
||||
#include "VideoBackends/Vulkan/TextureCache.h"
|
||||
#include "VideoBackends/Vulkan/Util.h"
|
||||
#include "VideoBackends/Vulkan/VKPipeline.h"
|
||||
#include "VideoBackends/Vulkan/VKShader.h"
|
||||
#include "VideoBackends/Vulkan/VKTexture.h"
|
||||
#include "VideoBackends/Vulkan/VulkanContext.h"
|
||||
|
||||
@ -171,6 +175,202 @@ std::unique_ptr<AbstractStagingTexture> Renderer::CreateStagingTexture(StagingTe
|
||||
return VKStagingTexture::Create(type, config);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromSource(ShaderStage stage,
|
||||
const char* source, size_t length)
|
||||
{
|
||||
return VKShader::CreateFromSource(stage, source, length);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractShader> Renderer::CreateShaderFromBinary(ShaderStage stage,
|
||||
const void* data, size_t length)
|
||||
{
|
||||
return VKShader::CreateFromBinary(stage, data, length);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelineConfig& config)
|
||||
{
|
||||
return VKPipeline::Create(config);
|
||||
}
|
||||
|
||||
std::tuple<VkBuffer, u32> Renderer::UpdateUtilityUniformBuffer(const void* uniforms,
|
||||
u32 uniforms_size)
|
||||
{
|
||||
StreamBuffer* ubo_buf = g_object_cache->GetUtilityShaderUniformBuffer();
|
||||
if (!ubo_buf->ReserveMemory(uniforms_size, g_vulkan_context->GetUniformBufferAlignment()))
|
||||
{
|
||||
Util::ExecuteCurrentCommandsAndRestoreState(false, true);
|
||||
if (!ubo_buf->ReserveMemory(uniforms_size, g_vulkan_context->GetUniformBufferAlignment()))
|
||||
{
|
||||
PanicAlert("Failed to reserve uniform buffer space for utility draw.");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
VkBuffer ubo = ubo_buf->GetBuffer();
|
||||
u32 ubo_offset = static_cast<u32>(ubo_buf->GetCurrentOffset());
|
||||
std::memcpy(ubo_buf->GetCurrentHostPointer(), uniforms, uniforms_size);
|
||||
ubo_buf->CommitMemory(uniforms_size);
|
||||
|
||||
return std::tie(ubo, ubo_offset);
|
||||
}
|
||||
|
||||
void Renderer::SetPipeline(const AbstractPipeline* pipeline)
|
||||
{
|
||||
m_graphics_pipeline = static_cast<const VKPipeline*>(pipeline);
|
||||
}
|
||||
|
||||
void Renderer::DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
// Binding the utility pipeline layout breaks the standard layout.
|
||||
StateTracker::GetInstance()->SetPendingRebind();
|
||||
|
||||
// Upload uniforms.
|
||||
VkBuffer uniform_buffer = g_object_cache->GetUtilityShaderUniformBuffer()->GetBuffer();
|
||||
u32 uniform_buffer_offset = 0;
|
||||
if (uniforms_size > 0)
|
||||
std::tie(uniform_buffer, uniform_buffer_offset) =
|
||||
UpdateUtilityUniformBuffer(uniforms, uniforms_size);
|
||||
|
||||
// Upload vertices.
|
||||
VkBuffer vertex_buffer = VK_NULL_HANDLE;
|
||||
VkDeviceSize vertex_buffer_offset = 0;
|
||||
if (vertices)
|
||||
{
|
||||
u32 vertices_size = vertex_stride * num_vertices;
|
||||
StreamBuffer* vbo_buf = g_object_cache->GetUtilityShaderVertexBuffer();
|
||||
if (!vbo_buf->ReserveMemory(vertices_size, vertex_stride))
|
||||
{
|
||||
Util::ExecuteCurrentCommandsAndRestoreState(true);
|
||||
if (!vbo_buf->ReserveMemory(vertices_size, vertex_stride))
|
||||
{
|
||||
PanicAlert("Failed to reserve vertex buffer space for utility draw.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
vertex_buffer = vbo_buf->GetBuffer();
|
||||
vertex_buffer_offset = vbo_buf->GetCurrentOffset();
|
||||
std::memcpy(vbo_buf->GetCurrentHostPointer(), vertices, vertices_size);
|
||||
vbo_buf->CommitMemory(vertices_size);
|
||||
}
|
||||
|
||||
// Allocate descriptor sets.
|
||||
std::array<VkDescriptorSet, 2> dsets;
|
||||
dsets[0] = g_command_buffer_mgr->AllocateDescriptorSet(
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_SINGLE_UNIFORM_BUFFER));
|
||||
dsets[1] = g_command_buffer_mgr->AllocateDescriptorSet(
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_PIXEL_SHADER_SAMPLERS));
|
||||
|
||||
// Flush first if failed.
|
||||
if (dsets[0] == VK_NULL_HANDLE || dsets[1] == VK_NULL_HANDLE)
|
||||
{
|
||||
Util::ExecuteCurrentCommandsAndRestoreState(true);
|
||||
dsets[0] = g_command_buffer_mgr->AllocateDescriptorSet(
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_SINGLE_UNIFORM_BUFFER));
|
||||
dsets[1] = g_command_buffer_mgr->AllocateDescriptorSet(
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_PIXEL_SHADER_SAMPLERS));
|
||||
|
||||
if (dsets[0] == VK_NULL_HANDLE || dsets[1] == VK_NULL_HANDLE)
|
||||
{
|
||||
PanicAlert("Failed to allocate descriptor sets in utility draw.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Build UBO descriptor set.
|
||||
std::array<VkWriteDescriptorSet, 2> dswrites;
|
||||
VkDescriptorBufferInfo dsbuffer = {uniform_buffer, 0, std::max(uniforms_size, 4u)};
|
||||
dswrites[0] = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, dsets[0], 0, 0, 1,
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, nullptr, &dsbuffer, nullptr};
|
||||
dswrites[1] = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
nullptr,
|
||||
dsets[1],
|
||||
0,
|
||||
0,
|
||||
NUM_PIXEL_SHADER_SAMPLERS,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
StateTracker::GetInstance()->GetPSSamplerBindings().data(),
|
||||
nullptr,
|
||||
nullptr};
|
||||
|
||||
// Build commands.
|
||||
VkCommandBuffer command_buffer = g_command_buffer_mgr->GetCurrentCommandBuffer();
|
||||
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
m_graphics_pipeline->GetPipeline());
|
||||
if (vertex_buffer != VK_NULL_HANDLE)
|
||||
vkCmdBindVertexBuffers(command_buffer, 0, 1, &vertex_buffer, &vertex_buffer_offset);
|
||||
|
||||
// Update and bind descriptors.
|
||||
VkPipelineLayout pipeline_layout = g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_UTILITY);
|
||||
vkUpdateDescriptorSets(g_vulkan_context->GetDevice(), static_cast<u32>(dswrites.size()),
|
||||
dswrites.data(), 0, nullptr);
|
||||
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
|
||||
static_cast<u32>(dsets.size()), dsets.data(), 1, &uniform_buffer_offset);
|
||||
|
||||
// Ensure we're in a render pass before drawing, just in case we had to flush.
|
||||
StateTracker::GetInstance()->BeginRenderPass();
|
||||
vkCmdDraw(command_buffer, num_vertices, 1, 0, 0);
|
||||
}
|
||||
|
||||
void Renderer::DispatchComputeShader(const AbstractShader* shader, const void* uniforms,
|
||||
u32 uniforms_size, u32 groups_x, u32 groups_y, u32 groups_z)
|
||||
{
|
||||
// Binding the utility pipeline layout breaks the standard layout.
|
||||
StateTracker::GetInstance()->SetPendingRebind();
|
||||
StateTracker::GetInstance()->EndRenderPass();
|
||||
|
||||
// Upload uniforms.
|
||||
VkBuffer uniform_buffer = g_object_cache->GetUtilityShaderUniformBuffer()->GetBuffer();
|
||||
u32 uniform_buffer_offset = 0;
|
||||
if (uniforms_size > 0)
|
||||
std::tie(uniform_buffer, uniform_buffer_offset) =
|
||||
UpdateUtilityUniformBuffer(uniforms, uniforms_size);
|
||||
|
||||
// Flush first if failed.
|
||||
VkDescriptorSet dset = g_command_buffer_mgr->AllocateDescriptorSet(
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_COMPUTE));
|
||||
if (dset == VK_NULL_HANDLE)
|
||||
{
|
||||
Util::ExecuteCurrentCommandsAndRestoreState(true);
|
||||
dset = g_command_buffer_mgr->AllocateDescriptorSet(
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_COMPUTE));
|
||||
if (dset == VK_NULL_HANDLE)
|
||||
{
|
||||
PanicAlert("Failed to allocate descriptor sets in utility dispatch.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::array<VkWriteDescriptorSet, 2> dswrites;
|
||||
VkDescriptorBufferInfo dsbuffer = {uniform_buffer, 0, std::max(uniforms_size, 4u)};
|
||||
dswrites[0] = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, dset, 0, 0, 1,
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, nullptr, &dsbuffer, nullptr};
|
||||
dswrites[1] = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
nullptr,
|
||||
dset,
|
||||
1,
|
||||
0,
|
||||
NUM_PIXEL_SHADER_SAMPLERS,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
StateTracker::GetInstance()->GetPSSamplerBindings().data(),
|
||||
nullptr,
|
||||
nullptr};
|
||||
|
||||
// TODO: Texel buffers, storage images.
|
||||
|
||||
// Build commands.
|
||||
VkCommandBuffer command_buffer = g_command_buffer_mgr->GetCurrentCommandBuffer();
|
||||
VkPipelineLayout pipeline_layout = g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_UTILITY);
|
||||
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE,
|
||||
static_cast<const VKShader*>(shader)->GetComputePipeline());
|
||||
vkUpdateDescriptorSets(g_vulkan_context->GetDevice(), static_cast<u32>(dswrites.size()),
|
||||
dswrites.data(), 0, nullptr);
|
||||
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1,
|
||||
&dset, 1, &uniform_buffer_offset);
|
||||
vkCmdDispatch(command_buffer, groups_x, groups_y, groups_z);
|
||||
}
|
||||
|
||||
void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
|
||||
{
|
||||
u32 backbuffer_width = m_swap_chain->GetWidth();
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoBackends/Vulkan/Constants.h"
|
||||
@ -22,6 +23,7 @@ class SwapChain;
|
||||
class StagingTexture2D;
|
||||
class Texture2D;
|
||||
class RasterFont;
|
||||
class VKPipeline;
|
||||
class VKTexture;
|
||||
|
||||
class Renderer : public ::Renderer
|
||||
@ -36,6 +38,12 @@ public:
|
||||
std::unique_ptr<AbstractStagingTexture>
|
||||
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
|
||||
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, const char* source,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length) override;
|
||||
std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config) override;
|
||||
|
||||
SwapChain* GetSwapChain() const { return m_swap_chain.get(); }
|
||||
BoundingBox* GetBoundingBox() const { return m_bounding_box.get(); }
|
||||
bool Initialize();
|
||||
@ -59,6 +67,7 @@ public:
|
||||
void ResetAPIState() override;
|
||||
void RestoreAPIState() override;
|
||||
|
||||
void SetPipeline(const AbstractPipeline* pipeline) override;
|
||||
void SetBlendingState(const BlendingState& state) override;
|
||||
void SetScissorRect(const MathUtil::Rectangle<int>& rc) override;
|
||||
void SetRasterizationState(const RasterizationState& state) override;
|
||||
@ -70,6 +79,11 @@ public:
|
||||
void SetViewport(float x, float y, float width, float height, float near_depth,
|
||||
float far_depth) override;
|
||||
|
||||
void DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices) override;
|
||||
void DispatchComputeShader(const AbstractShader* shader, const void* uniforms, u32 uniforms_size,
|
||||
u32 groups_x, u32 groups_y, u32 groups_z) override;
|
||||
|
||||
private:
|
||||
bool CreateSemaphores();
|
||||
void DestroySemaphores();
|
||||
@ -97,6 +111,8 @@ private:
|
||||
void BlitScreen(VkRenderPass render_pass, const TargetRectangle& dst_rect,
|
||||
const TargetRectangle& src_rect, const Texture2D* src_tex);
|
||||
|
||||
std::tuple<VkBuffer, u32> UpdateUtilityUniformBuffer(const void* uniforms, u32 uniforms_size);
|
||||
|
||||
VkSemaphore m_image_available_semaphore = VK_NULL_HANDLE;
|
||||
VkSemaphore m_rendering_finished_semaphore = VK_NULL_HANDLE;
|
||||
|
||||
@ -109,5 +125,6 @@ private:
|
||||
|
||||
// Shaders used for clear/blit.
|
||||
VkShaderModule m_clear_fragment_shader = VK_NULL_HANDLE;
|
||||
const VKPipeline* m_graphics_pipeline = nullptr;
|
||||
};
|
||||
}
|
||||
|
@ -1043,7 +1043,7 @@ bool StateTracker::UpdateDescriptorSet()
|
||||
m_descriptor_sets[DESCRIPTOR_SET_BIND_POINT_UNIFORM_BUFFERS] == VK_NULL_HANDLE)
|
||||
{
|
||||
VkDescriptorSetLayout layout =
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_UNIFORM_BUFFERS);
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_PER_STAGE_UNIFORM_BUFFERS);
|
||||
VkDescriptorSet set = g_command_buffer_mgr->AllocateDescriptorSet(layout);
|
||||
if (set == VK_NULL_HANDLE)
|
||||
return false;
|
||||
|
@ -41,6 +41,10 @@ public:
|
||||
}
|
||||
const DepthState& GetDepthStencilState() const { return m_pipeline_state.depth_state; }
|
||||
const BlendingState& GetBlendState() const { return m_pipeline_state.blend_state; }
|
||||
const std::array<VkDescriptorImageInfo, NUM_PIXEL_SHADER_SAMPLERS>& GetPSSamplerBindings() const
|
||||
{
|
||||
return m_bindings.ps_samplers;
|
||||
}
|
||||
void SetVertexBuffer(VkBuffer buffer, VkDeviceSize offset);
|
||||
void SetIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType type);
|
||||
|
||||
|
@ -566,7 +566,7 @@ void UtilityShaderDraw::BindDescriptors()
|
||||
if (m_vs_uniform_buffer.buffer != VK_NULL_HANDLE || m_ps_uniform_buffer.buffer != VK_NULL_HANDLE)
|
||||
{
|
||||
VkDescriptorSet set = g_command_buffer_mgr->AllocateDescriptorSet(
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_UNIFORM_BUFFERS));
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_PER_STAGE_UNIFORM_BUFFERS));
|
||||
if (set == VK_NULL_HANDLE)
|
||||
PanicAlert("Failed to allocate descriptor set for utility draw");
|
||||
|
||||
@ -595,7 +595,7 @@ void UtilityShaderDraw::BindDescriptors()
|
||||
&dummy_uniform_buffer,
|
||||
nullptr};
|
||||
|
||||
bind_descriptor_sets[DESCRIPTOR_SET_LAYOUT_UNIFORM_BUFFERS] = set;
|
||||
bind_descriptor_sets[DESCRIPTOR_SET_LAYOUT_PER_STAGE_UNIFORM_BUFFERS] = set;
|
||||
}
|
||||
|
||||
// PS samplers
|
||||
|
73
Source/Core/VideoBackends/Vulkan/VKPipeline.cpp
Normal file
73
Source/Core/VideoBackends/Vulkan/VKPipeline.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
|
||||
#include "VideoBackends/Vulkan/ObjectCache.h"
|
||||
#include "VideoBackends/Vulkan/Util.h"
|
||||
#include "VideoBackends/Vulkan/VKPipeline.h"
|
||||
#include "VideoBackends/Vulkan/VKShader.h"
|
||||
#include "VideoBackends/Vulkan/VertexFormat.h"
|
||||
#include "VideoBackends/Vulkan/VulkanContext.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
VKPipeline::VKPipeline(VkPipeline pipeline) : m_pipeline(pipeline)
|
||||
{
|
||||
}
|
||||
|
||||
VKPipeline::~VKPipeline()
|
||||
{
|
||||
vkDestroyPipeline(g_vulkan_context->GetDevice(), m_pipeline, nullptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<VKPipeline> VKPipeline::Create(const AbstractPipelineConfig& config)
|
||||
{
|
||||
_dbg_assert_(VIDEO, config.vertex_shader && config.pixel_shader);
|
||||
|
||||
// Get render pass for config.
|
||||
VkRenderPass render_pass = g_object_cache->GetRenderPass(
|
||||
Util::GetVkFormatForHostTextureFormat(config.framebuffer_state.color_texture_format),
|
||||
VK_FORMAT_UNDEFINED, config.framebuffer_state.samples, VK_ATTACHMENT_LOAD_OP_LOAD);
|
||||
|
||||
// Get pipeline layout.
|
||||
VkPipelineLayout pipeline_layout;
|
||||
switch (config.usage)
|
||||
{
|
||||
case AbstractPipelineUsage::GX:
|
||||
pipeline_layout = g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD);
|
||||
break;
|
||||
case AbstractPipelineUsage::Utility:
|
||||
pipeline_layout = g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_UTILITY);
|
||||
break;
|
||||
default:
|
||||
PanicAlert("Unknown pipeline layout.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: Move ShaderCache stuff to here.
|
||||
PipelineInfo pinfo;
|
||||
pinfo.vertex_format = static_cast<const VertexFormat*>(config.vertex_format);
|
||||
pinfo.pipeline_layout = pipeline_layout;
|
||||
pinfo.vs = static_cast<const VKShader*>(config.vertex_shader)->GetShaderModule();
|
||||
pinfo.ps = static_cast<const VKShader*>(config.pixel_shader)->GetShaderModule();
|
||||
pinfo.gs = config.geometry_shader ?
|
||||
static_cast<const VKShader*>(config.geometry_shader)->GetShaderModule() :
|
||||
VK_NULL_HANDLE;
|
||||
pinfo.render_pass = render_pass;
|
||||
pinfo.rasterization_state.hex = config.rasterization_state.hex;
|
||||
pinfo.depth_state.hex = config.depth_state.hex;
|
||||
pinfo.blend_state.hex = config.blending_state.hex;
|
||||
pinfo.multisampling_state.hex = 0;
|
||||
pinfo.multisampling_state.samples = config.framebuffer_state.samples;
|
||||
pinfo.multisampling_state.per_sample_shading = config.framebuffer_state.per_sample_shading;
|
||||
|
||||
VkPipeline pipeline = g_shader_cache->CreatePipeline(pinfo);
|
||||
if (pipeline == VK_NULL_HANDLE)
|
||||
return nullptr;
|
||||
|
||||
return std::make_unique<VKPipeline>(pipeline);
|
||||
}
|
||||
} // namespace Vulkan
|
27
Source/Core/VideoBackends/Vulkan/VKPipeline.h
Normal file
27
Source/Core/VideoBackends/Vulkan/VKPipeline.h
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "VideoBackends/Vulkan/VulkanLoader.h"
|
||||
#include "VideoCommon/AbstractPipeline.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
class VKPipeline final : public AbstractPipeline
|
||||
{
|
||||
public:
|
||||
explicit VKPipeline(VkPipeline pipeline);
|
||||
~VKPipeline() override;
|
||||
|
||||
VkPipeline GetPipeline() const { return m_pipeline; }
|
||||
static std::unique_ptr<VKPipeline> Create(const AbstractPipelineConfig& config);
|
||||
|
||||
private:
|
||||
VkPipeline m_pipeline;
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
124
Source/Core/VideoBackends/Vulkan/VKShader.cpp
Normal file
124
Source/Core/VideoBackends/Vulkan/VKShader.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Common/Assert.h"
|
||||
|
||||
#include "VideoBackends/Vulkan/ShaderCompiler.h"
|
||||
#include "VideoBackends/Vulkan/Util.h"
|
||||
#include "VideoBackends/Vulkan/VKShader.h"
|
||||
#include "VideoBackends/Vulkan/VulkanContext.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
VKShader::VKShader(ShaderStage stage, std::vector<u32> spv, VkShaderModule mod)
|
||||
: AbstractShader(stage), m_spv(std::move(spv)), m_module(mod),
|
||||
m_compute_pipeline(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
VKShader::VKShader(std::vector<u32> spv, VkPipeline compute_pipeline)
|
||||
: AbstractShader(ShaderStage::Compute), m_spv(std::move(spv)), m_module(VK_NULL_HANDLE),
|
||||
m_compute_pipeline(compute_pipeline)
|
||||
{
|
||||
}
|
||||
|
||||
VKShader::~VKShader()
|
||||
{
|
||||
if (m_stage != ShaderStage::Compute)
|
||||
vkDestroyShaderModule(g_vulkan_context->GetDevice(), m_module, nullptr);
|
||||
else
|
||||
vkDestroyPipeline(g_vulkan_context->GetDevice(), m_compute_pipeline, nullptr);
|
||||
}
|
||||
|
||||
bool VKShader::HasBinary() const
|
||||
{
|
||||
_assert_(!m_spv.empty());
|
||||
return true;
|
||||
}
|
||||
|
||||
AbstractShader::BinaryData VKShader::GetBinary() const
|
||||
{
|
||||
BinaryData ret(sizeof(u32) * m_spv.size());
|
||||
std::memcpy(ret.data(), m_spv.data(), sizeof(u32) * m_spv.size());
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::unique_ptr<VKShader> CreateShaderObject(ShaderStage stage,
|
||||
ShaderCompiler::SPIRVCodeVector spv)
|
||||
{
|
||||
VkShaderModule mod = Util::CreateShaderModule(spv.data(), spv.size());
|
||||
if (mod == VK_NULL_HANDLE)
|
||||
return nullptr;
|
||||
|
||||
// If it's a graphics shader, we defer pipeline creation.
|
||||
if (stage != ShaderStage::Compute)
|
||||
return std::make_unique<VKShader>(stage, std::move(spv), mod);
|
||||
|
||||
// If it's a compute shader, we create the pipeline straight away.
|
||||
ComputePipelineInfo pinfo;
|
||||
pinfo.pipeline_layout = g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_COMPUTE);
|
||||
pinfo.cs = mod;
|
||||
VkPipeline pipeline = g_shader_cache->CreateComputePipeline(pinfo);
|
||||
if (pipeline == VK_NULL_HANDLE)
|
||||
{
|
||||
vkDestroyShaderModule(g_vulkan_context->GetDevice(), mod, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Shader module is no longer needed, now it is compiled to a pipeline.
|
||||
return std::make_unique<VKShader>(std::move(spv), pipeline);
|
||||
}
|
||||
|
||||
std::unique_ptr<VKShader> VKShader::CreateFromSource(ShaderStage stage, const char* source,
|
||||
size_t length)
|
||||
{
|
||||
ShaderCompiler::SPIRVCodeVector spv;
|
||||
bool result;
|
||||
switch (stage)
|
||||
{
|
||||
case ShaderStage::Vertex:
|
||||
result = ShaderCompiler::CompileVertexShader(&spv, source, length);
|
||||
break;
|
||||
case ShaderStage::Geometry:
|
||||
result = ShaderCompiler::CompileGeometryShader(&spv, source, length);
|
||||
break;
|
||||
case ShaderStage::Pixel:
|
||||
result = ShaderCompiler::CompileFragmentShader(&spv, source, length);
|
||||
break;
|
||||
case ShaderStage::Compute:
|
||||
result = ShaderCompiler::CompileComputeShader(&spv, source, length);
|
||||
break;
|
||||
default:
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!result)
|
||||
return nullptr;
|
||||
|
||||
return CreateShaderObject(stage, std::move(spv));
|
||||
}
|
||||
|
||||
std::unique_ptr<VKShader> VKShader::CreateFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length)
|
||||
{
|
||||
ShaderCompiler::SPIRVCodeVector spv;
|
||||
const size_t size_in_words = sizeof(length) / sizeof(ShaderCompiler::SPIRVCodeType);
|
||||
if (size_in_words > 0)
|
||||
{
|
||||
spv.resize(length / size_in_words);
|
||||
std::memcpy(spv.data(), data, size_in_words);
|
||||
}
|
||||
|
||||
// Non-aligned code sizes, unlikely (unless using VK_NV_glsl).
|
||||
if ((length % sizeof(ShaderCompiler::SPIRVCodeType)) != 0)
|
||||
{
|
||||
spv.resize(size_in_words + 1);
|
||||
std::memcpy(&spv[size_in_words], data, (length % sizeof(ShaderCompiler::SPIRVCodeType)));
|
||||
}
|
||||
|
||||
return CreateShaderObject(stage, std::move(spv));
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
40
Source/Core/VideoBackends/Vulkan/VKShader.h
Normal file
40
Source/Core/VideoBackends/Vulkan/VKShader.h
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoBackends/Vulkan/VulkanLoader.h"
|
||||
#include "VideoCommon/AbstractShader.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
class VKShader final : public AbstractShader
|
||||
{
|
||||
public:
|
||||
VKShader(ShaderStage stage, std::vector<u32> spv, VkShaderModule mod);
|
||||
VKShader(std::vector<u32> spv, VkPipeline compute_pipeline);
|
||||
~VKShader() override;
|
||||
|
||||
VkShaderModule GetShaderModule() const { return m_module; }
|
||||
VkPipeline GetComputePipeline() const { return m_compute_pipeline; }
|
||||
bool HasBinary() const override;
|
||||
BinaryData GetBinary() const override;
|
||||
|
||||
static std::unique_ptr<VKShader> CreateFromSource(ShaderStage stage, const char* source,
|
||||
size_t length);
|
||||
static std::unique_ptr<VKShader> CreateFromBinary(ShaderStage stage, const void* data,
|
||||
size_t length);
|
||||
|
||||
private:
|
||||
std::vector<u32> m_spv;
|
||||
VkShaderModule m_module;
|
||||
VkPipeline m_compute_pipeline;
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
@ -57,6 +57,8 @@
|
||||
<ClCompile Include="Texture2D.cpp" />
|
||||
<ClCompile Include="TextureCache.cpp" />
|
||||
<ClCompile Include="VertexManager.cpp" />
|
||||
<ClCompile Include="VKPipeline.cpp" />
|
||||
<ClCompile Include="VKShader.cpp" />
|
||||
<ClCompile Include="VKTexture.cpp" />
|
||||
<ClCompile Include="VulkanContext.cpp" />
|
||||
<ClCompile Include="VulkanLoader.cpp" />
|
||||
@ -84,6 +86,8 @@
|
||||
<ClInclude Include="TextureCache.h" />
|
||||
<ClInclude Include="VertexManager.h" />
|
||||
<ClInclude Include="VideoBackend.h" />
|
||||
<ClInclude Include="VKPipeline.h" />
|
||||
<ClInclude Include="VKShader.h" />
|
||||
<ClInclude Include="VKTexture.h" />
|
||||
<ClInclude Include="VulkanContext.h" />
|
||||
<ClInclude Include="VulkanLoader.h" />
|
||||
|
95
Source/Core/VideoCommon/AbstractPipeline.h
Normal file
95
Source/Core/VideoCommon/AbstractPipeline.h
Normal file
@ -0,0 +1,95 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoCommon/RenderState.h"
|
||||
#include "VideoCommon/TextureConfig.h"
|
||||
|
||||
class AbstractShader;
|
||||
class NativeVertexFormat;
|
||||
|
||||
// We use three pipeline usages:
|
||||
// - GX
|
||||
// - Per-stage UBO (VS/GS/PS, VS constants accessible from PS)
|
||||
// - 8 combined image samplers (accessible from PS)
|
||||
// - 1 SSBO, accessible from PS if bounding box is enabled
|
||||
// - Utility
|
||||
// - Single UBO, accessible from all stages [set=0, binding=1]
|
||||
// - 8 combined image samplers (accessible from PS) [set=1, binding=0-7]
|
||||
// - 1 texel buffer, accessible from PS [set=2, binding=0]
|
||||
// - Compute
|
||||
// - 1 uniform buffer [set=0, binding=1]
|
||||
// - 8 combined image samplers [set=1, binding=0-7]
|
||||
// - 1 texel buffer [set=2, binding=0]
|
||||
// - 1 storage image [set=3, binding=0]
|
||||
enum class AbstractPipelineUsage
|
||||
{
|
||||
GX,
|
||||
Utility
|
||||
};
|
||||
|
||||
struct AbstractPipelineConfig
|
||||
{
|
||||
const NativeVertexFormat* vertex_format;
|
||||
const AbstractShader* vertex_shader;
|
||||
const AbstractShader* geometry_shader;
|
||||
const AbstractShader* pixel_shader;
|
||||
RasterizationState rasterization_state;
|
||||
DepthState depth_state;
|
||||
BlendingState blending_state;
|
||||
|
||||
union FramebufferState
|
||||
{
|
||||
BitField<0, 8, AbstractTextureFormat> color_texture_format;
|
||||
BitField<8, 8, AbstractTextureFormat> depth_texture_format;
|
||||
BitField<16, 8, u32> samples;
|
||||
BitField<24, 1, u32> per_sample_shading;
|
||||
|
||||
bool operator==(const FramebufferState& rhs) const { return hex == rhs.hex; }
|
||||
bool operator!=(const FramebufferState& rhs) const { return hex != rhs.hex; }
|
||||
FramebufferState& operator=(const FramebufferState& rhs)
|
||||
{
|
||||
hex = rhs.hex;
|
||||
return *this;
|
||||
}
|
||||
|
||||
u32 hex;
|
||||
} framebuffer_state;
|
||||
|
||||
AbstractPipelineUsage usage;
|
||||
|
||||
bool operator==(const AbstractPipelineConfig& rhs) const
|
||||
{
|
||||
return std::tie(vertex_format, vertex_shader, geometry_shader, pixel_shader,
|
||||
rasterization_state.hex, depth_state.hex, blending_state.hex,
|
||||
framebuffer_state.hex, usage) ==
|
||||
std::tie(rhs.vertex_format, rhs.vertex_shader, rhs.geometry_shader, rhs.pixel_shader,
|
||||
rhs.rasterization_state.hex, rhs.depth_state.hex, rhs.blending_state.hex,
|
||||
rhs.framebuffer_state.hex, rhs.usage);
|
||||
}
|
||||
bool operator!=(const AbstractPipelineConfig& rhs) const { return !operator==(rhs); }
|
||||
bool operator<(const AbstractPipelineConfig& rhs) const
|
||||
{
|
||||
return std::tie(vertex_format, vertex_shader, geometry_shader, pixel_shader,
|
||||
rasterization_state.hex, depth_state.hex, blending_state.hex,
|
||||
framebuffer_state.hex, usage) <
|
||||
std::tie(rhs.vertex_format, rhs.vertex_shader, rhs.geometry_shader, rhs.pixel_shader,
|
||||
rhs.rasterization_state.hex, rhs.depth_state.hex, rhs.blending_state.hex,
|
||||
rhs.framebuffer_state.hex, rhs.usage);
|
||||
}
|
||||
};
|
||||
|
||||
class AbstractPipeline
|
||||
{
|
||||
public:
|
||||
AbstractPipeline() = default;
|
||||
virtual ~AbstractPipeline() = default;
|
||||
};
|
34
Source/Core/VideoCommon/AbstractShader.h
Normal file
34
Source/Core/VideoCommon/AbstractShader.h
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
enum class ShaderStage
|
||||
{
|
||||
Vertex,
|
||||
Geometry,
|
||||
Pixel,
|
||||
Compute
|
||||
};
|
||||
|
||||
class AbstractShader
|
||||
{
|
||||
public:
|
||||
explicit AbstractShader(ShaderStage stage) : m_stage(stage) {}
|
||||
virtual ~AbstractShader() = default;
|
||||
|
||||
ShaderStage GetStage() const { return m_stage; }
|
||||
using BinaryData = std::vector<u8>;
|
||||
virtual bool HasBinary() const = 0;
|
||||
virtual BinaryData GetBinary() const = 0;
|
||||
|
||||
protected:
|
||||
ShaderStage m_stage;
|
||||
};
|
@ -33,10 +33,15 @@
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
|
||||
class AbstractRawTexture;
|
||||
class AbstractPipeline;
|
||||
class AbstractShader;
|
||||
class AbstractTexture;
|
||||
class AbstractStagingTexture;
|
||||
class PostProcessingShaderImplementation;
|
||||
struct TextureConfig;
|
||||
struct ComputePipelineConfig;
|
||||
struct AbstractPipelineConfig;
|
||||
enum class ShaderStage;
|
||||
enum class EFBAccessType;
|
||||
enum class StagingTextureType;
|
||||
|
||||
@ -69,6 +74,7 @@ public:
|
||||
PP_EFB_COPY_CLOCKS
|
||||
};
|
||||
|
||||
virtual void SetPipeline(const AbstractPipeline* pipeline) {}
|
||||
virtual void SetBlendingState(const BlendingState& state) {}
|
||||
virtual void SetScissorRect(const MathUtil::Rectangle<int>& rc) {}
|
||||
virtual void SetRasterizationState(const RasterizationState& state) {}
|
||||
@ -91,6 +97,14 @@ public:
|
||||
virtual std::unique_ptr<AbstractStagingTexture>
|
||||
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) = 0;
|
||||
|
||||
// Shader modules/objects.
|
||||
virtual std::unique_ptr<AbstractShader>
|
||||
CreateShaderFromSource(ShaderStage stage, const char* source, size_t length) = 0;
|
||||
virtual std::unique_ptr<AbstractShader>
|
||||
CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length) = 0;
|
||||
virtual std::unique_ptr<AbstractPipeline>
|
||||
CreatePipeline(const AbstractPipelineConfig& config) = 0;
|
||||
|
||||
// Ideal internal resolution - multiple of the native EFB resolution
|
||||
int GetTargetWidth() const { return m_target_width; }
|
||||
int GetTargetHeight() const { return m_target_height; }
|
||||
@ -160,6 +174,16 @@ public:
|
||||
|
||||
virtual void Shutdown();
|
||||
|
||||
// Drawing utility shaders.
|
||||
virtual void DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
}
|
||||
virtual void DispatchComputeShader(const AbstractShader* shader, const void* uniforms,
|
||||
u32 uniforms_size, u32 groups_x, u32 groups_y, u32 groups_z)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
std::tuple<int, int> CalculateTargetScale(int x, int y) const;
|
||||
bool CalculateTargetSize();
|
||||
|
@ -99,6 +99,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AbstractStagingTexture.h" />
|
||||
<ClInclude Include="AbstractPipeline.h" />
|
||||
<ClInclude Include="AbstractShader.h" />
|
||||
<ClInclude Include="AbstractTexture.h" />
|
||||
<ClInclude Include="AsyncRequests.h" />
|
||||
<ClInclude Include="AsyncShaderCompiler.h" />
|
||||
|
@ -374,6 +374,12 @@
|
||||
<ClInclude Include="AbstractStagingTexture.h">
|
||||
<Filter>Base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AbstractShader.h">
|
||||
<Filter>Base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AbstractPipeline.h">
|
||||
<Filter>Base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user