From 93b4540e1943263e33aebf9aa3912f35dbdb4a0a Mon Sep 17 00:00:00 2001 From: Rodolfo Bogado Date: Thu, 4 Dec 2014 23:01:20 -0300 Subject: Add HW bounding Box support to d3d backend --- Source/Core/VideoBackends/D3D/BoundingBox.cpp | 95 +++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 Source/Core/VideoBackends/D3D/BoundingBox.cpp (limited to 'Source/Core/VideoBackends/D3D/BoundingBox.cpp') diff --git a/Source/Core/VideoBackends/D3D/BoundingBox.cpp b/Source/Core/VideoBackends/D3D/BoundingBox.cpp new file mode 100644 index 0000000000..727d5a9fac --- /dev/null +++ b/Source/Core/VideoBackends/D3D/BoundingBox.cpp @@ -0,0 +1,95 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "VideoBackends/D3D/BoundingBox.h" + +#include "VideoCommon/VideoConfig.h" + +namespace DX11 +{ + +static ID3D11Buffer* s_bbox_buffer; +static ID3D11Buffer* s_bbox_Readbuffer; +static ID3D11UnorderedAccessView* s_bbox_uav; + +ID3D11UnorderedAccessView* &BBox::GetUAV() +{ + return s_bbox_uav; +} + +void BBox::Init() +{ + if (g_ActiveConfig.backend_info.bSupportsBBox) + { + // create the pool texture here + auto desc = CD3D11_BUFFER_DESC(4 * sizeof(s32), D3D11_BIND_UNORDERED_ACCESS, D3D11_USAGE_DEFAULT, 0, 0, 4); + int initial_values[4] = { 0, 0, 0, 0 }; + D3D11_SUBRESOURCE_DATA data; + data.pSysMem = initial_values; + data.SysMemPitch = 4 * sizeof(s32); + data.SysMemSlicePitch = 0; + HRESULT hr; + hr = D3D::device->CreateBuffer(&desc, &data, &s_bbox_buffer); + CHECK(SUCCEEDED(hr), "create bbox buffer"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_buffer, "boundingbox buffer"); + desc.Usage = D3D11_USAGE_STAGING; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + desc.BindFlags = 0; + hr = D3D::device->CreateBuffer(&desc, nullptr, &s_bbox_Readbuffer); + CHECK(SUCCEEDED(hr), "create bbox staging buffer"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_Readbuffer, "boundingbox staging buffer"); + + D3D11_UNORDERED_ACCESS_VIEW_DESC UAVdesc; + memset(&UAVdesc, 0, sizeof(UAVdesc)); + UAVdesc.Format = DXGI_FORMAT_R32_SINT; + UAVdesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; + UAVdesc.Buffer.FirstElement = 0; + UAVdesc.Buffer.Flags = 0; + UAVdesc.Buffer.NumElements = 4; + hr = D3D::device->CreateUnorderedAccessView(s_bbox_buffer, &UAVdesc, &s_bbox_uav); + CHECK(SUCCEEDED(hr), "create bbox UAV"); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_uav, "boundingbox UAV"); + } +} + +void BBox::Shutdown() +{ + if (s_bbox_buffer != nullptr) + { + s_bbox_buffer->Release(); + s_bbox_buffer = nullptr; + } + if (s_bbox_Readbuffer != nullptr) + { + s_bbox_Readbuffer->Release(); + s_bbox_Readbuffer = nullptr; + } + if (s_bbox_uav != nullptr) + { + s_bbox_uav->Release(); + s_bbox_uav = nullptr; + } +} + +void BBox::Set(int index, int value) +{ + D3D11_BOX box{ index * sizeof(s32), 0, 0, (index + 1) * sizeof(s32), 1, 1 }; + D3D::context->UpdateSubresource(s_bbox_buffer, 0, &box, &value, 0, 0); +} + +int BBox::Get(int index) +{ + int data = 0; + D3D::context->CopyResource(s_bbox_Readbuffer, s_bbox_buffer); + D3D11_MAPPED_SUBRESOURCE map; + HRESULT hr = D3D::context->Map(s_bbox_Readbuffer, 0, D3D11_MAP_READ, 0, &map); + if (SUCCEEDED(hr)) + { + data = ((s32*)map.pData)[index]; + } + D3D::context->Unmap(s_bbox_Readbuffer, 0); + return data; +} + +}; -- cgit v1.2.3 From c7bb8fba9ea73b84381c21e18fba6ff65a565f84 Mon Sep 17 00:00:00 2001 From: Rodolfo Bogado Date: Fri, 5 Dec 2014 18:51:23 -0300 Subject: Added support test for bbox and some naming corrections --- Source/Core/VideoBackends/D3D/BoundingBox.cpp | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/BoundingBox.cpp') diff --git a/Source/Core/VideoBackends/D3D/BoundingBox.cpp b/Source/Core/VideoBackends/D3D/BoundingBox.cpp index 727d5a9fac..0bb55acab9 100644 --- a/Source/Core/VideoBackends/D3D/BoundingBox.cpp +++ b/Source/Core/VideoBackends/D3D/BoundingBox.cpp @@ -10,7 +10,7 @@ namespace DX11 { static ID3D11Buffer* s_bbox_buffer; -static ID3D11Buffer* s_bbox_Readbuffer; +static ID3D11Buffer* s_bbox_staging_buffer; static ID3D11UnorderedAccessView* s_bbox_uav; ID3D11UnorderedAccessView* &BBox::GetUAV() @@ -22,7 +22,8 @@ void BBox::Init() { if (g_ActiveConfig.backend_info.bSupportsBBox) { - // create the pool texture here + // Create 2 buffers here. + // First ror unordered access on Default pool. auto desc = CD3D11_BUFFER_DESC(4 * sizeof(s32), D3D11_BIND_UNORDERED_ACCESS, D3D11_USAGE_DEFAULT, 0, 0, 4); int initial_values[4] = { 0, 0, 0, 0 }; D3D11_SUBRESOURCE_DATA data; @@ -31,25 +32,27 @@ void BBox::Init() data.SysMemSlicePitch = 0; HRESULT hr; hr = D3D::device->CreateBuffer(&desc, &data, &s_bbox_buffer); - CHECK(SUCCEEDED(hr), "create bbox buffer"); - D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_buffer, "boundingbox buffer"); + CHECK(SUCCEEDED(hr), "Create BoundingBox Buffer."); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_buffer, "BoundingBox Buffer"); + + // Second to use as a staging buffer. desc.Usage = D3D11_USAGE_STAGING; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.BindFlags = 0; - hr = D3D::device->CreateBuffer(&desc, nullptr, &s_bbox_Readbuffer); - CHECK(SUCCEEDED(hr), "create bbox staging buffer"); - D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_Readbuffer, "boundingbox staging buffer"); - - D3D11_UNORDERED_ACCESS_VIEW_DESC UAVdesc; - memset(&UAVdesc, 0, sizeof(UAVdesc)); + hr = D3D::device->CreateBuffer(&desc, nullptr, &s_bbox_staging_buffer); + CHECK(SUCCEEDED(hr), "Create BoundingBox Staging Buffer."); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_staging_buffer, "BoundingBox Staging Buffer"); + + // UAV is required to allow concurrent access. + D3D11_UNORDERED_ACCESS_VIEW_DESC UAVdesc = {}; UAVdesc.Format = DXGI_FORMAT_R32_SINT; UAVdesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; UAVdesc.Buffer.FirstElement = 0; UAVdesc.Buffer.Flags = 0; UAVdesc.Buffer.NumElements = 4; hr = D3D::device->CreateUnorderedAccessView(s_bbox_buffer, &UAVdesc, &s_bbox_uav); - CHECK(SUCCEEDED(hr), "create bbox UAV"); - D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_uav, "boundingbox UAV"); + CHECK(SUCCEEDED(hr), "Create BoundingBox UAV."); + D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_uav, "BoundingBox UAV"); } } @@ -60,10 +63,10 @@ void BBox::Shutdown() s_bbox_buffer->Release(); s_bbox_buffer = nullptr; } - if (s_bbox_Readbuffer != nullptr) + if (s_bbox_staging_buffer != nullptr) { - s_bbox_Readbuffer->Release(); - s_bbox_Readbuffer = nullptr; + s_bbox_staging_buffer->Release(); + s_bbox_staging_buffer = nullptr; } if (s_bbox_uav != nullptr) { @@ -81,14 +84,14 @@ void BBox::Set(int index, int value) int BBox::Get(int index) { int data = 0; - D3D::context->CopyResource(s_bbox_Readbuffer, s_bbox_buffer); + D3D::context->CopyResource(s_bbox_staging_buffer, s_bbox_buffer); D3D11_MAPPED_SUBRESOURCE map; - HRESULT hr = D3D::context->Map(s_bbox_Readbuffer, 0, D3D11_MAP_READ, 0, &map); + HRESULT hr = D3D::context->Map(s_bbox_staging_buffer, 0, D3D11_MAP_READ, 0, &map); if (SUCCEEDED(hr)) { data = ((s32*)map.pData)[index]; } - D3D::context->Unmap(s_bbox_Readbuffer, 0); + D3D::context->Unmap(s_bbox_staging_buffer, 0); return data; } -- cgit v1.2.3 From 817d02532839b0d6e45747380a10865e6f05ff0f Mon Sep 17 00:00:00 2001 From: Rodolfo Bogado Date: Fri, 5 Dec 2014 23:54:34 -0300 Subject: small spacing fixes --- Source/Core/VideoBackends/D3D/BoundingBox.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/BoundingBox.cpp') diff --git a/Source/Core/VideoBackends/D3D/BoundingBox.cpp b/Source/Core/VideoBackends/D3D/BoundingBox.cpp index 0bb55acab9..37f2ca8890 100644 --- a/Source/Core/VideoBackends/D3D/BoundingBox.cpp +++ b/Source/Core/VideoBackends/D3D/BoundingBox.cpp @@ -23,7 +23,7 @@ void BBox::Init() if (g_ActiveConfig.backend_info.bSupportsBBox) { // Create 2 buffers here. - // First ror unordered access on Default pool. + // First for unordered access on default pool. auto desc = CD3D11_BUFFER_DESC(4 * sizeof(s32), D3D11_BIND_UNORDERED_ACCESS, D3D11_USAGE_DEFAULT, 0, 0, 4); int initial_values[4] = { 0, 0, 0, 0 }; D3D11_SUBRESOURCE_DATA data; @@ -33,7 +33,7 @@ void BBox::Init() HRESULT hr; hr = D3D::device->CreateBuffer(&desc, &data, &s_bbox_buffer); CHECK(SUCCEEDED(hr), "Create BoundingBox Buffer."); - D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_buffer, "BoundingBox Buffer"); + D3D::SetDebugObjectName(s_bbox_buffer, "BoundingBox Buffer"); // Second to use as a staging buffer. desc.Usage = D3D11_USAGE_STAGING; @@ -41,7 +41,7 @@ void BBox::Init() desc.BindFlags = 0; hr = D3D::device->CreateBuffer(&desc, nullptr, &s_bbox_staging_buffer); CHECK(SUCCEEDED(hr), "Create BoundingBox Staging Buffer."); - D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_staging_buffer, "BoundingBox Staging Buffer"); + D3D::SetDebugObjectName(s_bbox_staging_buffer, "BoundingBox Staging Buffer"); // UAV is required to allow concurrent access. D3D11_UNORDERED_ACCESS_VIEW_DESC UAVdesc = {}; @@ -52,7 +52,7 @@ void BBox::Init() UAVdesc.Buffer.NumElements = 4; hr = D3D::device->CreateUnorderedAccessView(s_bbox_buffer, &UAVdesc, &s_bbox_uav); CHECK(SUCCEEDED(hr), "Create BoundingBox UAV."); - D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_uav, "BoundingBox UAV"); + D3D::SetDebugObjectName(s_bbox_uav, "BoundingBox UAV"); } } -- cgit v1.2.3 From c2de38c115879b464f4c9f928685cf3d5c4b1314 Mon Sep 17 00:00:00 2001 From: Rodolfo Bogado Date: Sat, 6 Dec 2014 10:46:15 -0300 Subject: use SAFE_RELEASE to make code cleaner --- Source/Core/VideoBackends/D3D/BoundingBox.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'Source/Core/VideoBackends/D3D/BoundingBox.cpp') diff --git a/Source/Core/VideoBackends/D3D/BoundingBox.cpp b/Source/Core/VideoBackends/D3D/BoundingBox.cpp index 37f2ca8890..ac85da5685 100644 --- a/Source/Core/VideoBackends/D3D/BoundingBox.cpp +++ b/Source/Core/VideoBackends/D3D/BoundingBox.cpp @@ -58,21 +58,9 @@ void BBox::Init() void BBox::Shutdown() { - if (s_bbox_buffer != nullptr) - { - s_bbox_buffer->Release(); - s_bbox_buffer = nullptr; - } - if (s_bbox_staging_buffer != nullptr) - { - s_bbox_staging_buffer->Release(); - s_bbox_staging_buffer = nullptr; - } - if (s_bbox_uav != nullptr) - { - s_bbox_uav->Release(); - s_bbox_uav = nullptr; - } + SAFE_RELEASE(s_bbox_buffer); + SAFE_RELEASE(s_bbox_staging_buffer); + SAFE_RELEASE(s_bbox_uav); } void BBox::Set(int index, int value) -- cgit v1.2.3 From cf7512683c04e6e9836929c34f458515928eca4b Mon Sep 17 00:00:00 2001 From: Rodolfo Bogado Date: Sun, 7 Dec 2014 20:28:27 -0300 Subject: spaces cleanup --- Source/Core/VideoBackends/D3D/BoundingBox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/D3D/BoundingBox.cpp') diff --git a/Source/Core/VideoBackends/D3D/BoundingBox.cpp b/Source/Core/VideoBackends/D3D/BoundingBox.cpp index ac85da5685..564a84a276 100644 --- a/Source/Core/VideoBackends/D3D/BoundingBox.cpp +++ b/Source/Core/VideoBackends/D3D/BoundingBox.cpp @@ -42,7 +42,7 @@ void BBox::Init() hr = D3D::device->CreateBuffer(&desc, nullptr, &s_bbox_staging_buffer); CHECK(SUCCEEDED(hr), "Create BoundingBox Staging Buffer."); D3D::SetDebugObjectName(s_bbox_staging_buffer, "BoundingBox Staging Buffer"); - + // UAV is required to allow concurrent access. D3D11_UNORDERED_ACCESS_VIEW_DESC UAVdesc = {}; UAVdesc.Format = DXGI_FORMAT_R32_SINT; -- cgit v1.2.3