upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authormrp1no <137657338+mrp1no@users.noreply.github.com>2026-11-22 19:24:07 +0100
committermrp1no <137657338+mrp1no@users.noreply.github.com>2026-11-22 19:24:07 +0100
commit55a073183e15b461b1c4e059308d9bc25b44cdb8 (patch)
tree369c8f3147ef1927fa4ec1a9d52524d861da922e /runtime
parentb0a9c16d216acee1738ec561c51db972f319f00d (diff)
d3d12: SetName is readable as WKPDID_D3DDebugObjectNameW, with the right GUID
@pwu2775-dev found on #2533 that the tests' WKPDID_D3DDebugObjectNameW was mistyped ({4cca5fd8-921f-42c8-8599-d2866a3e5f7e}, the layer's old constant) instead of d3dcommon.h's {4cca5fd8-921f-42c8-8566-70caf2a9b741}. Measured with the right key, the host runtime does what D3D12 documents: SetName is SetPrivateData with that key and the name with its terminator, GetPrivateData reads it back (an empty name is a 2-byte entry), and the narrow key is not touched. SetName(nullptr) faults in the host and leaves the name as it was. So the name goes back into the private data, now under the right GUID, and the separate name_ / debug_name() are gone. SetName(nullptr) answers E_INVALIDARG and changes nothing. d3d12_private_data_test: 667 steps compared, 0 mismatches (RTX 3060, driver 610.88); d3d12_debug_markers_test checks the name again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/d3d12_com_object.h21
-rw-r--r--runtime/test/d3d12_debug_markers_test.cpp16
-rw-r--r--runtime/test/d3d12_private_data_test.cpp2
3 files changed, 19 insertions, 20 deletions
diff --git a/runtime/shims/d3d12_com_object.h b/runtime/shims/d3d12_com_object.h
index e45fcd29f..6b3ddf4ef 100644
--- a/runtime/shims/d3d12_com_object.h
+++ b/runtime/shims/d3d12_com_object.h
@@ -11,7 +11,6 @@
11#include <cstring> 11#include <cstring>
12#include <cwchar> 12#include <cwchar>
13#include <mutex> 13#include <mutex>
14#include <string>
15#include <utility> 14#include <utility>
16#include <vector> 15#include <vector>
17 16
@@ -98,20 +97,17 @@ public:
98 return S_OK; 97 return S_OK;
99 } 98 }
100 99
101 // The host runtime doesn't keep the name where GetPrivateData can read it (WKPDID_D3DDebugObjectNameW and the 100 // SetName is SetPrivateData with WKPDID_D3DDebugObjectNameW and the name with its terminator, as D3D12 documents
102 // narrow key both stay missing), so the name is kept apart. A null name, which the host runtime faults on, 101 // and the host runtime does: GetPrivateData reads it back (an empty name is a 2-byte entry), and the narrow
103 // clears it. 102 // WKPDID_D3DDebugObjectName is not touched. A null name, which the host runtime faults on, changes nothing.
104 HRESULT STDMETHODCALLTYPE SetName(LPCWSTR name) override { 103 HRESULT STDMETHODCALLTYPE SetName(LPCWSTR name) override {
105 std::lock_guard lock(data_mutex_); 104 if (!name) return E_INVALIDARG;
106 name_.assign(name ? name : L""); 105 return SetPrivateData(kDebugObjectNameW, UINT((std::wcslen(name) + 1) * sizeof(wchar_t)), name);
107 return S_OK;
108 } 106 }
109 107
110 // The name SetName gave the object, or an empty string. 108 // WKPDID_D3DDebugObjectNameW (d3dcommon.h), spelled out so nothing needs dxguid.lib.
111 std::wstring debug_name() { 109 static constexpr GUID kDebugObjectNameW{0x4cca5fd8, 0x921f, 0x42c8,
112 std::lock_guard lock(data_mutex_); 110 {0x85, 0x66, 0x70, 0xca, 0xf2, 0xa9, 0xb7, 0x41}};
113 return name_;
114 }
115 111
116 // The implementation behind a public interface pointer, or null when it is not a T. No reference is added. 112 // The implementation behind a public interface pointer, or null when it is not a T. No reference is added.
117 template<class T> 113 template<class T>
@@ -165,7 +161,6 @@ private:
165 std::atomic<ULONG> refs_{1}; 161 std::atomic<ULONG> refs_{1};
166 std::mutex data_mutex_; 162 std::mutex data_mutex_;
167 std::vector<PrivateData> data_; 163 std::vector<PrivateData> data_;
168 std::wstring name_;
169}; 164};
170 165
171// An ID3D12DeviceChild: holds a reference to its device, as D3D12 children do, and GetDevice returns it. When the 166// An ID3D12DeviceChild: holds a reference to its device, as D3D12 children do, and GetDevice returns it. When the
diff --git a/runtime/test/d3d12_debug_markers_test.cpp b/runtime/test/d3d12_debug_markers_test.cpp
index 1be8fffed..a87fd030f 100644
--- a/runtime/test/d3d12_debug_markers_test.cpp
+++ b/runtime/test/d3d12_debug_markers_test.cpp
@@ -186,7 +186,7 @@ struct Counted final : IUnknown {
186constexpr GUID kKey{0xd3d24a01, 0x0000, 0x4000, {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}; 186constexpr GUID kKey{0xd3d24a01, 0x0000, 0x4000, {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}};
187constexpr GUID kOtherKey{0xd3d24a01, 0x0000, 0x4000, {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}; 187constexpr GUID kOtherKey{0xd3d24a01, 0x0000, 0x4000, {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}};
188// WKPDID_D3DDebugObjectNameW (d3dcommon.h). 188// WKPDID_D3DDebugObjectNameW (d3dcommon.h).
189constexpr GUID kDebugObjectNameW{0x4cca5fd8, 0x921f, 0x42c8, {0x85, 0x99, 0xd2, 0x86, 0x6a, 0x3e, 0x5f, 0x7e}}; 189constexpr GUID kDebugObjectNameW{0x4cca5fd8, 0x921f, 0x42c8, {0x85, 0x66, 0x70, 0xca, 0xf2, 0xa9, 0xb7, 0x41}};
190 190
191int check_private_data(ID3D12Object* object, const char* what) { 191int check_private_data(ID3D12Object* object, const char* what) {
192 std::printf("private data: %s\n", what); 192 std::printf("private data: %s\n", what);
@@ -230,13 +230,17 @@ int check_private_data(ID3D12Object* object, const char* what) {
230 EXPECT(object->SetPrivateData(kKey, 0, nullptr) == S_OK); 230 EXPECT(object->SetPrivateData(kKey, 0, nullptr) == S_OK);
231 EXPECT(object->GetPrivateData(kKey, &size, nullptr) == DXGI_ERROR_NOT_FOUND && size == 0); 231 EXPECT(object->GetPrivateData(kKey, &size, nullptr) == DXGI_ERROR_NOT_FOUND && size == 0);
232 232
233 // SetName is not readable through GetPrivateData, as on the host runtime: WKPDID_D3DDebugObjectNameW stays 233 // SetName is readable as WKPDID_D3DDebugObjectNameW, terminator included, as on the host runtime. A null name
234 // missing. A null name (which the host faults on) clears it. 234 // (which the host faults on) changes nothing.
235 const wchar_t name[] = L"leonida object"; 235 const wchar_t name[] = L"leonida object";
236 EXPECT(object->SetName(name) == S_OK); 236 EXPECT(object->SetName(name) == S_OK);
237 size = 0; 237 wchar_t stored[32] = {};
238 EXPECT(object->GetPrivateData(kDebugObjectNameW, &size, nullptr) == DXGI_ERROR_NOT_FOUND && size == 0); 238 size = sizeof(stored);
239 EXPECT(object->SetName(nullptr) == S_OK); 239 EXPECT(object->GetPrivateData(kDebugObjectNameW, &size, stored) == S_OK);
240 EXPECT(size == sizeof(name) && std::wcscmp(stored, name) == 0);
241 EXPECT(object->SetName(nullptr) == E_INVALIDARG);
242 size = sizeof(stored);
243 EXPECT(object->GetPrivateData(kDebugObjectNameW, &size, stored) == S_OK && size == sizeof(name));
240 244
241 // Left set: released when the object dies (checked for a fence below). 245 // Left set: released when the object dies (checked for a fence below).
242 EXPECT(object->SetPrivateDataInterface(kOtherKey, nullptr) == S_OK); 246 EXPECT(object->SetPrivateDataInterface(kOtherKey, nullptr) == S_OK);
diff --git a/runtime/test/d3d12_private_data_test.cpp b/runtime/test/d3d12_private_data_test.cpp
index 4c1848a9c..8acacb049 100644
--- a/runtime/test/d3d12_private_data_test.cpp
+++ b/runtime/test/d3d12_private_data_test.cpp
@@ -51,7 +51,7 @@ public:
51 51
52// WKPDID_D3DDebugObjectName / ...NameW (d3dcommon.h), spelled out so nothing needs dxguid.lib. 52// WKPDID_D3DDebugObjectName / ...NameW (d3dcommon.h), spelled out so nothing needs dxguid.lib.
53constexpr GUID kName{0x429b8c22, 0x9188, 0x4b0c, {0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00}}; 53constexpr GUID kName{0x429b8c22, 0x9188, 0x4b0c, {0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00}};
54constexpr GUID kNameW{0x4cca5fd8, 0x921f, 0x42c8, {0x85, 0x99, 0xd2, 0x86, 0x6a, 0x3e, 0x5f, 0x7e}}; 54constexpr GUID kNameW{0x4cca5fd8, 0x921f, 0x42c8, {0x85, 0x66, 0x70, 0xca, 0xf2, 0xa9, 0xb7, 0x41}};
55 55
56// A key of its own for each step, so no step sees another's entry. 56// A key of its own for each step, so no step sees another's entry.
57GUID key(unsigned step) { return GUID{0x5eed0000u + step, 0x1d3d, 0x4c12, {0x9a, 0x41, 0x77, 0x10, 0x2b, 0x6c, 0x00, 0x01}}; } 57GUID key(unsigned step) { return GUID{0x5eed0000u + step, 0x1d3d, 0x4c12, {0x9a, 0x41, 0x77, 0x10, 0x2b, 0x6c, 0x00, 0x01}}; }