Skip to content

Commit

Permalink
updated GPU validation code
Browse files Browse the repository at this point in the history
  • Loading branch information
Devaniti committed Dec 23, 2023
1 parent 55f6e06 commit c885aa1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
45 changes: 37 additions & 8 deletions D3D12Backend/APIWrappers/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ namespace Boolka
{

Device::Device()
: m_Device(nullptr)
, m_Adapter(nullptr)
: m_Adapter(nullptr)
, m_Device(nullptr)
, m_SupportsRaytracing(false)
{
}

Expand Down Expand Up @@ -193,10 +194,10 @@ namespace Boolka

if (m_Adapter == nullptr)
{
m_Adapter = adapter;
m_Device = device;
}
else
m_Adapter = adapter;
m_Device = device;
}
else
{
adapter->Release();
device->Release();
Expand All @@ -208,8 +209,8 @@ namespace Boolka

if (m_Adapter != nullptr)
{
return true;
}
return true;
}

::MessageBoxW(0,
L"No supported GPUs found.\nRequired features are:\nResource Binding Tier 3\n"
Expand All @@ -235,6 +236,8 @@ namespace Boolka
void Device::InitializeDebug()
{
SetDebugBreakSeverity(D3D12_MESSAGE_SEVERITY_WARNING);
SetGPUBasedValidationShaderPatchMode(
D3D12_GPU_BASED_VALIDATION_SHADER_PATCH_MODE_GUARDED_VALIDATION);
}

void Device::SetDebugBreakSeverity(D3D12_MESSAGE_SEVERITY severity)
Expand Down Expand Up @@ -277,6 +280,32 @@ namespace Boolka
BLK_ASSERT(refCount == 1);
}

void Device::SetGPUBasedValidationShaderPatchMode(
D3D12_GPU_BASED_VALIDATION_SHADER_PATCH_MODE patchMode)
{
ID3D12DebugDevice2* debugDevice = nullptr;
HRESULT hr = m_Device->QueryInterface(IID_PPV_ARGS(&debugDevice));
if (FAILED(hr))
{
return;
}
D3D12_DEBUG_DEVICE_GPU_BASED_VALIDATION_SETTINGS settings = {};
hr = debugDevice->GetDebugParameter(
D3D12_DEBUG_DEVICE_PARAMETER_GPU_BASED_VALIDATION_SETTINGS, &settings,
sizeof(settings));
if (FAILED(hr))
{
debugDevice->Release();
return;
}
settings.DefaultShaderPatchMode = patchMode;
hr = debugDevice->SetDebugParameter(
D3D12_DEBUG_DEVICE_PARAMETER_GPU_BASED_VALIDATION_SETTINGS, &settings,
sizeof(settings));
BLK_ASSERT(SUCCEEDED(hr));
debugDevice->Release();
}

void Device::FilterMessage(D3D12_MESSAGE_ID id)
{
FilterMessage(&id, 1);
Expand Down
2 changes: 2 additions & 0 deletions D3D12Backend/APIWrappers/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace Boolka
#ifdef BLK_RENDER_DEBUG
void InitializeDebug();
void SetDebugBreakSeverity(D3D12_MESSAGE_SEVERITY severity);
void SetGPUBasedValidationShaderPatchMode(
D3D12_GPU_BASED_VALIDATION_SHADER_PATCH_MODE patchMode);
void ReportDeviceObjectLeaks();
#endif

Expand Down
2 changes: 1 addition & 1 deletion D3D12Backend/ProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define BLK_RENDER_DEBUG
#define BLK_RENDER_DEVICE_LOST_DEBUG
#define BLK_RENDER_PROFILING
//#define BLK_USE_GPU_VALIDATION
#define BLK_USE_GPU_VALIDATION
#elif defined(BLK_CONFIGURATION_DEVELOPMENT)
#define BLK_RENDER_DEVICE_LOST_DEBUG
#define BLK_RENDER_PROFILING
Expand Down
32 changes: 18 additions & 14 deletions D3D12Backend/RenderPasses/DebugOverlayPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,29 +476,33 @@ namespace Boolka

static const size_t elementsPerLine = 16;

bool anyFlagsFound = false;

static bool interpretAsFloat = false;
ImGui::Checkbox("Interpret values as float", &interpretAsFloat);

for (size_t i = 0; i < BLK_DEBUG_DATA_ELEMENT_COUNT; ++i)
size_t end = 0;
for (size_t i = BLK_DEBUG_DATA_ELEMENT_COUNT - 1; i < BLK_DEBUG_DATA_ELEMENT_COUNT; --i)
{
if (debugStats.gpuDebugMarkers[i])
{
end = i + 1;
break;
}
}

for (size_t i = 0; i < end; ++i)
{
uint markerValue = debugStats.gpuDebugMarkers[i];
if (markerValue)
if (interpretAsFloat)
{
anyFlagsFound = true;
if (interpretAsFloat)
{
ImGui::Text("Flag %d - data %f", i, asfloat(markerValue));
}
else
{
ImGui::Text("Flag %d - data %d", i, markerValue);
}
ImGui::Text("Flag %d - data %f", i, asfloat(markerValue));
}
else
{
ImGui::Text("Flag %d - data %d", i, markerValue);
}
}

if (!anyFlagsFound)
if (end == 0)
{
ImGui::TextUnformatted("No flags set");
}
Expand Down

0 comments on commit c885aa1

Please sign in to comment.