D3D: also uses VideoCommon constant buffer handling

As now both backends uses the VideoCommon one, the old setting API was removed.
This commit is contained in:
degasus 2013-10-07 17:52:22 +02:00
parent 7c14463d11
commit 6e2fe72b8f
11 changed files with 13 additions and 139 deletions

View File

@ -14,15 +14,12 @@
#include "Globals.h" #include "Globals.h"
#include "PixelShaderGen.h" #include "PixelShaderGen.h"
#include "PixelShaderCache.h" #include "PixelShaderCache.h"
#include "PixelShaderManager.h"
#include "ConfigManager.h" #include "ConfigManager.h"
extern int frameCount; extern int frameCount;
// See comment near the bottom of this file.
float psconstants[C_PENVCONST_END*4];
bool pscbufchanged = true;
namespace DX11 namespace DX11
{ {
@ -339,15 +336,15 @@ ID3D11PixelShader* PixelShaderCache::GetClearProgram()
ID3D11Buffer* &PixelShaderCache::GetConstantBuffer() ID3D11Buffer* &PixelShaderCache::GetConstantBuffer()
{ {
// TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up // 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; D3D11_MAPPED_SUBRESOURCE map;
D3D::context->Map(pscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &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); D3D::context->Unmap(pscbuf, 0);
pscbufchanged = false; PixelShaderManager::dirty = false;
ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(psconstants)); ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(PixelShaderConstants));
} }
return pscbuf; return pscbuf;
} }
@ -364,7 +361,7 @@ public:
void PixelShaderCache::Init() 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); 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); D3D::device->CreateBuffer(&cbdesc, NULL, &pscbuf);
CHECK(pscbuf!=NULL, "Create pixel shader constant buffer"); CHECK(pscbuf!=NULL, "Create pixel shader constant buffer");
@ -536,12 +533,4 @@ bool PixelShaderCache::InsertByteCode(const PixelShaderUid &uid, const void* byt
return true; 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 } // DX11

View File

@ -51,9 +51,6 @@ public:
bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc);
static bool CheckForResize(); 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);
}; };
} }

View File

@ -12,14 +12,10 @@
#include "D3DShader.h" #include "D3DShader.h"
#include "Globals.h" #include "Globals.h"
#include "VertexShaderCache.h" #include "VertexShaderCache.h"
#include "VertexShaderManager.h"
#include "ConfigManager.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 { namespace DX11 {
VertexShaderCache::VSCache VertexShaderCache::vshaders; VertexShaderCache::VSCache VertexShaderCache::vshaders;
@ -44,15 +40,15 @@ ID3D11Buffer* vscbuf = NULL;
ID3D11Buffer* &VertexShaderCache::GetConstantBuffer() ID3D11Buffer* &VertexShaderCache::GetConstantBuffer()
{ {
// TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up // 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; D3D11_MAPPED_SUBRESOURCE map;
D3D::context->Map(vscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &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); D3D::context->Unmap(vscbuf, 0);
vscbufchanged = false; VertexShaderManager::dirty = false;
ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(vsconstants)); ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(VertexShaderConstants));
} }
return vscbuf; return vscbuf;
} }
@ -116,7 +112,7 @@ void VertexShaderCache::Init()
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "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); 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); HRESULT hr = D3D::device->CreateBuffer(&cbdesc, NULL, &vscbuf);
CHECK(hr==S_OK, "Create vertex shader constant buffer (size=%u)", cbsize); CHECK(hr==S_OK, "Create vertex shader constant buffer (size=%u)", cbsize);
@ -141,19 +137,6 @@ void VertexShaderCache::Init()
Clear(); 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))) if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str()); File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str());
@ -277,14 +260,4 @@ bool VertexShaderCache::InsertByteCode(const VertexShaderUid &uid, D3DBlob* bcod
return true; 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 } // namespace DX11

View File

@ -3,7 +3,6 @@ set(SRCS Src/FramebufferManager.cpp
Src/main.cpp Src/main.cpp
Src/NativeVertexFormat.cpp Src/NativeVertexFormat.cpp
Src/PerfQuery.cpp Src/PerfQuery.cpp
Src/PixelShaderCache.cpp
Src/PostProcessing.cpp Src/PostProcessing.cpp
Src/ProgramShaderCache.cpp Src/ProgramShaderCache.cpp
Src/RasterFont.cpp Src/RasterFont.cpp
@ -12,7 +11,6 @@ set(SRCS Src/FramebufferManager.cpp
Src/StreamBuffer.cpp Src/StreamBuffer.cpp
Src/TextureCache.cpp Src/TextureCache.cpp
Src/TextureConverter.cpp Src/TextureConverter.cpp
Src/VertexShaderCache.cpp
Src/VertexManager.cpp) Src/VertexManager.cpp)
set(LIBS videocommon set(LIBS videocommon

View File

@ -151,7 +151,6 @@
<ClCompile Include="Src\main.cpp" /> <ClCompile Include="Src\main.cpp" />
<ClCompile Include="Src\NativeVertexFormat.cpp" /> <ClCompile Include="Src\NativeVertexFormat.cpp" />
<ClCompile Include="Src\PerfQuery.cpp" /> <ClCompile Include="Src\PerfQuery.cpp" />
<ClCompile Include="Src\PixelShaderCache.cpp" />
<ClCompile Include="Src\PostProcessing.cpp" /> <ClCompile Include="Src\PostProcessing.cpp" />
<ClCompile Include="Src\ProgramShaderCache.cpp" /> <ClCompile Include="Src\ProgramShaderCache.cpp" />
<ClCompile Include="Src\RasterFont.cpp" /> <ClCompile Include="Src\RasterFont.cpp" />
@ -169,7 +168,6 @@
<ClCompile Include="Src\TextureCache.cpp" /> <ClCompile Include="Src\TextureCache.cpp" />
<ClCompile Include="Src\TextureConverter.cpp" /> <ClCompile Include="Src\TextureConverter.cpp" />
<ClCompile Include="Src\VertexManager.cpp" /> <ClCompile Include="Src\VertexManager.cpp" />
<ClCompile Include="Src\VertexShaderCache.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Src\FramebufferManager.h" /> <ClInclude Include="Src\FramebufferManager.h" />
@ -203,4 +201,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@ -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 <cmath>
#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

View File

@ -81,9 +81,6 @@ public:
bool SaveScreenshot(const std::string &filename, const TargetRectangle &rc); 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: private:
void UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc, const TargetRectangle& targetPixelRc, const u32* data); void UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc, const TargetRectangle& targetPixelRc, const u32* data);
}; };

View File

@ -1,31 +0,0 @@
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <math.h>
#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

View File

@ -355,12 +355,6 @@ void PixelShaderManager::SetConstants(u32 components)
nMaterialsChanged = 0; 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) void PixelShaderManager::SetPSTextureDims(int texid)

View File

@ -115,10 +115,6 @@ public:
static unsigned int GetPrevPixelFormat() { return prev_efb_format; } static unsigned int GetPrevPixelFormat() { return prev_efb_format; }
static void StorePixelFormat(unsigned int new_format) { prev_efb_format = new_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: protected:
static void CalculateTargetScale(int x, int y, int &scaledX, int &scaledY); static void CalculateTargetScale(int x, int y, int &scaledX, int &scaledY);

View File

@ -517,12 +517,6 @@ void VertexShaderManager::SetConstants()
SetMultiVSConstant4fv(C_PROJECTION, 4, correctedMtx.data); 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) void VertexShaderManager::InvalidateXFRange(int start, int end)