diff --git a/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcproj b/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcproj index af6fc88931..5677d98180 100644 --- a/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcproj +++ b/Source/Plugins/Plugin_VideoDX11/Plugin_VideoDX11.vcproj @@ -91,7 +91,7 @@ ClearState(); - - if (gfxstate) delete gfxstate; SAFE_RELEASE(backbuf); - SAFE_RELEASE(context); + if (gfxstate) delete gfxstate; SAFE_RELEASE(swapchain); + context->Flush(); // immediately destroy device objects + + SAFE_RELEASE(context); ULONG references = device->Release(); if (references) { @@ -403,12 +404,31 @@ unsigned int GetBackBufferHeight() { return yres; } void Reset() { - DXGI_SWAP_CHAIN_DESC desc; - D3D::swapchain->ResizeBuffers(1, 0, 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0); - swapchain->GetDesc(&desc); - xres = desc.BufferDesc.Width; - yres = desc.BufferDesc.Height; - // TODO: Check whether we need to do anything here + // release all back buffer references + SAFE_RELEASE(backbuf); + + // resize swapchain buffers + RECT client; + GetClientRect(hWnd, &client); + xres = client.right - client.left; + yres = client.bottom - client.top; + D3D::swapchain->ResizeBuffers(1, xres, yres, DXGI_FORMAT_R8G8B8A8_UNORM, 0); + + // recreate back buffer texture + ID3D11Texture2D* buf; + HRESULT hr = swapchain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&buf); + if (FAILED(hr)) + { + MessageBox(hWnd, _T("Failed to get swapchain buffer"), _T("Dolphin Direct3D 11 plugin"), MB_OK | MB_ICONERROR); + device->Release(); + context->Release(); + swapchain->Release(); + return; + } + backbuf = new D3DTexture2D(buf, D3D11_BIND_RENDER_TARGET); + buf->Release(); + SetDebugObjectName((ID3D11DeviceChild*)backbuf->GetTex(), "backbuffer texture"); + SetDebugObjectName((ID3D11DeviceChild*)backbuf->GetRTV(), "backbuffer render target view"); } bool BeginFrame() diff --git a/Source/Plugins/Plugin_VideoDX11/Src/D3DTexture.cpp b/Source/Plugins/Plugin_VideoDX11/Src/D3DTexture.cpp index e4c86cce91..1c9a318d08 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/D3DTexture.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/D3DTexture.cpp @@ -45,7 +45,7 @@ void ReplaceTexture2D(ID3D11Texture2D* pTexture, const u8* buffer, unsigned int if (usage == D3D11_USAGE_DYNAMIC || usage == D3D11_USAGE_STAGING) { - if (level != 0) PanicAlert("Dynamic textures don't support mipmaps, but given level is not 0 at %s %d\n", __FILE__, __LINE__); + if (usage == D3D11_USAGE_DYNAMIC && level != 0) PanicAlert("Dynamic textures don't support mipmaps, but given level is not 0 at %s %d\n", __FILE__, __LINE__); D3D11_MAPPED_SUBRESOURCE map; D3D::context->Map(pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); outptr = (u8*)map.pData; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp b/Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp index 7dd8f754cc..b655e12f9d 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/D3DUtil.cpp @@ -174,6 +174,7 @@ int CD3DFont::Init() PanicAlert("Failed to create font texture"); return hr; } + D3D::SetDebugObjectName((ID3D11DeviceChild*)buftex, "texture of a CD3DFont object"); // lock the surface and write the alpha values for the set pixels D3D11_MAPPED_SUBRESOURCE texmap; @@ -205,12 +206,14 @@ int CD3DFont::Init() // setup device objects for drawing m_pshader = D3D::CompileAndCreatePixelShader(fontpixshader, sizeof(fontpixshader)); if (m_pshader == NULL) PanicAlert("Failed to create pixel shader, %s %d\n", __FILE__, __LINE__); + D3D::SetDebugObjectName((ID3D11DeviceChild*)m_pshader, "pixel shader of a CD3DFont object"); D3DBlob* vsbytecode; D3D::CompileVertexShader(fontvertshader, sizeof(fontvertshader), &vsbytecode); if (vsbytecode == NULL) PanicAlert("Failed to compile vertex shader, %s %d\n", __FILE__, __LINE__); m_vshader = D3D::CreateVertexShaderFromByteCode(vsbytecode); if (m_vshader == NULL) PanicAlert("Failed to create vertex shader, %s %d\n", __FILE__, __LINE__); + D3D::SetDebugObjectName((ID3D11DeviceChild*)m_vshader, "vertex shader of a CD3DFont object"); const D3D11_INPUT_ELEMENT_DESC desc[] = { @@ -234,10 +237,12 @@ int CD3DFont::Init() blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; blenddesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; D3D::device->CreateBlendState(&blenddesc, &m_blendstate); + D3D::SetDebugObjectName((ID3D11DeviceChild*)m_blendstate, "blend state of a CD3DFont object"); // this might need to be changed when adding multisampling support D3D11_RASTERIZER_DESC rastdesc = CD3D11_RASTERIZER_DESC(D3D11_FILL_SOLID, D3D11_CULL_NONE, false, 0, 0.f, 0.f, false, false, false, false); D3D::device->CreateRasterizerState(&rastdesc, &m_raststate); + D3D::SetDebugObjectName((ID3D11DeviceChild*)m_raststate, "rasterizer state of a CD3DFont object"); D3D11_BUFFER_DESC vbdesc = CD3D11_BUFFER_DESC(MAX_NUM_VERTICES*sizeof(FONT2DVERTEX), D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); if (FAILED(hr = device->CreateBuffer(&vbdesc, NULL, &m_pVB))) @@ -245,6 +250,7 @@ int CD3DFont::Init() PanicAlert("Failed to create vertex buffer!\n"); return hr; } + D3D::SetDebugObjectName((ID3D11DeviceChild*)m_pVB, "vertex buffer of a CD3DFont object"); return S_OK; } diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp index 265dc76a7a..8d3752b80f 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp @@ -166,15 +166,19 @@ void PixelShaderCache::Init() { // used when drawing clear quads s_ClearProgram = D3D::CompileAndCreatePixelShader(clear_program_code, strlen(clear_program_code)); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ClearProgram, "clear pixel shader"); // used when copying/resolving the color buffer s_ColorCopyProgram = D3D::CompileAndCreatePixelShader(color_copy_program_code, strlen(color_copy_program_code)); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ClearProgram, "color copy pixel shader"); // used for color conversion s_ColorMatrixProgram = D3D::CompileAndCreatePixelShader(color_matrix_program_code, strlen(color_matrix_program_code)); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ClearProgram, "color matrix pixel shader"); // used for depth copy s_DepthMatrixProgram = D3D::CompileAndCreatePixelShader(depth_matrix_program, strlen(depth_matrix_program)); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ClearProgram, "depth matrix pixel shader"); Clear(); @@ -262,6 +266,8 @@ bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, void* bytecode, 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; @@ -274,4 +280,4 @@ bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, void* bytecode, SETSTAT(stats.numPixelShadersAlive, PixelShaders.size()); return true; -} +} \ No newline at end of file diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp index 9107c03419..719ac61c49 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp @@ -70,6 +70,10 @@ static float yScale; static u32 s_blendMode; static bool XFBWrited; +static bool s_bScreenshot = false; +static Common::CriticalSection s_criticalScreenshot; +static char s_sScreenshotName[1024]; + ID3D11Buffer* access_efb_cbuf = NULL; ID3D11DepthStencilState* cleardepthstates[2] = {NULL}; ID3D11RasterizerState* clearraststate = NULL; @@ -873,6 +877,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) D3D::drawShadedTexSubQuad(xfbSource->tex->GetSRV(), &sourceRc, xfbSource->texWidth, xfbSource->texHeight, &drawRc, PixelShaderCache::GetColorCopyProgram(),VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout()); } + if (s_bScreenshot) + { + HRESULT hr = D3DX11SaveTextureToFileA(D3D::context, D3D::GetBackBuffer()->GetTex(), D3DX11_IFF_PNG, s_sScreenshotName); + s_bScreenshot = false; + } vp = CD3D11_VIEWPORT(0.f, 0.f, s_backbuffer_width, s_backbuffer_height); D3D::context->RSSetViewports(1, &vp); @@ -910,7 +919,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) UpdateActiveConfig(); WindowResized = false; CheckForResize(); - + bool xfbchanged = false; if (s_XFB_width != fbWidth || s_XFB_height != fbHeight) @@ -931,9 +940,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) xScale = (float)(dst_rect.right - dst_rect.left) / (float)s_XFB_width; yScale = (float)(dst_rect.bottom - dst_rect.top) / (float)s_XFB_height; - s_target_width = EFB_WIDTH * xScale; - s_target_height = EFB_HEIGHT * yScale; - + s_target_width = (int)(EFB_WIDTH * xScale); + s_target_height = (int)(EFB_HEIGHT * yScale); + D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), NULL); FBManager.Destroy(); @@ -1096,5 +1105,9 @@ void Renderer::SetInterlacingMode() // Save screenshot void Renderer::SetScreenshot(const char* filename) { - PanicAlert("Renderer::SetScreenshot not implemented\n"); + s_criticalScreenshot.Enter(); + strcpy_s(s_sScreenshotName, filename); + s_bScreenshot = true; + s_criticalScreenshot.Leave(); } + diff --git a/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp index 9e408c3bd5..c85325ed3f 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/TextureCache.cpp @@ -257,7 +257,13 @@ TextureCache::TCacheEntry* TextureCache::Load(unsigned int stage, u32 address, u D3D11_USAGE usage = (TexLevels == 1) ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT; if (!skip_texture_create) { - if (usage == D3D11_USAGE_DYNAMIC) entry.texture = D3DTexture2D::Create(width, height, D3D11_BIND_SHADER_RESOURCE, usage, d3d_fmt, TexLevels); + // TODO: A little more verbosity in the debug names would be quite helpful.. + if (usage == D3D11_USAGE_DYNAMIC) + { + entry.texture = D3DTexture2D::Create(width, height, D3D11_BIND_SHADER_RESOURCE, usage, d3d_fmt, TexLevels); + D3D::SetDebugObjectName((ID3D11DeviceChild*)entry.texture->GetTex(), "a (dynamic) texture of the TextureCache"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)entry.texture->GetSRV(), "shader resource view of a (dynamic) texture of the TextureCache"); + } else // need to use default textures { ID3D11Texture2D* pTexture = NULL; @@ -276,6 +282,8 @@ TextureCache::TCacheEntry* TextureCache::Load(unsigned int stage, u32 address, u } // we only need the shader resource view entry.texture = new D3DTexture2D(pTexture, D3D11_BIND_SHADER_RESOURCE); + D3D::SetDebugObjectName((ID3D11DeviceChild*)entry.texture->GetTex(), "a (static) texture of the TextureCache"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)entry.texture->GetSRV(), "shader resource view of a (static) texture of the TextureCache"); pTexture->Release(); } if (entry.texture == NULL) PanicAlert("Failed to create texture at %s %d\n", __FILE__, __LINE__); diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp index bb19b3bb58..1d05ab5762 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp @@ -148,12 +148,16 @@ void VertexShaderCache::Init() SimpleVertexShader = D3D::CreateVertexShaderFromByteCode(blob); if (SimpleLayout == NULL || SimpleVertexShader == NULL) PanicAlert("Failed to create simple vertex shader or input layout at %s %d\n", __FILE__, __LINE__); blob->Release(); + D3D::SetDebugObjectName((ID3D11DeviceChild*)SimpleVertexShader, "simple vertex shader"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)SimpleLayout, "simple input layout"); D3D::CompileVertexShader(clear_shader_code, (int)strlen(clear_shader_code), &blob); D3D::device->CreateInputLayout(clearelems, 2, blob->Data(), blob->Size(), &ClearLayout); ClearVertexShader = D3D::CreateVertexShaderFromByteCode(blob); if (ClearLayout == NULL || ClearVertexShader == NULL) PanicAlert("Failed to create clear vertex shader or input layout at %s %d\n", __FILE__, __LINE__); blob->Release(); + D3D::SetDebugObjectName((ID3D11DeviceChild*)ClearVertexShader, "clear vertex shader"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)ClearLayout, "clear input layout"); Clear(); @@ -249,6 +253,8 @@ bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, D3DBlob* bcod 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; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h index 9c3a0e914f..c33372b760 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h @@ -53,7 +53,7 @@ private: VSCacheEntry() : shader(NULL), bytecode(NULL), frameCount(0) {} void SetByteCode(D3DBlob* blob) { - if (bytecode) bytecode->Release(); + SAFE_RELEASE(bytecode); bytecode = blob; blob->AddRef(); } @@ -63,7 +63,6 @@ private: SAFE_RELEASE(bytecode); } }; - typedef std::map VSCache; static VSCache vshaders; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp index b215796e09..8c9a487c84 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp @@ -385,6 +385,7 @@ HRESULT ScreenShot(const char* filename) void Video_Screenshot(const char* _szFilename) { + Renderer::SetScreenshot(_szFilename); } static struct