From 6e2fe72b8fe0bfd13171b43bcbff40b20d15737e Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 7 Oct 2013 17:52:22 +0200 Subject: [PATCH] D3D: also uses VideoCommon constant buffer handling As now both backends uses the VideoCommon one, the old setting API was removed. --- .../D3D/Src/PixelShaderCache.cpp | 23 +++-------- Source/Core/VideoBackends/D3D/Src/Render.h | 3 -- .../D3D/Src/VertexShaderCache.cpp | 39 +++---------------- Source/Core/VideoBackends/OGL/CMakeLists.txt | 2 - Source/Core/VideoBackends/OGL/OGL.vcxproj | 4 +- .../OGL/Src/PixelShaderCache.cpp | 31 --------------- Source/Core/VideoBackends/OGL/Src/Render.h | 3 -- .../OGL/Src/VertexShaderCache.cpp | 31 --------------- .../VideoCommon/Src/PixelShaderManager.cpp | 6 --- Source/Core/VideoCommon/Src/RenderBase.h | 4 -- .../VideoCommon/Src/VertexShaderManager.cpp | 6 --- 11 files changed, 13 insertions(+), 139 deletions(-) delete mode 100644 Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp delete mode 100644 Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp diff --git a/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp b/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp index 8109d7fd20..04a1722d04 100644 --- a/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/Src/PixelShaderCache.cpp @@ -14,15 +14,12 @@ #include "Globals.h" #include "PixelShaderGen.h" #include "PixelShaderCache.h" +#include "PixelShaderManager.h" #include "ConfigManager.h" extern int frameCount; -// See comment near the bottom of this file. -float psconstants[C_PENVCONST_END*4]; -bool pscbufchanged = true; - namespace DX11 { @@ -339,15 +336,15 @@ ID3D11PixelShader* PixelShaderCache::GetClearProgram() ID3D11Buffer* &PixelShaderCache::GetConstantBuffer() { // TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up - if (pscbufchanged) + if (PixelShaderManager::dirty) { D3D11_MAPPED_SUBRESOURCE map; D3D::context->Map(pscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); - memcpy(map.pData, psconstants, sizeof(psconstants)); + memcpy(map.pData, &PixelShaderManager::constants, sizeof(PixelShaderConstants)); D3D::context->Unmap(pscbuf, 0); - pscbufchanged = false; + PixelShaderManager::dirty = false; - ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(psconstants)); + ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(PixelShaderConstants)); } return pscbuf; } @@ -364,7 +361,7 @@ public: void PixelShaderCache::Init() { - unsigned int cbsize = ((sizeof(psconstants))&(~0xf))+0x10; // must be a multiple of 16 + unsigned int cbsize = ((sizeof(PixelShaderConstants))&(~0xf))+0x10; // must be a multiple of 16 D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); D3D::device->CreateBuffer(&cbdesc, NULL, &pscbuf); CHECK(pscbuf!=NULL, "Create pixel shader constant buffer"); @@ -536,12 +533,4 @@ bool PixelShaderCache::InsertByteCode(const PixelShaderUid &uid, const void* byt return true; } -// These are "callbacks" from VideoCommon and thus must be outside namespace DX11. -// This will have to be changed when we merge. -void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float* f) -{ - memcpy(psconstants, f, sizeof(float)*4*count); - pscbufchanged = true; -} - } // DX11 diff --git a/Source/Core/VideoBackends/D3D/Src/Render.h b/Source/Core/VideoBackends/D3D/Src/Render.h index c0090cd2f2..39b5b90d81 100644 --- a/Source/Core/VideoBackends/D3D/Src/Render.h +++ b/Source/Core/VideoBackends/D3D/Src/Render.h @@ -51,9 +51,6 @@ public: bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); static bool CheckForResize(); - - void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f); - void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f); }; } diff --git a/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp b/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp index 6f3c4051b1..28a03b3bca 100644 --- a/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/Src/VertexShaderCache.cpp @@ -12,14 +12,10 @@ #include "D3DShader.h" #include "Globals.h" #include "VertexShaderCache.h" +#include "VertexShaderManager.h" #include "ConfigManager.h" -// See comment near the bottom of this file -static unsigned int vs_constant_offset_table[C_VENVCONST_END]; -float vsconstants[C_VENVCONST_END*4]; -bool vscbufchanged = true; - namespace DX11 { VertexShaderCache::VSCache VertexShaderCache::vshaders; @@ -44,15 +40,15 @@ ID3D11Buffer* vscbuf = NULL; ID3D11Buffer* &VertexShaderCache::GetConstantBuffer() { // TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up - if (vscbufchanged) + if (VertexShaderManager::dirty) { D3D11_MAPPED_SUBRESOURCE map; D3D::context->Map(vscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); - memcpy(map.pData, vsconstants, sizeof(vsconstants)); + memcpy(map.pData, &VertexShaderManager::constants, sizeof(VertexShaderConstants)); D3D::context->Unmap(vscbuf, 0); - vscbufchanged = false; + VertexShaderManager::dirty = false; - ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(vsconstants)); + ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(VertexShaderConstants)); } return vscbuf; } @@ -116,7 +112,7 @@ void VertexShaderCache::Init() { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; - unsigned int cbsize = ((sizeof(vsconstants))&(~0xf))+0x10; // must be a multiple of 16 + unsigned int cbsize = ((sizeof(VertexShaderConstants))&(~0xf))+0x10; // must be a multiple of 16 D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); HRESULT hr = D3D::device->CreateBuffer(&cbdesc, NULL, &vscbuf); CHECK(hr==S_OK, "Create vertex shader constant buffer (size=%u)", cbsize); @@ -141,19 +137,6 @@ void VertexShaderCache::Init() Clear(); - // these values are hardcoded, they depend on internal D3DCompile behavior - // TODO: Do this with D3DReflect or something instead - unsigned int k; - for (k = 0;k < 6;k++) vs_constant_offset_table[C_POSNORMALMATRIX+k] = 0+4*k; - for (k = 0;k < 4;k++) vs_constant_offset_table[C_PROJECTION+k] = 24+4*k; - for (k = 0;k < 4;k++) vs_constant_offset_table[C_MATERIALS+k] = 40+4*k; - for (k = 0;k < 40;k++) vs_constant_offset_table[C_LIGHTS+k] = 56+4*k; - for (k = 0;k < 24;k++) vs_constant_offset_table[C_TEXMATRICES+k] = 216+4*k; - for (k = 0;k < 64;k++) vs_constant_offset_table[C_TRANSFORMMATRICES+k] = 312+4*k; - for (k = 0;k < 32;k++) vs_constant_offset_table[C_NORMALMATRICES+k] = 568+4*k; - for (k = 0;k < 64;k++) vs_constant_offset_table[C_POSTTRANSFORMMATRICES+k] = 696+4*k; - vs_constant_offset_table[C_DEPTHPARAMS] = 952; - if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX))) File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str()); @@ -277,14 +260,4 @@ bool VertexShaderCache::InsertByteCode(const VertexShaderUid &uid, D3DBlob* bcod return true; } -// These are "callbacks" from VideoCommon and thus must be outside namespace DX11. -// This will have to be changed when we merge. - -// TODO: fetch directly from VideoCommon -void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float* f) -{ - memcpy(&vsconstants[vs_constant_offset_table[const_number]], f, sizeof(float)*4*count); - vscbufchanged = true; -} - } // namespace DX11 diff --git a/Source/Core/VideoBackends/OGL/CMakeLists.txt b/Source/Core/VideoBackends/OGL/CMakeLists.txt index f3d7ce4e4f..3e1d2aaa60 100644 --- a/Source/Core/VideoBackends/OGL/CMakeLists.txt +++ b/Source/Core/VideoBackends/OGL/CMakeLists.txt @@ -3,7 +3,6 @@ set(SRCS Src/FramebufferManager.cpp Src/main.cpp Src/NativeVertexFormat.cpp Src/PerfQuery.cpp - Src/PixelShaderCache.cpp Src/PostProcessing.cpp Src/ProgramShaderCache.cpp Src/RasterFont.cpp @@ -12,7 +11,6 @@ set(SRCS Src/FramebufferManager.cpp Src/StreamBuffer.cpp Src/TextureCache.cpp Src/TextureConverter.cpp - Src/VertexShaderCache.cpp Src/VertexManager.cpp) set(LIBS videocommon diff --git a/Source/Core/VideoBackends/OGL/OGL.vcxproj b/Source/Core/VideoBackends/OGL/OGL.vcxproj index 69e23065c5..46113f53ce 100644 --- a/Source/Core/VideoBackends/OGL/OGL.vcxproj +++ b/Source/Core/VideoBackends/OGL/OGL.vcxproj @@ -151,7 +151,6 @@ - @@ -169,7 +168,6 @@ - @@ -203,4 +201,4 @@ - \ No newline at end of file + diff --git a/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp deleted file mode 100644 index ba6a0b2e97..0000000000 --- a/Source/Core/VideoBackends/OGL/Src/PixelShaderCache.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include "Globals.h" - -#include "GLUtil.h" - -#include - -#include "Statistics.h" -#include "VideoConfig.h" -#include "ImageWrite.h" -#include "Common.h" -#include "Render.h" -#include "VertexShaderGen.h" -#include "ProgramShaderCache.h" -#include "PixelShaderManager.h" -#include "OnScreenDisplay.h" -#include "StringUtil.h" -#include "FileUtil.h" -#include "Debugger.h" - -namespace OGL -{ - -// Renderer functions -void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) -{ -} -} // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/Src/Render.h b/Source/Core/VideoBackends/OGL/Src/Render.h index 6216097e79..8c6a8ca8f8 100644 --- a/Source/Core/VideoBackends/OGL/Src/Render.h +++ b/Source/Core/VideoBackends/OGL/Src/Render.h @@ -81,9 +81,6 @@ public: bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); - void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f); - void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f); - private: void UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc, const TargetRectangle& targetPixelRc, const u32* data); }; diff --git a/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp b/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp deleted file mode 100644 index c2c49b8505..0000000000 --- a/Source/Core/VideoBackends/OGL/Src/VertexShaderCache.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include - -#include "Globals.h" -#include "VideoConfig.h" -#include "Statistics.h" - -#include "GLUtil.h" - -#include "Render.h" -#include "VertexShaderGen.h" -#include "VertexShaderManager.h" -#include "ProgramShaderCache.h" -#include "VertexManager.h" -#include "VertexLoader.h" -#include "XFMemory.h" -#include "ImageWrite.h" -#include "FileUtil.h" -#include "Debugger.h" - -namespace OGL -{ - -void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) -{ -} - -} // namespace OGL diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index 970bdb6e58..46672758e4 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -355,12 +355,6 @@ void PixelShaderManager::SetConstants(u32 components) nMaterialsChanged = 0; } } - - if(dirty && g_ActiveConfig.backend_info.APIType != API_OPENGL) - { - g_renderer->SetMultiPSConstant4fv(0, sizeof(constants)/16, (float*) &constants); - dirty = false; - } } void PixelShaderManager::SetPSTextureDims(int texid) diff --git a/Source/Core/VideoCommon/Src/RenderBase.h b/Source/Core/VideoCommon/Src/RenderBase.h index 08ed80343d..4e093700a9 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.h +++ b/Source/Core/VideoCommon/Src/RenderBase.h @@ -115,10 +115,6 @@ public: static unsigned int GetPrevPixelFormat() { return prev_efb_format; } static void StorePixelFormat(unsigned int new_format) { prev_efb_format = new_format; } - // TODO: doesn't belong here - virtual void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) = 0; - virtual void SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) = 0; - protected: static void CalculateTargetScale(int x, int y, int &scaledX, int &scaledY); diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index 20c4994cf8..91be3597cd 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -517,12 +517,6 @@ void VertexShaderManager::SetConstants() SetMultiVSConstant4fv(C_PROJECTION, 4, correctedMtx.data); } } - - if(dirty && g_ActiveConfig.backend_info.APIType != API_OPENGL) - { - dirty = false; - g_renderer->SetMultiVSConstant4fv(0, sizeof(constants)/16, (float*) &constants); - } } void VertexShaderManager::InvalidateXFRange(int start, int end)