Added support test for bbox and some naming corrections

This commit is contained in:
Rodolfo Bogado
2014-12-05 18:51:23 -03:00
parent 93b4540e19
commit c7bb8fba9e
2 changed files with 27 additions and 21 deletions

View File

@ -10,7 +10,7 @@ namespace DX11
{ {
static ID3D11Buffer* s_bbox_buffer; static ID3D11Buffer* s_bbox_buffer;
static ID3D11Buffer* s_bbox_Readbuffer; static ID3D11Buffer* s_bbox_staging_buffer;
static ID3D11UnorderedAccessView* s_bbox_uav; static ID3D11UnorderedAccessView* s_bbox_uav;
ID3D11UnorderedAccessView* &BBox::GetUAV() ID3D11UnorderedAccessView* &BBox::GetUAV()
@ -22,7 +22,8 @@ void BBox::Init()
{ {
if (g_ActiveConfig.backend_info.bSupportsBBox) 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); 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 }; int initial_values[4] = { 0, 0, 0, 0 };
D3D11_SUBRESOURCE_DATA data; D3D11_SUBRESOURCE_DATA data;
@ -31,25 +32,27 @@ void BBox::Init()
data.SysMemSlicePitch = 0; data.SysMemSlicePitch = 0;
HRESULT hr; HRESULT hr;
hr = D3D::device->CreateBuffer(&desc, &data, &s_bbox_buffer); hr = D3D::device->CreateBuffer(&desc, &data, &s_bbox_buffer);
CHECK(SUCCEEDED(hr), "create bbox buffer"); CHECK(SUCCEEDED(hr), "Create BoundingBox Buffer.");
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_buffer, "boundingbox buffer"); D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_buffer, "BoundingBox Buffer");
// Second to use as a staging buffer.
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.BindFlags = 0; desc.BindFlags = 0;
hr = D3D::device->CreateBuffer(&desc, nullptr, &s_bbox_Readbuffer); hr = D3D::device->CreateBuffer(&desc, nullptr, &s_bbox_staging_buffer);
CHECK(SUCCEEDED(hr), "create bbox staging buffer"); CHECK(SUCCEEDED(hr), "Create BoundingBox Staging Buffer.");
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_Readbuffer, "boundingbox staging buffer"); D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_staging_buffer, "BoundingBox Staging Buffer");
D3D11_UNORDERED_ACCESS_VIEW_DESC UAVdesc; // UAV is required to allow concurrent access.
memset(&UAVdesc, 0, sizeof(UAVdesc)); D3D11_UNORDERED_ACCESS_VIEW_DESC UAVdesc = {};
UAVdesc.Format = DXGI_FORMAT_R32_SINT; UAVdesc.Format = DXGI_FORMAT_R32_SINT;
UAVdesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; UAVdesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
UAVdesc.Buffer.FirstElement = 0; UAVdesc.Buffer.FirstElement = 0;
UAVdesc.Buffer.Flags = 0; UAVdesc.Buffer.Flags = 0;
UAVdesc.Buffer.NumElements = 4; UAVdesc.Buffer.NumElements = 4;
hr = D3D::device->CreateUnorderedAccessView(s_bbox_buffer, &UAVdesc, &s_bbox_uav); hr = D3D::device->CreateUnorderedAccessView(s_bbox_buffer, &UAVdesc, &s_bbox_uav);
CHECK(SUCCEEDED(hr), "create bbox UAV"); CHECK(SUCCEEDED(hr), "Create BoundingBox UAV.");
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_uav, "boundingbox UAV"); D3D::SetDebugObjectName((ID3D11DeviceChild*)s_bbox_uav, "BoundingBox UAV");
} }
} }
@ -60,10 +63,10 @@ void BBox::Shutdown()
s_bbox_buffer->Release(); s_bbox_buffer->Release();
s_bbox_buffer = nullptr; s_bbox_buffer = nullptr;
} }
if (s_bbox_Readbuffer != nullptr) if (s_bbox_staging_buffer != nullptr)
{ {
s_bbox_Readbuffer->Release(); s_bbox_staging_buffer->Release();
s_bbox_Readbuffer = nullptr; s_bbox_staging_buffer = nullptr;
} }
if (s_bbox_uav != nullptr) if (s_bbox_uav != nullptr)
{ {
@ -81,14 +84,14 @@ void BBox::Set(int index, int value)
int BBox::Get(int index) int BBox::Get(int index)
{ {
int data = 0; 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; 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)) if (SUCCEEDED(hr))
{ {
data = ((s32*)map.pData)[index]; data = ((s32*)map.pData)[index];
} }
D3D::context->Unmap(s_bbox_Readbuffer, 0); D3D::context->Unmap(s_bbox_staging_buffer, 0);
return data; return data;
} }

View File

@ -77,8 +77,7 @@ void InitBackendInfo()
g_Config.backend_info.bSupportsExclusiveFullscreen = true; g_Config.backend_info.bSupportsExclusiveFullscreen = true;
g_Config.backend_info.bSupportsDualSourceBlend = true; g_Config.backend_info.bSupportsDualSourceBlend = true;
g_Config.backend_info.bSupportsPrimitiveRestart = true; g_Config.backend_info.bSupportsPrimitiveRestart = true;
g_Config.backend_info.bSupportsOversizedViewports = false; g_Config.backend_info.bSupportsOversizedViewports = false;
g_Config.backend_info.bSupportsBBox = true;
g_Config.backend_info.bSupportsStereoscopy = false; // TODO: not implemented g_Config.backend_info.bSupportsStereoscopy = false; // TODO: not implemented
IDXGIFactory* factory; IDXGIFactory* factory;
@ -114,8 +113,12 @@ void InitBackendInfo()
g_Config.backend_info.AAModes.push_back(samples); g_Config.backend_info.AAModes.push_back(samples);
} }
bool shader_model_5_supported = (DX11::D3D::GetFeatureLevel(ad) >= D3D_FEATURE_LEVEL_11_0);
// Requires the earlydepthstencil attribute (only available in shader model 5) // Requires the earlydepthstencil attribute (only available in shader model 5)
g_Config.backend_info.bSupportsEarlyZ = (DX11::D3D::GetFeatureLevel(ad) == D3D_FEATURE_LEVEL_11_0); g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported;
// Requires full UAV functionality (only available in shader model 5)
g_Config.backend_info.bSupportsBBox = shader_model_5_supported;
} }
g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description)); g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description));