From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 374 +++++++++++++++++++++++++++ 1 file changed, 374 insertions(+) create mode 100644 Source/Core/VideoBackends/D3D/XFBEncoder.cpp (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp new file mode 100644 index 0000000000..bc6c66d29b --- /dev/null +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -0,0 +1,374 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "XFBEncoder.h" + +#include "D3DBase.h" +#include "D3DBlob.h" +#include "D3DShader.h" +#include "Render.h" +#include "GfxState.h" +#include "FramebufferManager.h" + +namespace DX11 +{ + +union XFBEncodeParams +{ + struct + { + FLOAT Width; // Width and height of encoded XFB in luma pixels + FLOAT Height; + FLOAT TexLeft; // Normalized tex coordinates of XFB source area in EFB texture + FLOAT TexTop; + FLOAT TexRight; + FLOAT TexBottom; + FLOAT Gamma; + }; + // Constant buffers must be a multiple of 16 bytes in size + u8 pad[32]; // Pad to the next multiple of 16 +}; + +static const char XFB_ENCODE_VS[] = +"// dolphin-emu XFB encoder vertex shader\n" + +"cbuffer cbParams : register(b0)\n" +"{\n" + "struct\n" // Should match XFBEncodeParams above + "{\n" + "float Width;\n" + "float Height;\n" + "float TexLeft;\n" + "float TexTop;\n" + "float TexRight;\n" + "float TexBottom;\n" + "float Gamma;\n" + "} Params;\n" +"}\n" + +"struct Output\n" +"{\n" + "float4 Pos : SV_Position;\n" + "float2 Coord : ENCODECOORD;\n" +"};\n" + +"Output main(in float2 Pos : POSITION)\n" +"{\n" + "Output result;\n" + "result.Pos = float4(2*Pos.x-1, -2*Pos.y+1, 0, 1);\n" + "result.Coord = Pos * float2(floor(Params.Width/2), Params.Height);\n" + "return result;\n" +"}\n" +; + +static const char XFB_ENCODE_PS[] = +"// dolphin-emu XFB encoder pixel shader\n" + +"cbuffer cbParams : register(b0)\n" +"{\n" + "struct\n" // Should match XFBEncodeParams above + "{\n" + "float Width;\n" + "float Height;\n" + "float TexLeft;\n" + "float TexTop;\n" + "float TexRight;\n" + "float TexBottom;\n" + "float Gamma;\n" + "} Params;\n" +"}\n" + +"Texture2D EFBTexture : register(t0);\n" +"sampler EFBSampler : register(s0);\n" + +// GameCube/Wii uses the BT.601 standard algorithm for converting to YCbCr; see +// +"static const float3x4 RGB_TO_YCBCR = float3x4(\n" + "0.257, 0.504, 0.098, 16.0/255.0,\n" + "-0.148, -0.291, 0.439, 128.0/255.0,\n" + "0.439, -0.368, -0.071, 128.0/255.0\n" + ");\n" + +"float3 SampleEFB(float2 coord)\n" +"{\n" + "float2 texCoord = lerp(float2(Params.TexLeft,Params.TexTop), float2(Params.TexRight,Params.TexBottom), coord / float2(Params.Width,Params.Height));\n" + "return EFBTexture.Sample(EFBSampler, texCoord).rgb;\n" +"}\n" + +"void main(out float4 ocol0 : SV_Target, in float4 Pos : SV_Position, in float2 Coord : ENCODECOORD)\n" +"{\n" + "float2 baseCoord = Coord * float2(2,1);\n" + // FIXME: Shall we apply gamma here, or apply it below to the Y components? + // Be careful if you apply it to Y! The Y components are in the range (16..235) / 255. + "float3 sampleL = pow(abs(SampleEFB(baseCoord+float2(-1,0))), Params.Gamma);\n" // Left + "float3 sampleM = pow(abs(SampleEFB(baseCoord)), Params.Gamma);\n" // Middle + "float3 sampleR = pow(abs(SampleEFB(baseCoord+float2(1,0))), Params.Gamma);\n" // Right + + "float3 yuvL = mul(RGB_TO_YCBCR, float4(sampleL,1));\n" + "float3 yuvM = mul(RGB_TO_YCBCR, float4(sampleM,1));\n" + "float3 yuvR = mul(RGB_TO_YCBCR, float4(sampleR,1));\n" + + // The Y components correspond to two EFB pixels, while the U and V are + // made from a blend of three EFB pixels. + "float y0 = yuvM.r;\n" + "float y1 = yuvR.r;\n" + "float u0 = 0.25*yuvL.g + 0.5*yuvM.g + 0.25*yuvR.g;\n" + "float v0 = 0.25*yuvL.b + 0.5*yuvM.b + 0.25*yuvR.b;\n" + + "ocol0 = float4(y0, u0, y1, v0);\n" +"}\n" +; + +static const D3D11_INPUT_ELEMENT_DESC QUAD_LAYOUT_DESC[] = { + { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 } +}; + +static const struct QuadVertex +{ + float posX; + float posY; +} QUAD_VERTS[4] = { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }; + +XFBEncoder::XFBEncoder() + : m_out(NULL), m_outRTV(NULL), m_outStage(NULL), m_encodeParams(NULL), + m_quad(NULL), m_vShader(NULL), m_quadLayout(NULL), m_pShader(NULL), + m_xfbEncodeBlendState(NULL), m_xfbEncodeDepthState(NULL), + m_xfbEncodeRastState(NULL), m_efbSampler(NULL) +{ } + +void XFBEncoder::Init() +{ + HRESULT hr; + + // Create output texture + + // The pixel shader can generate one YUYV entry per pixel. One YUYV entry + // is created for every two EFB pixels. + D3D11_TEXTURE2D_DESC t2dd = CD3D11_TEXTURE2D_DESC( + DXGI_FORMAT_R8G8B8A8_UNORM, MAX_XFB_WIDTH/2, MAX_XFB_HEIGHT, 1, 1, + D3D11_BIND_RENDER_TARGET); + hr = D3D::device->CreateTexture2D(&t2dd, NULL, &m_out); + CHECK(SUCCEEDED(hr), "create xfb encoder output texture"); + D3D::SetDebugObjectName(m_out, "xfb encoder output texture"); + + // Create output render target view + + D3D11_RENDER_TARGET_VIEW_DESC rtvd = CD3D11_RENDER_TARGET_VIEW_DESC(m_out, + D3D11_RTV_DIMENSION_TEXTURE2D, DXGI_FORMAT_R8G8B8A8_UNORM); + hr = D3D::device->CreateRenderTargetView(m_out, &rtvd, &m_outRTV); + CHECK(SUCCEEDED(hr), "create xfb encoder output texture rtv"); + D3D::SetDebugObjectName(m_outRTV, "xfb encoder output rtv"); + + // Create output staging buffer + + t2dd.Usage = D3D11_USAGE_STAGING; + t2dd.BindFlags = 0; + t2dd.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + hr = D3D::device->CreateTexture2D(&t2dd, NULL, &m_outStage); + CHECK(SUCCEEDED(hr), "create xfb encoder output staging buffer"); + D3D::SetDebugObjectName(m_outStage, "xfb encoder output staging buffer"); + + // Create constant buffer for uploading params to shaders + + D3D11_BUFFER_DESC bd = CD3D11_BUFFER_DESC(sizeof(XFBEncodeParams), + D3D11_BIND_CONSTANT_BUFFER); + hr = D3D::device->CreateBuffer(&bd, NULL, &m_encodeParams); + CHECK(SUCCEEDED(hr), "create xfb encode params buffer"); + D3D::SetDebugObjectName(m_encodeParams, "xfb encoder params buffer"); + + // Create vertex quad + + bd = CD3D11_BUFFER_DESC(sizeof(QUAD_VERTS), D3D11_BIND_VERTEX_BUFFER, + D3D11_USAGE_IMMUTABLE); + D3D11_SUBRESOURCE_DATA srd = { QUAD_VERTS, 0, 0 }; + + hr = D3D::device->CreateBuffer(&bd, &srd, &m_quad); + CHECK(SUCCEEDED(hr), "create xfb encode quad vertex buffer"); + D3D::SetDebugObjectName(m_quad, "xfb encoder quad vertex buffer"); + + // Create vertex shader + + D3DBlob* bytecode = NULL; + if (!D3D::CompileVertexShader(XFB_ENCODE_VS, sizeof(XFB_ENCODE_VS), &bytecode)) + { + ERROR_LOG(VIDEO, "XFB encode vertex shader failed to compile"); + return; + } + + hr = D3D::device->CreateVertexShader(bytecode->Data(), bytecode->Size(), NULL, &m_vShader); + CHECK(SUCCEEDED(hr), "create xfb encode vertex shader"); + D3D::SetDebugObjectName(m_vShader, "xfb encoder vertex shader"); + + // Create input layout for vertex quad using bytecode from vertex shader + + hr = D3D::device->CreateInputLayout(QUAD_LAYOUT_DESC, + sizeof(QUAD_LAYOUT_DESC)/sizeof(D3D11_INPUT_ELEMENT_DESC), + bytecode->Data(), bytecode->Size(), &m_quadLayout); + CHECK(SUCCEEDED(hr), "create xfb encode quad vertex layout"); + D3D::SetDebugObjectName(m_quadLayout, "xfb encoder quad layout"); + + bytecode->Release(); + + // Create pixel shader + + m_pShader = D3D::CompileAndCreatePixelShader(XFB_ENCODE_PS, sizeof(XFB_ENCODE_PS)); + if (!m_pShader) + { + ERROR_LOG(VIDEO, "XFB encode pixel shader failed to compile"); + return; + } + D3D::SetDebugObjectName(m_pShader, "xfb encoder pixel shader"); + + // Create blend state + + D3D11_BLEND_DESC bld = CD3D11_BLEND_DESC(CD3D11_DEFAULT()); + hr = D3D::device->CreateBlendState(&bld, &m_xfbEncodeBlendState); + CHECK(SUCCEEDED(hr), "create xfb encode blend state"); + D3D::SetDebugObjectName(m_xfbEncodeBlendState, "xfb encoder blend state"); + + // Create depth state + + D3D11_DEPTH_STENCIL_DESC dsd = CD3D11_DEPTH_STENCIL_DESC(CD3D11_DEFAULT()); + dsd.DepthEnable = FALSE; + hr = D3D::device->CreateDepthStencilState(&dsd, &m_xfbEncodeDepthState); + CHECK(SUCCEEDED(hr), "create xfb encode depth state"); + D3D::SetDebugObjectName(m_xfbEncodeDepthState, "xfb encoder depth state"); + + // Create rasterizer state + + D3D11_RASTERIZER_DESC rd = CD3D11_RASTERIZER_DESC(CD3D11_DEFAULT()); + rd.CullMode = D3D11_CULL_NONE; + rd.DepthClipEnable = FALSE; + hr = D3D::device->CreateRasterizerState(&rd, &m_xfbEncodeRastState); + CHECK(SUCCEEDED(hr), "create xfb encode rasterizer state"); + D3D::SetDebugObjectName(m_xfbEncodeRastState, "xfb encoder rast state"); + + // Create EFB texture sampler + + D3D11_SAMPLER_DESC sd = CD3D11_SAMPLER_DESC(CD3D11_DEFAULT()); + // FIXME: Should we really use point sampling here? + sd.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + hr = D3D::device->CreateSamplerState(&sd, &m_efbSampler); + CHECK(SUCCEEDED(hr), "create xfb encode texture sampler"); + D3D::SetDebugObjectName(m_efbSampler, "xfb encoder texture sampler"); +} + +void XFBEncoder::Shutdown() +{ + SAFE_RELEASE(m_efbSampler); + SAFE_RELEASE(m_xfbEncodeRastState); + SAFE_RELEASE(m_xfbEncodeDepthState); + SAFE_RELEASE(m_xfbEncodeBlendState); + SAFE_RELEASE(m_pShader); + SAFE_RELEASE(m_quadLayout); + SAFE_RELEASE(m_vShader); + SAFE_RELEASE(m_quad); + SAFE_RELEASE(m_encodeParams); + SAFE_RELEASE(m_outStage); + SAFE_RELEASE(m_outRTV); + SAFE_RELEASE(m_out); +} + +void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcRect, float gamma) +{ + HRESULT hr; + + // Reset API + + g_renderer->ResetAPIState(); + + // Set up all the state for XFB encoding + + D3D::context->PSSetShader(m_pShader, NULL, 0); + D3D::context->VSSetShader(m_vShader, NULL, 0); + + D3D::stateman->PushBlendState(m_xfbEncodeBlendState); + D3D::stateman->PushDepthState(m_xfbEncodeDepthState); + D3D::stateman->PushRasterizerState(m_xfbEncodeRastState); + D3D::stateman->Apply(); + + D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, FLOAT(width/2), FLOAT(height)); + D3D::context->RSSetViewports(1, &vp); + + D3D::context->IASetInputLayout(m_quadLayout); + D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + UINT stride = sizeof(QuadVertex); + UINT offset = 0; + D3D::context->IASetVertexBuffers(0, 1, &m_quad, &stride, &offset); + + TargetRectangle targetRect = g_renderer->ConvertEFBRectangle(srcRect); + + XFBEncodeParams params = { 0 }; + params.Width = FLOAT(width); + params.Height = FLOAT(height); + params.TexLeft = FLOAT(targetRect.left) / g_renderer->GetTargetWidth(); + params.TexTop = FLOAT(targetRect.top) / g_renderer->GetTargetHeight(); + params.TexRight = FLOAT(targetRect.right) / g_renderer->GetTargetWidth(); + params.TexBottom = FLOAT(targetRect.bottom) / g_renderer->GetTargetHeight(); + params.Gamma = gamma; + D3D::context->UpdateSubresource(m_encodeParams, 0, NULL, ¶ms, 0, 0); + + D3D::context->VSSetConstantBuffers(0, 1, &m_encodeParams); + + D3D::context->OMSetRenderTargets(1, &m_outRTV, NULL); + + ID3D11ShaderResourceView* pEFB = FramebufferManager::GetEFBColorTexture()->GetSRV(); + + D3D::context->PSSetConstantBuffers(0, 1, &m_encodeParams); + D3D::context->PSSetShaderResources(0, 1, &pEFB); + D3D::context->PSSetSamplers(0, 1, &m_efbSampler); + + // Encode! + + D3D::context->Draw(4, 0); + + // Copy to staging buffer + + D3D11_BOX srcBox = CD3D11_BOX(0, 0, 0, width/2, height, 1); + D3D::context->CopySubresourceRegion(m_outStage, 0, 0, 0, 0, m_out, 0, &srcBox); + + // Clean up state + + IUnknown* nullDummy = NULL; + + D3D::context->PSSetSamplers(0, 1, (ID3D11SamplerState**)&nullDummy); + D3D::context->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&nullDummy); + D3D::context->PSSetConstantBuffers(0, 1, (ID3D11Buffer**)&nullDummy); + + D3D::context->OMSetRenderTargets(0, NULL, NULL); + + D3D::context->VSSetConstantBuffers(0, 1, (ID3D11Buffer**)&nullDummy); + + D3D::stateman->PopRasterizerState(); + D3D::stateman->PopDepthState(); + D3D::stateman->PopBlendState(); + + D3D::context->PSSetShader(NULL, NULL, 0); + D3D::context->VSSetShader(NULL, NULL, 0); + + // Transfer staging buffer to GameCube/Wii RAM + + D3D11_MAPPED_SUBRESOURCE map = { 0 }; + hr = D3D::context->Map(m_outStage, 0, D3D11_MAP_READ, 0, &map); + CHECK(SUCCEEDED(hr), "map staging buffer"); + + u8* src = (u8*)map.pData; + for (unsigned int y = 0; y < height; ++y) + { + memcpy(dst, src, 2*width); + dst += bpmem.copyMipMapStrideChannels*32; + src += map.RowPitch; + } + + D3D::context->Unmap(m_outStage, 0); + + // Restore API + + g_renderer->RestoreAPIState(); + D3D::context->OMSetRenderTargets(1, + &FramebufferManager::GetEFBColorTexture()->GetRTV(), + FramebufferManager::GetEFBDepthTexture()->GetDSV()); +} + +} -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index bc6c66d29b..25d69aed12 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -2,14 +2,13 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "XFBEncoder.h" - -#include "D3DBase.h" -#include "D3DBlob.h" -#include "D3DShader.h" -#include "Render.h" -#include "GfxState.h" -#include "FramebufferManager.h" +#include "VideoBackends/D3D/D3DBase.h" +#include "VideoBackends/D3D/D3DBlob.h" +#include "VideoBackends/D3D/D3DShader.h" +#include "VideoBackends/D3D/FramebufferManager.h" +#include "VideoBackends/D3D/GfxState.h" +#include "VideoBackends/D3D/Render.h" +#include "VideoBackends/D3D/XFBEncoder.h" namespace DX11 { -- cgit v1.2.3 From d802d392811be44d34ae9cd23f616db93e54c50f Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 9 Mar 2014 21:14:26 +0100 Subject: clang-modernize -use-nullptr and s/\bNULL\b/nullptr/g for *.cpp/h/mm files not compiled on my machine --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 25d69aed12..d32d76f88e 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -130,10 +130,10 @@ static const struct QuadVertex } QUAD_VERTS[4] = { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }; XFBEncoder::XFBEncoder() - : m_out(NULL), m_outRTV(NULL), m_outStage(NULL), m_encodeParams(NULL), - m_quad(NULL), m_vShader(NULL), m_quadLayout(NULL), m_pShader(NULL), - m_xfbEncodeBlendState(NULL), m_xfbEncodeDepthState(NULL), - m_xfbEncodeRastState(NULL), m_efbSampler(NULL) + : m_out(nullptr), m_outRTV(nullptr), m_outStage(nullptr), m_encodeParams(nullptr), + m_quad(nullptr), m_vShader(nullptr), m_quadLayout(nullptr), m_pShader(nullptr), + m_xfbEncodeBlendState(nullptr), m_xfbEncodeDepthState(nullptr), + m_xfbEncodeRastState(nullptr), m_efbSampler(nullptr) { } void XFBEncoder::Init() @@ -147,7 +147,7 @@ void XFBEncoder::Init() D3D11_TEXTURE2D_DESC t2dd = CD3D11_TEXTURE2D_DESC( DXGI_FORMAT_R8G8B8A8_UNORM, MAX_XFB_WIDTH/2, MAX_XFB_HEIGHT, 1, 1, D3D11_BIND_RENDER_TARGET); - hr = D3D::device->CreateTexture2D(&t2dd, NULL, &m_out); + hr = D3D::device->CreateTexture2D(&t2dd, nullptr, &m_out); CHECK(SUCCEEDED(hr), "create xfb encoder output texture"); D3D::SetDebugObjectName(m_out, "xfb encoder output texture"); @@ -164,7 +164,7 @@ void XFBEncoder::Init() t2dd.Usage = D3D11_USAGE_STAGING; t2dd.BindFlags = 0; t2dd.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - hr = D3D::device->CreateTexture2D(&t2dd, NULL, &m_outStage); + hr = D3D::device->CreateTexture2D(&t2dd, nullptr, &m_outStage); CHECK(SUCCEEDED(hr), "create xfb encoder output staging buffer"); D3D::SetDebugObjectName(m_outStage, "xfb encoder output staging buffer"); @@ -172,7 +172,7 @@ void XFBEncoder::Init() D3D11_BUFFER_DESC bd = CD3D11_BUFFER_DESC(sizeof(XFBEncodeParams), D3D11_BIND_CONSTANT_BUFFER); - hr = D3D::device->CreateBuffer(&bd, NULL, &m_encodeParams); + hr = D3D::device->CreateBuffer(&bd, nullptr, &m_encodeParams); CHECK(SUCCEEDED(hr), "create xfb encode params buffer"); D3D::SetDebugObjectName(m_encodeParams, "xfb encoder params buffer"); @@ -188,14 +188,14 @@ void XFBEncoder::Init() // Create vertex shader - D3DBlob* bytecode = NULL; + D3DBlob* bytecode = nullptr; if (!D3D::CompileVertexShader(XFB_ENCODE_VS, sizeof(XFB_ENCODE_VS), &bytecode)) { ERROR_LOG(VIDEO, "XFB encode vertex shader failed to compile"); return; } - hr = D3D::device->CreateVertexShader(bytecode->Data(), bytecode->Size(), NULL, &m_vShader); + hr = D3D::device->CreateVertexShader(bytecode->Data(), bytecode->Size(), nullptr, &m_vShader); CHECK(SUCCEEDED(hr), "create xfb encode vertex shader"); D3D::SetDebugObjectName(m_vShader, "xfb encoder vertex shader"); @@ -279,8 +279,8 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR // Set up all the state for XFB encoding - D3D::context->PSSetShader(m_pShader, NULL, 0); - D3D::context->VSSetShader(m_vShader, NULL, 0); + D3D::context->PSSetShader(m_pShader, nullptr, 0); + D3D::context->VSSetShader(m_vShader, nullptr, 0); D3D::stateman->PushBlendState(m_xfbEncodeBlendState); D3D::stateman->PushDepthState(m_xfbEncodeDepthState); @@ -306,11 +306,11 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR params.TexRight = FLOAT(targetRect.right) / g_renderer->GetTargetWidth(); params.TexBottom = FLOAT(targetRect.bottom) / g_renderer->GetTargetHeight(); params.Gamma = gamma; - D3D::context->UpdateSubresource(m_encodeParams, 0, NULL, ¶ms, 0, 0); + D3D::context->UpdateSubresource(m_encodeParams, 0, nullptr, ¶ms, 0, 0); D3D::context->VSSetConstantBuffers(0, 1, &m_encodeParams); - D3D::context->OMSetRenderTargets(1, &m_outRTV, NULL); + D3D::context->OMSetRenderTargets(1, &m_outRTV, nullptr); ID3D11ShaderResourceView* pEFB = FramebufferManager::GetEFBColorTexture()->GetSRV(); @@ -329,13 +329,13 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR // Clean up state - IUnknown* nullDummy = NULL; + IUnknown* nullDummy = nullptr; D3D::context->PSSetSamplers(0, 1, (ID3D11SamplerState**)&nullDummy); D3D::context->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&nullDummy); D3D::context->PSSetConstantBuffers(0, 1, (ID3D11Buffer**)&nullDummy); - D3D::context->OMSetRenderTargets(0, NULL, NULL); + D3D::context->OMSetRenderTargets(0, nullptr, nullptr); D3D::context->VSSetConstantBuffers(0, 1, (ID3D11Buffer**)&nullDummy); @@ -343,8 +343,8 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR D3D::stateman->PopDepthState(); D3D::stateman->PopBlendState(); - D3D::context->PSSetShader(NULL, NULL, 0); - D3D::context->VSSetShader(NULL, NULL, 0); + D3D::context->PSSetShader(nullptr, nullptr, 0); + D3D::context->VSSetShader(nullptr, nullptr, 0); // Transfer staging buffer to GameCube/Wii RAM -- cgit v1.2.3 From a523a6d1bfabddbd2030dda1aebf28ddb28b5f26 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 7 Jul 2014 19:28:12 -0400 Subject: D3D: Use std::strings for Compile[x]Shader and CompileAndCreate[x]Shader With strings, we don't need to care about passing in a length, since it internally stores it. So now, we don't even need a length parameter for these functions anymore as well. This also kills off some sprintf_s calls. --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index d32d76f88e..8c200b4ab2 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -189,7 +189,7 @@ void XFBEncoder::Init() // Create vertex shader D3DBlob* bytecode = nullptr; - if (!D3D::CompileVertexShader(XFB_ENCODE_VS, sizeof(XFB_ENCODE_VS), &bytecode)) + if (!D3D::CompileVertexShader(XFB_ENCODE_VS, &bytecode)) { ERROR_LOG(VIDEO, "XFB encode vertex shader failed to compile"); return; @@ -211,7 +211,7 @@ void XFBEncoder::Init() // Create pixel shader - m_pShader = D3D::CompileAndCreatePixelShader(XFB_ENCODE_PS, sizeof(XFB_ENCODE_PS)); + m_pShader = D3D::CompileAndCreatePixelShader(XFB_ENCODE_PS); if (!m_pShader) { ERROR_LOG(VIDEO, "XFB encode pixel shader failed to compile"); -- cgit v1.2.3 From fe9b7fa4f371d1c400afa6274eaf9512681685d6 Mon Sep 17 00:00:00 2001 From: jimbo1qaz Date: Tue, 29 Jul 2014 18:15:01 -0700 Subject: Fix D3D Real XFB texture sampling. --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 8c200b4ab2..215a7e911f 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -97,7 +97,8 @@ static const char XFB_ENCODE_PS[] = "void main(out float4 ocol0 : SV_Target, in float4 Pos : SV_Position, in float2 Coord : ENCODECOORD)\n" "{\n" - "float2 baseCoord = Coord * float2(2,1);\n" + // Multiplying X by 2, moves pixel centers from (x+0.5) to (2x+1) instead of (2x+0.5), so subtract 0.5 to compensate + "float2 baseCoord = Coord * float2(2,1) - float2(0.5,0);\n" // FIXME: Shall we apply gamma here, or apply it below to the Y components? // Be careful if you apply it to Y! The Y components are in the range (16..235) / 255. "float3 sampleL = pow(abs(SampleEFB(baseCoord+float2(-1,0))), Params.Gamma);\n" // Left -- cgit v1.2.3 From 21655dc61a81845c88ebc20934c76a2ad93f1f3a Mon Sep 17 00:00:00 2001 From: Yuriy O'Donnell Date: Mon, 23 Jun 2014 08:11:07 +0200 Subject: D3D: moved render state cache implementation to D3DState.h/cpp --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 215a7e911f..50524d8a3d 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -5,8 +5,8 @@ #include "VideoBackends/D3D/D3DBase.h" #include "VideoBackends/D3D/D3DBlob.h" #include "VideoBackends/D3D/D3DShader.h" +#include "VideoBackends/D3D/D3DState.h" #include "VideoBackends/D3D/FramebufferManager.h" -#include "VideoBackends/D3D/GfxState.h" #include "VideoBackends/D3D/Render.h" #include "VideoBackends/D3D/XFBEncoder.h" -- cgit v1.2.3 From 6e9226650d44fd79343f1fcfa30c7f04ee4cd01f Mon Sep 17 00:00:00 2001 From: Yuriy O'Donnell Date: Wed, 29 Oct 2014 01:19:09 +0100 Subject: D3D: Implemented context state caching This avoids most of the redundant API calls. --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 38 +++++++++++++--------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 50524d8a3d..9f805d995c 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -280,22 +280,21 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR // Set up all the state for XFB encoding - D3D::context->PSSetShader(m_pShader, nullptr, 0); - D3D::context->VSSetShader(m_vShader, nullptr, 0); + D3D::stateman->setPixelShader(m_pShader); + D3D::stateman->setVertexShader(m_vShader); D3D::stateman->PushBlendState(m_xfbEncodeBlendState); D3D::stateman->PushDepthState(m_xfbEncodeDepthState); D3D::stateman->PushRasterizerState(m_xfbEncodeRastState); - D3D::stateman->Apply(); D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, FLOAT(width/2), FLOAT(height)); D3D::context->RSSetViewports(1, &vp); - D3D::context->IASetInputLayout(m_quadLayout); - D3D::context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + D3D::stateman->setInputLayout(m_quadLayout); + D3D::stateman->setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); UINT stride = sizeof(QuadVertex); UINT offset = 0; - D3D::context->IASetVertexBuffers(0, 1, &m_quad, &stride, &offset); + D3D::stateman->setVertexBuffer(m_quad, stride, offset); TargetRectangle targetRect = g_renderer->ConvertEFBRectangle(srcRect); @@ -309,18 +308,18 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR params.Gamma = gamma; D3D::context->UpdateSubresource(m_encodeParams, 0, nullptr, ¶ms, 0, 0); - D3D::context->VSSetConstantBuffers(0, 1, &m_encodeParams); - D3D::context->OMSetRenderTargets(1, &m_outRTV, nullptr); ID3D11ShaderResourceView* pEFB = FramebufferManager::GetEFBColorTexture()->GetSRV(); - D3D::context->PSSetConstantBuffers(0, 1, &m_encodeParams); - D3D::context->PSSetShaderResources(0, 1, &pEFB); - D3D::context->PSSetSamplers(0, 1, &m_efbSampler); + D3D::stateman->setVertexConstants(m_encodeParams); + D3D::stateman->setPixelConstants(m_encodeParams); + D3D::stateman->setTexture(0, pEFB); + D3D::stateman->setSampler(0, m_efbSampler); // Encode! + D3D::stateman->Apply(); D3D::context->Draw(4, 0); // Copy to staging buffer @@ -330,23 +329,20 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR // Clean up state - IUnknown* nullDummy = nullptr; - - D3D::context->PSSetSamplers(0, 1, (ID3D11SamplerState**)&nullDummy); - D3D::context->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&nullDummy); - D3D::context->PSSetConstantBuffers(0, 1, (ID3D11Buffer**)&nullDummy); - D3D::context->OMSetRenderTargets(0, nullptr, nullptr); - D3D::context->VSSetConstantBuffers(0, 1, (ID3D11Buffer**)&nullDummy); + D3D::stateman->setSampler(0, nullptr); + D3D::stateman->setTexture(0, nullptr); + D3D::stateman->setPixelConstants(nullptr); + D3D::stateman->setVertexConstants(nullptr); + + D3D::stateman->setPixelShader(nullptr); + D3D::stateman->setVertexShader(nullptr); D3D::stateman->PopRasterizerState(); D3D::stateman->PopDepthState(); D3D::stateman->PopBlendState(); - D3D::context->PSSetShader(nullptr, nullptr, 0); - D3D::context->VSSetShader(nullptr, nullptr, 0); - // Transfer staging buffer to GameCube/Wii RAM D3D11_MAPPED_SUBRESOURCE map = { 0 }; -- cgit v1.2.3 From 4392d3cd55f4b39ae6006702ff6466867609e2a3 Mon Sep 17 00:00:00 2001 From: Yuriy O'Donnell Date: Sat, 6 Dec 2014 14:54:06 +0100 Subject: D3D: Fixed StateManager member function name case --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 9f805d995c..fb56363e31 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -280,8 +280,8 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR // Set up all the state for XFB encoding - D3D::stateman->setPixelShader(m_pShader); - D3D::stateman->setVertexShader(m_vShader); + D3D::stateman->SetPixelShader(m_pShader); + D3D::stateman->SetVertexShader(m_vShader); D3D::stateman->PushBlendState(m_xfbEncodeBlendState); D3D::stateman->PushDepthState(m_xfbEncodeDepthState); @@ -290,11 +290,11 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, FLOAT(width/2), FLOAT(height)); D3D::context->RSSetViewports(1, &vp); - D3D::stateman->setInputLayout(m_quadLayout); - D3D::stateman->setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + D3D::stateman->SetInputLayout(m_quadLayout); + D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); UINT stride = sizeof(QuadVertex); UINT offset = 0; - D3D::stateman->setVertexBuffer(m_quad, stride, offset); + D3D::stateman->SetVertexBuffer(m_quad, stride, offset); TargetRectangle targetRect = g_renderer->ConvertEFBRectangle(srcRect); @@ -312,10 +312,10 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR ID3D11ShaderResourceView* pEFB = FramebufferManager::GetEFBColorTexture()->GetSRV(); - D3D::stateman->setVertexConstants(m_encodeParams); - D3D::stateman->setPixelConstants(m_encodeParams); - D3D::stateman->setTexture(0, pEFB); - D3D::stateman->setSampler(0, m_efbSampler); + D3D::stateman->SetVertexConstants(m_encodeParams); + D3D::stateman->SetPixelConstants(m_encodeParams); + D3D::stateman->SetTexture(0, pEFB); + D3D::stateman->SetSampler(0, m_efbSampler); // Encode! @@ -331,13 +331,13 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR D3D::context->OMSetRenderTargets(0, nullptr, nullptr); - D3D::stateman->setSampler(0, nullptr); - D3D::stateman->setTexture(0, nullptr); - D3D::stateman->setPixelConstants(nullptr); - D3D::stateman->setVertexConstants(nullptr); + D3D::stateman->SetSampler(0, nullptr); + D3D::stateman->SetTexture(0, nullptr); + D3D::stateman->SetPixelConstants(nullptr); + D3D::stateman->SetVertexConstants(nullptr); - D3D::stateman->setPixelShader(nullptr); - D3D::stateman->setVertexShader(nullptr); + D3D::stateman->SetPixelShader(nullptr); + D3D::stateman->SetVertexShader(nullptr); D3D::stateman->PopRasterizerState(); D3D::stateman->PopDepthState(); -- cgit v1.2.3 From 3d9dfad6a229f03948620b97f7e3b48e80784b3c Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 17 Dec 2014 03:05:23 +0100 Subject: D3D: Set the geometry shader before every draw call. And refactor the VertexManager draw call. --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index fb56363e31..955fb38bc8 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -282,6 +282,7 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR D3D::stateman->SetPixelShader(m_pShader); D3D::stateman->SetVertexShader(m_vShader); + D3D::stateman->SetGeometryShader(nullptr); D3D::stateman->PushBlendState(m_xfbEncodeBlendState); D3D::stateman->PushDepthState(m_xfbEncodeDepthState); -- cgit v1.2.3 From 833513f38413dc0f6af47067b223125c3de3eeaf Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 25 Dec 2014 12:09:35 +0100 Subject: XFBEncoder: Sample the first layer of the resolved EFB texture. Using the multisampled EFB texture is invalid, as the XFB encoder does not have a multisampling shader. --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 955fb38bc8..9e95e1ea74 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -78,7 +78,7 @@ static const char XFB_ENCODE_PS[] = "} Params;\n" "}\n" -"Texture2D EFBTexture : register(t0);\n" +"Texture2DArray EFBTexture : register(t0);\n" "sampler EFBSampler : register(s0);\n" // GameCube/Wii uses the BT.601 standard algorithm for converting to YCbCr; see @@ -92,7 +92,7 @@ static const char XFB_ENCODE_PS[] = "float3 SampleEFB(float2 coord)\n" "{\n" "float2 texCoord = lerp(float2(Params.TexLeft,Params.TexTop), float2(Params.TexRight,Params.TexBottom), coord / float2(Params.Width,Params.Height));\n" - "return EFBTexture.Sample(EFBSampler, texCoord).rgb;\n" + "return EFBTexture.Sample(EFBSampler, float3(texCoord, 0)).rgb;\n" "}\n" "void main(out float4 ocol0 : SV_Target, in float4 Pos : SV_Position, in float2 Coord : ENCODECOORD)\n" @@ -311,7 +311,7 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR D3D::context->OMSetRenderTargets(1, &m_outRTV, nullptr); - ID3D11ShaderResourceView* pEFB = FramebufferManager::GetEFBColorTexture()->GetSRV(); + ID3D11ShaderResourceView* pEFB = FramebufferManager::GetResolvedEFBColorTexture()->GetSRV(); D3D::stateman->SetVertexConstants(m_encodeParams); D3D::stateman->SetPixelConstants(m_encodeParams); -- cgit v1.2.3 From 81d1b7f0c2bebbc9c8835f1bfe6ae1cb3c324105 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sun, 28 Dec 2014 16:30:48 +0100 Subject: XFBEncoder: Cosmetics. --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 9e95e1ea74..e0932fe616 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -92,7 +92,7 @@ static const char XFB_ENCODE_PS[] = "float3 SampleEFB(float2 coord)\n" "{\n" "float2 texCoord = lerp(float2(Params.TexLeft,Params.TexTop), float2(Params.TexRight,Params.TexBottom), coord / float2(Params.Width,Params.Height));\n" - "return EFBTexture.Sample(EFBSampler, float3(texCoord, 0)).rgb;\n" + "return EFBTexture.Sample(EFBSampler, float3(texCoord, 0.0)).rgb;\n" "}\n" "void main(out float4 ocol0 : SV_Target, in float4 Pos : SV_Position, in float2 Coord : ENCODECOORD)\n" -- cgit v1.2.3 From c43da7e00bd6be103a11090f53cc04d4c0b2caf8 Mon Sep 17 00:00:00 2001 From: "mr.greywater" Date: Thu, 12 Feb 2015 14:45:05 +0100 Subject: D3D: replace memset, fix warning --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index e0932fe616..70316a9df5 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -361,8 +361,8 @@ void XFBEncoder::Encode(u8* dst, u32 width, u32 height, const EFBRectangle& srcR D3D::context->Unmap(m_outStage, 0); // Restore API - g_renderer->RestoreAPIState(); + D3D::stateman->Apply(); // force unbind efb texture as shader resource D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), FramebufferManager::GetEFBDepthTexture()->GetDSV()); -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 70316a9df5..097f322026 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -1,5 +1,5 @@ // Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include "VideoBackends/D3D/D3DBase.h" -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- Source/Core/VideoBackends/D3D/XFBEncoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/D3D/XFBEncoder.cpp') diff --git a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp index 097f322026..560b13fa7a 100644 --- a/Source/Core/VideoBackends/D3D/XFBEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/XFBEncoder.cpp @@ -1,4 +1,4 @@ -// Copyright 2013 Dolphin Emulator Project +// Copyright 2011 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3