summaryrefslogtreecommitdiff
path: root/Source/Plugins/Plugin_VideoDX11
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2012-03-22 15:21:52 +0100
committerPierre Bourdon <delroth@gmail.com>2012-03-22 15:21:52 +0100
commit0ffc12bbfd6ac44b3030ec30f400a58e951087b7 (patch)
tree53a6fac9ec79bcd71fe2046d8fb579478da12fd2 /Source/Plugins/Plugin_VideoDX11
parent006923e871e496a7c6c0fe9ba76da4ee939ce14e (diff)
parentd95e31af3f779bfa3141047e8b6275e1fd2e4bbb (diff)
Merge branch 'master' into zcomploc-support
Conflicts: Source/Core/VideoCommon/Src/PixelShaderGen.cpp
Diffstat (limited to 'Source/Plugins/Plugin_VideoDX11')
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcxproj3
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp2
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp7
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp71
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h12
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp7
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/Render.cpp175
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/Render.h2
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp22
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp7
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp40
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h11
-rw-r--r--Source/Plugins/Plugin_VideoDX11/Src/main.cpp7
13 files changed, 224 insertions, 142 deletions
diff --git a/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcxproj b/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcxproj
index f1f4d40457..2903bd0550 100644
--- a/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcxproj
+++ b/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcxproj
@@ -46,7 +46,7 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
@@ -57,7 +57,6 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
- <WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp b/Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp
index 81a4cf96a6..8ee8081b2c 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp
@@ -595,7 +595,7 @@ void drawShadedTexSubQuad(ID3D11ShaderResourceView* texture,
// only upload the data to VRAM if it changed
if (stsq_observer ||
- memcmp(rDest, &tex_sub_quad_data.rdest, sizeof(rDest)) != 0 ||
+ memcmp(rDest, &tex_sub_quad_data.rdest, sizeof(*rDest)) != 0 ||
tex_sub_quad_data.u1 != u1 || tex_sub_quad_data.v1 != v1 ||
tex_sub_quad_data.u2 != u2 || tex_sub_quad_data.v2 != v2 || tex_sub_quad_data.G != G)
{
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp b/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp
index 25f3712eb1..3afd38a2e1 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/LineGeometryShader.cpp
@@ -187,14 +187,15 @@ bool LineGeometryShader::SetShader(u32 components, float lineWidth,
p = GenerateVSOutputStruct(p, components, API_D3D11);
p += sprintf(p, "\n%s", LINE_GS_COMMON);
- std::stringstream numTexCoordsStr;
- numTexCoordsStr << xfregs.numTexGen.numTexGens;
+ std::stringstream numTexCoordsStream;
+ numTexCoordsStream << xfregs.numTexGen.numTexGens;
INFO_LOG(VIDEO, "Compiling line geometry shader for components 0x%.08X (num texcoords %d)",
components, xfregs.numTexGen.numTexGens);
+ const std::string& numTexCoordsStr = numTexCoordsStream.str();
D3D_SHADER_MACRO macros[] = {
- { "NUM_TEXCOORDS", numTexCoordsStr.str().c_str() },
+ { "NUM_TEXCOORDS", numTexCoordsStr.c_str() },
{ NULL, NULL }
};
ID3D11GeometryShader* newShader = D3D::CompileAndCreateGeometryShader(code, unsigned int(strlen(code)), macros);
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp
index 5418923bf8..fe33c4db80 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp
@@ -41,6 +41,7 @@ namespace DX11
PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
const PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry;
+PIXELSHADERUID PixelShaderCache::last_uid;
LinearDiskCache<PIXELSHADERUID, u8> g_ps_disk_cache;
@@ -412,6 +413,11 @@ void PixelShaderCache::Init()
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
PixelShaderCacheInserter inserter;
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
+
+ if (g_Config.bEnableShaderDebugging)
+ Clear();
+
+ last_entry = NULL;
}
// ONLY to be used during shutdown.
@@ -420,6 +426,8 @@ void PixelShaderCache::Clear()
for (PSCache::iterator iter = PixelShaders.begin(); iter != PixelShaders.end(); iter++)
iter->second.Destroy();
PixelShaders.clear();
+
+ last_entry = NULL;
}
// Used in Swap() when AA mode has changed
@@ -454,28 +462,31 @@ void PixelShaderCache::Shutdown()
bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
{
PIXELSHADERUID uid;
- GetPixelShaderId(&uid, dstAlphaMode);
+ GetPixelShaderId(&uid, dstAlphaMode, components);
// Check if the shader is already set
- if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount)
+ if (last_entry)
{
- PSCache::const_iterator iter = PixelShaders.find(uid);
- GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
- return (iter != PixelShaders.end() && iter->second.shader);
+ if (uid == last_uid)
+ {
+ GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
+ ValidatePixelShaderIDs(API_D3D11, last_entry->safe_uid, last_entry->code, dstAlphaMode, components);
+ return (last_entry->shader != NULL);
+ }
}
- memcpy(&last_pixel_shader_uid, &uid, sizeof(PIXELSHADERUID));
+ last_uid = uid;
// Check if the shader is already in the cache
PSCache::iterator iter;
iter = PixelShaders.find(uid);
if (iter != PixelShaders.end())
{
- iter->second.frameCount = frameCount;
const PSCacheEntry &entry = iter->second;
last_entry = &entry;
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
+ ValidatePixelShaderIDs(API_D3D11, entry.safe_uid, entry.code, dstAlphaMode, components);
return (entry.shader != NULL);
}
@@ -485,36 +496,38 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
D3DBlob* pbytecode;
if (!D3D::CompilePixelShader(code, (unsigned int)strlen(code), &pbytecode))
{
- PanicAlert("Failed to compile Pixel Shader:\n\n%s", code);
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return false;
}
// Insert the bytecode into the caches
g_ps_disk_cache.Append(uid, pbytecode->Data(), pbytecode->Size());
- g_ps_disk_cache.Sync();
- bool result = InsertByteCode(uid, pbytecode->Data(), pbytecode->Size());
+ bool success = InsertByteCode(uid, pbytecode->Data(), pbytecode->Size());
pbytecode->Release();
+
+ if (g_ActiveConfig.bEnableShaderDebugging && success)
+ {
+ PixelShaders[uid].code = code;
+ GetSafePixelShaderId(&PixelShaders[uid].safe_uid, dstAlphaMode, components);
+ }
+
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
- return result;
+ return success;
}
bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const void* bytecode, unsigned int bytecodelen)
{
ID3D11PixelShader* shader = D3D::CreatePixelShaderFromByteCode(bytecode, bytecodelen);
if (shader == NULL)
- {
- PanicAlert("Failed to create pixel shader at %s %d\n", __FILE__, __LINE__);
return false;
- }
+
// TODO: Somehow make the debug name a bit more specific
D3D::SetDebugObjectName((ID3D11DeviceChild*)shader, "a pixel shader of PixelShaderCache");
// Make an entry in the table
PSCacheEntry newentry;
newentry.shader = shader;
- newentry.frameCount = frameCount;
PixelShaders[uid] = newentry;
last_entry = &PixelShaders[uid];
@@ -539,20 +552,22 @@ static const unsigned int ps_constant_offset_table[] = {
16, 20, 24, 28, // C_KCOLORS, 16
32, // C_ALPHA, 4
36, 40, 44, 48, 52, 56, 60, 64, // C_TEXDIMS, 32
- 68, 72, // C_ZBIAS, 8
- 76, 80, // C_INDTEXSCALE, 8
- 84, 88, 92, 96, 100, 104, // C_INDTEXMTX, 24
- 108, 112, 116, // C_FOG, 12
- 120, 124, 128, 132, 136, // C_PLIGHTS0, 20
- 140, 144, 148, 152, 156, // C_PLIGHTS1, 20
- 160, 164, 168, 172, 176, // C_PLIGHTS2, 20
- 180, 184, 188, 192, 196, // C_PLIGHTS3, 20
- 200, 204, 208, 212, 216, // C_PLIGHTS4, 20
- 220, 224, 228, 232, 236, // C_PLIGHTS5, 20
- 240, 244, 248, 252, 256, // C_PLIGHTS6, 20
- 260, 264, 268, 272, 276, // C_PLIGHTS7, 20
- 280, 284, 288, 292 // C_PMATERIALS, 16
+ 68, 72, 76, 80, // C_VTEXSCALE, 16 (unused)
+ 84, 88, // C_ZBIAS, 8
+ 92, 96, // C_INDTEXSCALE, 8
+ 100, 104, 108, 112, 116, 120, // C_INDTEXMTX, 24
+ 124, 128, 132, // C_FOG, 12
+ 136, 140, 144, 148, 152, // C_PLIGHTS0, 20
+ 156, 160, 164, 168, 172, // C_PLIGHTS1, 20
+ 176, 180, 184, 188, 192, // C_PLIGHTS2, 20
+ 196, 200, 204, 208, 212, // C_PLIGHTS3, 20
+ 216, 220, 224, 228, 232, // C_PLIGHTS4, 20
+ 236, 240, 244, 248, 252, // C_PLIGHTS5, 20
+ 256, 260, 264, 268, 272, // C_PLIGHTS6, 20
+ 276, 280, 284, 288, 292, // C_PLIGHTS7, 20
+ 296, 300, 304, 308, // C_PMATERIALS, 16
};
+
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
psconstants[ps_constant_offset_table[const_number] ] = f1;
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h
index 046f551657..874a47e4c1 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h
+++ b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h
@@ -17,11 +17,12 @@
#pragma once
-#include <map>
+#include "PixelShaderGen.h"
#include <d3d11.h>
-class PIXELSHADERUID;
+#include <map>
+
enum DSTALPHA_MODE;
namespace DX11
@@ -52,9 +53,11 @@ private:
struct PSCacheEntry
{
ID3D11PixelShader* shader;
- int frameCount;
- PSCacheEntry() : shader(NULL), frameCount(0) {}
+ PIXELSHADERUIDSAFE safe_uid;
+ std::string code;
+
+ PSCacheEntry() : shader(NULL) {}
void Destroy() { SAFE_RELEASE(shader); }
};
@@ -62,6 +65,7 @@ private:
static PSCache PixelShaders;
static const PSCacheEntry* last_entry;
+ static PIXELSHADERUID last_uid;
};
} // namespace DX11
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp b/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp
index fcf3315802..ad23786610 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/PointGeometryShader.cpp
@@ -181,14 +181,15 @@ bool PointGeometryShader::SetShader(u32 components, float pointSize,
p = GenerateVSOutputStruct(p, components, API_D3D11);
p += sprintf(p, "\n%s", POINT_GS_COMMON);
- std::stringstream numTexCoordsStr;
- numTexCoordsStr << xfregs.numTexGen.numTexGens;
+ std::stringstream numTexCoordsStream;
+ numTexCoordsStream << xfregs.numTexGen.numTexGens;
INFO_LOG(VIDEO, "Compiling point geometry shader for components 0x%.08X (num texcoords %d)",
components, xfregs.numTexGen.numTexGens);
+ const std::string& numTexCoordsStr = numTexCoordsStream.str();
D3D_SHADER_MACRO macros[] = {
- { "NUM_TEXCOORDS", numTexCoordsStr.str().c_str() },
+ { "NUM_TEXCOORDS", numTexCoordsStr.c_str() },
{ NULL, NULL }
};
ID3D11GeometryShader* newShader = D3D::CompileAndCreateGeometryShader(code, unsigned int(strlen(code)), macros);
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp
index d0756bfa98..69f0d0215a 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp
@@ -42,6 +42,8 @@
#include "Movie.h"
#include "Television.h"
#include "Host.h"
+#include "BPFunctions.h"
+#include "AVIDump.h"
namespace DX11
{
@@ -61,6 +63,8 @@ ID3D11BlendState* resetblendstate = NULL;
ID3D11DepthStencilState* resetdepthstate = NULL;
ID3D11RasterizerState* resetraststate = NULL;
+static ID3D11Texture2D* s_screenshot_texture = NULL;
+
// GX pipeline state
struct
{
@@ -295,9 +299,14 @@ void SetupDeviceObjects()
hr = D3D::device->CreateRasterizerState(&rastdesc, &resetraststate);
CHECK(hr==S_OK, "Create rasterizer state for Renderer::ResetAPIState");
D3D::SetDebugObjectName((ID3D11DeviceChild*)resetraststate, "rasterizer state for Renderer::ResetAPIState");
+
+ D3D11_TEXTURE2D_DESC scrtex_desc = CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight(), 1, 1, 0, D3D11_USAGE_STAGING, D3D11_CPU_ACCESS_READ|D3D11_CPU_ACCESS_WRITE);
+ hr = D3D::device->CreateTexture2D(&scrtex_desc, NULL, &s_screenshot_texture);
+ CHECK(hr==S_OK, "Create screenshot staging texture");
+ D3D::SetDebugObjectName((ID3D11DeviceChild*)s_screenshot_texture, "staging screenshot texture");
}
-// Kill off all POOL_DEFAULT device objects.
+// Kill off all device objects
void TeardownDeviceObjects()
{
delete g_framebuffer_manager;
@@ -313,6 +322,7 @@ void TeardownDeviceObjects()
SAFE_RELEASE(resetblendstate);
SAFE_RELEASE(resetdepthstate);
SAFE_RELEASE(resetraststate);
+ SAFE_RELEASE(s_screenshot_texture);
s_television.Shutdown();
}
@@ -343,6 +353,7 @@ Renderer::Renderer()
SetupDeviceObjects();
+
// Setup GX pipeline state
memset(&gx_state.blenddc, 0, sizeof(gx_state.blenddc));
gx_state.blenddc.AlphaToCoverageEnable = FALSE;
@@ -444,51 +455,9 @@ bool Renderer::CheckForResize()
return false;
}
-bool Renderer::SetScissorRect()
+void Renderer::SetScissorRect(const TargetRectangle& rc)
{
- TargetRectangle rc;
- GetScissorRect(rc);
-
- if (rc.left < 0) rc.left = 0;
- if (rc.right < 0) rc.right = 0;
- if (rc.top < 0) rc.top = 0;
- if (rc.bottom < 0) rc.bottom = 0;
-
- if (rc.left > EFB_WIDTH) rc.left = EFB_WIDTH;
- if (rc.right > EFB_WIDTH) rc.right = EFB_WIDTH;
- if (rc.top > EFB_HEIGHT) rc.top = EFB_HEIGHT;
- if (rc.bottom > EFB_HEIGHT) rc.bottom = EFB_HEIGHT;
-
- rc.left = EFBToScaledX(rc.left);
- rc.right = EFBToScaledX(rc.right);
- rc.top = EFBToScaledY(rc.top);
- rc.bottom = EFBToScaledY(rc.bottom);
-
- if (rc.left > rc.right)
- {
- int temp = rc.right;
- rc.right = rc.left;
- rc.left = temp;
- }
- if (rc.top > rc.bottom)
- {
- int temp = rc.bottom;
- rc.bottom = rc.top;
- rc.top = temp;
- }
-
- if (rc.right >= rc.left && rc.bottom >= rc.top)
- {
- D3D::context->RSSetScissorRects(1, rc.AsRECT());
- return true;
- }
- else
- {
- //WARN_LOG(VIDEO, "Bad scissor rectangle: %i %i %i %i", rc.left, rc.top, rc.right, rc.bottom);
- *rc.AsRECT() = CD3D11_RECT(0.f, 0.f, s_target_width, s_target_height);
- D3D::context->RSSetScissorRects(1, rc.AsRECT());
- return false;
- }
+ D3D::context->RSSetScissorRects(1, rc.AsRECT());
}
void Renderer::SetColorMask()
@@ -726,15 +695,18 @@ void Renderer::UpdateViewport(Matrix44& vpCorrection)
int Ht = intendedHt;
if (Y + Ht > GetTargetHeight())
Ht = GetTargetHeight() - Y;
-
+
// If GX viewport is off the render target, we must clamp our viewport
// within the bounds. Use the correction matrix to compensate.
ViewportCorrectionMatrix(vpCorrection,
- intendedX, intendedY, intendedWd, intendedHt,
- X, Y, Wd, Ht);
+ (float)intendedX, (float)intendedY,
+ (float)intendedWd, (float)intendedHt,
+ (float)X, (float)Y,
+ (float)Wd, (float)Ht);
// Some games set invalids values for z min and z max so fix them to the max an min alowed and let the shaders do this work
- D3D11_VIEWPORT vp = CD3D11_VIEWPORT(X, Y, Wd, Ht,
+ D3D11_VIEWPORT vp = CD3D11_VIEWPORT((float)X, (float)Y,
+ (float)Wd, (float)Ht,
0.f, // (xfregs.viewport.farZ - xfregs.viewport.zRange) / 16777216.0f;
1.f); // xfregs.viewport.farZ / 16777216.0f;
D3D::context->RSSetViewports(1, &vp);
@@ -779,7 +751,7 @@ void Renderer::ReinterpretPixelData(unsigned int convtype)
else if (convtype == 2) pixel_shader = PixelShaderCache::ReinterpRGBA6ToRGB8(true);
else
{
- PanicAlert("Trying to reinterpret pixel data with unsupported conversion type %d", convtype);
+ ERROR_LOG(VIDEO, "Trying to reinterpret pixel data with unsupported conversion type %d", convtype);
return;
}
@@ -876,15 +848,11 @@ void Renderer::SetBlendMode(bool forceUpdate)
bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle &rc)
{
// copy back buffer to system memory
- ID3D11Texture2D* buftex;
- D3D11_TEXTURE2D_DESC tex_desc = CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight(), 1, 1, 0, D3D11_USAGE_STAGING, D3D11_CPU_ACCESS_READ|D3D11_CPU_ACCESS_WRITE);
- HRESULT hr = D3D::device->CreateTexture2D(&tex_desc, NULL, &buftex);
- if (FAILED(hr)) PanicAlert("Failed to create screenshot buffer texture");
- D3D::context->CopyResource(buftex, (ID3D11Resource*)D3D::GetBackBuffer()->GetTex());
+ D3D::context->CopyResource(s_screenshot_texture, (ID3D11Resource*)D3D::GetBackBuffer()->GetTex());
// D3DX11SaveTextureToFileA doesn't allow us to ignore the alpha channel, so we need to strip it out ourselves
D3D11_MAPPED_SUBRESOURCE map;
- D3D::context->Map(buftex, 0, D3D11_MAP_READ_WRITE, 0, &map);
+ D3D::context->Map(s_screenshot_texture, 0, D3D11_MAP_READ_WRITE, 0, &map);
for (unsigned int y = 0; y < D3D::GetBackBufferHeight(); ++y)
{
u8* ptr = (u8*)map.pData + y * map.RowPitch + 3;
@@ -894,21 +862,38 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle
ptr += 4;
}
}
- D3D::context->Unmap(buftex, 0);
+ D3D::context->Unmap(s_screenshot_texture, 0);
// ready to be saved
- hr = PD3DX11SaveTextureToFileA(D3D::context, buftex, D3DX11_IFF_PNG, filename.c_str());
- buftex->Release();
+ HRESULT hr = PD3DX11SaveTextureToFileA(D3D::context, s_screenshot_texture, D3DX11_IFF_PNG, filename.c_str());
return SUCCEEDED(hr);
}
+void formatBufferDump(const char *in, char *out, int w, int h, int p)
+{
+ for (int y = 0; y < h; ++y)
+ {
+ const u8 *line = (u8*)(in + (h - y - 1) * p);
+ for (int x = 0; x < w; ++x)
+ {
+ out[0] = line[2];
+ out[1] = line[1];
+ out[2] = line[0];
+ out += 3;
+ line += 4;
+ }
+ }
+}
// This function has the final picture. We adjust the aspect ratio here.
void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma)
{
if (g_bSkipCurrentFrame || (!XFBWrited && (!g_ActiveConfig.bUseXFB || !g_ActiveConfig.bUseRealXFB)) || !fbWidth || !fbHeight)
{
+ if (g_ActiveConfig.bDumpFrames && frame_data)
+ AVIDump::AddFrame(frame_data);
+
Core::Callback_VideoCopiedToXFB(false);
return;
}
@@ -920,6 +905,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount);
if ((!xfbSourceList || xfbCount == 0) && g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB)
{
+ if (g_ActiveConfig.bDumpFrames && frame_data)
+ AVIDump::AddFrame(frame_data);
+
Core::Callback_VideoCopiedToXFB(false);
return;
}
@@ -1025,6 +1013,64 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
s_bScreenshot = false;
}
+ // Dump frames
+ static int w = 0, h = 0;
+ if (g_ActiveConfig.bDumpFrames)
+ {
+ static int s_recordWidth;
+ static int s_recordHeight;
+
+ D3D::context->CopyResource(s_screenshot_texture, (ID3D11Resource*)D3D::GetBackBuffer()->GetTex());
+ if (!bLastFrameDumped)
+ {
+ s_recordWidth = dst_rect.GetWidth();
+ s_recordHeight = dst_rect.GetHeight();
+ bAVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), s_recordWidth, s_recordHeight);
+ if (!bAVIDumping)
+ {
+ PanicAlert("Error dumping frames to AVI.");
+ }
+ else
+ {
+ char msg [255];
+ sprintf_s(msg,255, "Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)",
+ File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), s_recordWidth, s_recordHeight);
+ OSD::AddMessage(msg, 2000);
+ }
+ }
+ if (bAVIDumping)
+ {
+ D3D11_MAPPED_SUBRESOURCE map;
+ D3D::context->Map(s_screenshot_texture, 0, D3D11_MAP_READ, 0, &map);
+
+ if (!frame_data || w != s_recordWidth || h != s_recordHeight)
+ {
+ delete[] frame_data;
+ frame_data = new char[3 * s_recordWidth * s_recordHeight];
+ w = s_recordWidth;
+ h = s_recordHeight;
+ }
+ char* source_ptr = (char*)map.pData + dst_rect.left*4 + dst_rect.top*map.RowPitch;
+ formatBufferDump(source_ptr, frame_data, s_recordWidth, s_recordHeight, map.RowPitch);
+ AVIDump::AddFrame(frame_data);
+ D3D::context->Unmap(s_screenshot_texture, 0);
+ }
+ bLastFrameDumped = true;
+ }
+ else
+ {
+ if (bLastFrameDumped && bAVIDumping)
+ {
+ SAFE_DELETE_ARRAY(frame_data);
+ w = h = 0;
+
+ AVIDump::Stop();
+ bAVIDumping = false;
+ OSD::AddMessage("Stop dumping frames to AVI", 2000);
+ }
+ bLastFrameDumped = false;
+ }
+
// Finish up the current frame, print some stats
if (g_ActiveConfig.bShowFPS)
{
@@ -1063,12 +1109,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
DLCache::ProgressiveCleanup();
TextureCache::Cleanup();
- // reload textures if these settings changed
- if (g_Config.bSafeTextureCache != g_ActiveConfig.bSafeTextureCache ||
- g_Config.bUseNativeMips != g_ActiveConfig.bUseNativeMips)
+ // Reload textures if this settings changes
+ if (g_Config.bUseNativeMips != g_ActiveConfig.bUseNativeMips)
TextureCache::Invalidate(false);
- // Enable any configuration changes
+ // Enable configuration changes
UpdateActiveConfig();
SetWindowSize(fbWidth, fbHeight);
@@ -1163,7 +1208,7 @@ void Renderer::RestoreAPIState()
D3D::stateman->PopDepthState();
D3D::stateman->PopRasterizerState();
VertexShaderManager::SetViewportChanged();
- SetScissorRect();
+ BPFunctions::SetScissor();
}
void Renderer::ApplyState(bool bUseDstAlpha)
@@ -1385,4 +1430,4 @@ void Renderer::SetInterlacingMode()
// TODO
}
-} // namespace DX11 \ No newline at end of file
+} // namespace DX11
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.h b/Source/Plugins/Plugin_VideoDX11/Src/Render.h
index 5d1c24bc23..8f6c78fae1 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/Render.h
+++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.h
@@ -15,7 +15,7 @@ public:
void SetColorMask();
void SetBlendMode(bool forceUpdate);
- bool SetScissorRect();
+ void SetScissorRect(const TargetRectangle& rc);
void SetGenerationMode();
void SetDepthMode();
void SetLogicOpMode();
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp
index 39018c83bc..e59fbd496e 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp
@@ -102,12 +102,12 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
const float *colmat)
{
- if (!isDynamic || g_ActiveConfig.bCopyEFBToTexture)
+ if (type != TCET_EC_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture)
{
g_renderer->ResetAPIState();
// stretch picture with increased internal resolution
- const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)virtualW, (float)virtualH);
+ const D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)virtual_width, (float)virtual_height);
D3D::context->RSSetViewports(1, &vp);
// set transformation
@@ -149,17 +149,15 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
if (!g_ActiveConfig.bCopyEFBToTexture)
{
u8* dst = Memory::GetPointer(dstAddr);
- size_t encodeSize = g_encoder->Encode(dst, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf);
- hash = GetHash64(dst, encodeSize, g_ActiveConfig.iSafeTextureCache_ColorSamples);
- if (g_ActiveConfig.bEFBCopyCacheEnable)
- {
- // If the texture in RAM is already in the texture cache,
- // do not copy it again as it has not changed.
- if (TextureCache::Find(dstAddr, hash))
- return;
- }
+ size_t encoded_size = g_encoder->Encode(dst, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf);
+
+ hash = GetHash64(dst, (int)encoded_size, g_ActiveConfig.iSafeTextureCache_ColorSamples);
- TextureCache::MakeRangeDynamic(dstAddr, encodeSize);
+ // Mark texture entries in destination address range dynamic unless caching is enabled and the texture entry is up to date
+ if (!g_ActiveConfig.bEFBCopyCacheEnable)
+ TextureCache::MakeRangeDynamic(addr, (u32)encoded_size);
+ else if (!TextureCache::Find(addr, hash))
+ TextureCache::MakeRangeDynamic(addr, (u32)encoded_size);
}
}
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp
index e1e40047e4..1079863347 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp
@@ -228,12 +228,13 @@ void VertexManager::vFlush()
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
tex.texTlut[i&3].tlut_format,
(tex.texMode0[i&3].min_filter & 3) && (tex.texMode0[i&3].min_filter != 8) && g_ActiveConfig.bUseNativeMips,
- (tex.texMode1[i&3].max_lod >> 4));
+ tex.texMode1[i&3].max_lod >> 4,
+ tex.texImage1[i&3].image_type);
if (tentry)
{
// 0s are probably for no manual wrapping needed.
- PixelShaderManager::SetTexDims(i, tentry->realW, tentry->realH, 0, 0);
+ PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, tentry->virtual_width, tentry->virtual_height, 0, 0, API_D3D11);
}
else
ERROR_LOG(VIDEO, "error loading texture");
@@ -242,7 +243,7 @@ void VertexManager::vFlush()
// set global constants
VertexShaderManager::SetConstants();
- PixelShaderManager::SetConstants();
+ PixelShaderManager::SetConstants(API_D3D11);
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp
index 041caba28c..d727ce1ebf 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp
@@ -37,6 +37,7 @@ namespace DX11 {
VertexShaderCache::VSCache VertexShaderCache::vshaders;
const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry;
+VERTEXSHADERUID VertexShaderCache::last_uid;
static ID3D11VertexShader* SimpleVertexShader = NULL;
static ID3D11VertexShader* ClearVertexShader = NULL;
@@ -174,6 +175,11 @@ void VertexShaderCache::Init()
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
VertexShaderCacheInserter inserter;
g_vs_disk_cache.OpenAndRead(cache_filename, inserter);
+
+ if (g_Config.bEnableShaderDebugging)
+ Clear();
+
+ last_entry = NULL;
}
void VertexShaderCache::Clear()
@@ -181,6 +187,8 @@ void VertexShaderCache::Clear()
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
iter->second.Destroy();
vshaders.clear();
+
+ last_entry = NULL;
}
void VertexShaderCache::Shutdown()
@@ -202,22 +210,26 @@ bool VertexShaderCache::SetShader(u32 components)
{
VERTEXSHADERUID uid;
GetVertexShaderId(&uid, components);
- if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount)
+ if (last_entry)
{
- GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
- return (vshaders[uid].shader != NULL);
+ if (uid == last_uid)
+ {
+ GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
+ ValidateVertexShaderIDs(API_D3D11, last_entry->safe_uid, last_entry->code, components);
+ return (last_entry->shader != NULL);
+ }
}
- memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID));
+ last_uid = uid;
VSCache::iterator iter = vshaders.find(uid);
if (iter != vshaders.end())
{
- iter->second.frameCount = frameCount;
const VSCacheEntry &entry = iter->second;
last_entry = &entry;
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
+ ValidateVertexShaderIDs(API_D3D11, entry.safe_uid, entry.code, components);
return (entry.shader != NULL);
}
@@ -228,34 +240,36 @@ bool VertexShaderCache::SetShader(u32 components)
if (pbytecode == NULL)
{
- PanicAlert("Failed to compile Vertex Shader %s %d:\n\n%s", __FILE__, __LINE__, code);
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return false;
}
g_vs_disk_cache.Append(uid, pbytecode->Data(), pbytecode->Size());
- g_vs_disk_cache.Sync();
- bool result = InsertByteCode(uid, pbytecode);
+ bool success = InsertByteCode(uid, pbytecode);
pbytecode->Release();
+
+ if (g_ActiveConfig.bEnableShaderDebugging && success)
+ {
+ vshaders[uid].code = code;
+ GetSafeVertexShaderId(&vshaders[uid].safe_uid, components);
+ }
+
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
- return result;
+ return success;
}
bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, D3DBlob* bcodeblob)
{
ID3D11VertexShader* shader = D3D::CreateVertexShaderFromByteCode(bcodeblob);
if (shader == NULL)
- {
- PanicAlert("Failed to create vertex shader from %p size %d at %s %d\n", bcodeblob->Data(), bcodeblob->Size(), __FILE__, __LINE__);
return false;
- }
+
// TODO: Somehow make the debug name a bit more specific
D3D::SetDebugObjectName((ID3D11DeviceChild*)shader, "a vertex shader of VertexShaderCache");
// Make an entry in the table
VSCacheEntry entry;
entry.shader = shader;
- entry.frameCount = frameCount;
entry.SetByteCode(bcodeblob);
vshaders[uid] = entry;
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h
index 3c7dadd3e7..6d9537606a 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h
+++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h
@@ -18,12 +18,12 @@
#ifndef _VERTEXSHADERCACHE_H
#define _VERTEXSHADERCACHE_H
-#include <map>
+#include "VertexShaderGen.h"
#include "D3DBase.h"
#include "D3DBlob.h"
-class VERTEXSHADERUID;
+#include <map>
namespace DX11 {
@@ -51,9 +51,11 @@ private:
{
ID3D11VertexShader* shader;
D3DBlob* bytecode; // needed to initialize the input layout
- int frameCount;
- VSCacheEntry() : shader(NULL), bytecode(NULL), frameCount(0) {}
+ VERTEXSHADERUIDSAFE safe_uid;
+ std::string code;
+
+ VSCacheEntry() : shader(NULL), bytecode(NULL) {}
void SetByteCode(D3DBlob* blob)
{
SAFE_RELEASE(bytecode);
@@ -70,6 +72,7 @@ private:
static VSCache vshaders;
static const VSCacheEntry* last_entry;
+ static VERTEXSHADERUID last_uid;
};
} // namespace DX11
diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp
index ba93890e2b..ba3a67108b 100644
--- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp
+++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp
@@ -68,9 +68,9 @@ unsigned int VideoBackend::PeekMessages()
void VideoBackend::UpdateFPSDisplay(const char *text)
{
- char temp[512];
- sprintf_s(temp, sizeof temp, "%s | DX11 | %s", scm_rev_str, text);
- SetWindowTextA(EmuWindow::GetWnd(), temp);
+ TCHAR temp[512];
+ swprintf_s(temp, sizeof(temp)/sizeof(TCHAR), _T("%hs | DX11 | %hs"), scm_rev_str, text);
+ EmuWindow::SetWindowText(temp);
}
std::string VideoBackend::GetName()
@@ -150,6 +150,7 @@ void VideoBackend::ShowConfig(void *_hParent)
bool VideoBackend::Initialize(void *&window_handle)
{
+ InitializeShared();
InitBackendInfo();
frameCount = 0;