summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/D3D/BoundingBox.cpp
diff options
context:
space:
mode:
authorRodolfo Bogado <rodolfoosvaldobogado@gmail.com>2014-12-04 23:01:20 -0300
committerRodolfo Bogado <rodolfoosvaldobogado@gmail.com>2014-12-05 15:03:24 -0300
commit93b4540e1943263e33aebf9aa3912f35dbdb4a0a (patch)
tree949df27d122c7a2d41d445af982c714d14d15ee2 /Source/Core/VideoBackends/D3D/BoundingBox.cpp
parentc617b6c722d293be3b79d7344ea2d05828e7acc3 (diff)
Add HW bounding Box support to d3d backend
Diffstat (limited to 'Source/Core/VideoBackends/D3D/BoundingBox.cpp')
-rw-r--r--Source/Core/VideoBackends/D3D/BoundingBox.cpp95
1 files changed, 95 insertions, 0 deletions
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;
+}
+
+};