upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/d3d12_xs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/shims/d3d12_xs.cpp')
-rw-r--r--runtime/shims/d3d12_xs.cpp66
1 files changed, 37 insertions, 29 deletions
diff --git a/runtime/shims/d3d12_xs.cpp b/runtime/shims/d3d12_xs.cpp
index 3e7626d92..85997fce7 100644
--- a/runtime/shims/d3d12_xs.cpp
+++ b/runtime/shims/d3d12_xs.cpp
@@ -18,6 +18,7 @@
18#ifdef LEONIDA_VULKAN_DEVICE 18#ifdef LEONIDA_VULKAN_DEVICE
19#include "d3d12_com.h" 19#include "d3d12_com.h"
20#endif 20#endif
21#include "d3d12_trace.h"
21#include "d3d12_xs_device.h" 22#include "d3d12_xs_device.h"
22#include "d3d12_xs_rootsig.h" 23#include "d3d12_xs_rootsig.h"
23#include "shims.h" 24#include "shims.h"
@@ -121,26 +122,31 @@ HRESULT WINAPI create_root_signature_deserializer(const void* data, SIZE_T size,
121// (96 bytes) and no more. The PC D3D12CreateDevice needs a minimum feature level instead, so 12_0 is used as the 122// (96 bytes) and no more. The PC D3D12CreateDevice needs a minimum feature level instead, so 12_0 is used as the
122// least restrictive floor; higher feature levels are still exposed by the created device. 123// least restrictive floor; higher feature levels are still exposed by the created device.
123HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, const IID* riid, void** out) { 124HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, const IID* riid, void** out) {
124 if (!out) return E_POINTER; 125 constexpr auto method = "D3D12XboxCreateDevice";
126 using rt::d3d12_trace::result;
127 if (!out) return result(method, E_POINTER);
125 *out = nullptr; 128 *out = nullptr;
126 if (!riid) return E_POINTER; 129 if (!riid) return result(method, E_POINTER);
127 130
128 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice adapter=%p params=%p riid=%08lx-%04x-%04x\n", 131 const bool tracing = rt::d3d12_trace::enabled();
129 adapter, params, static_cast<unsigned long>(riid->Data1), riid->Data2, riid->Data3); 132 if (!tracing) {
130 if (params) { 133 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice adapter=%p params=%p riid=%08lx-%04x-%04x\n",
131 const uint32_t* words = static_cast<const uint32_t*>(params); 134 adapter, params, static_cast<unsigned long>(riid->Data1), riid->Data2, riid->Data3);
132 char line[24 * 11 + 1]; 135 if (params) {
133 line[0] = '\0'; 136 const uint32_t* words = static_cast<const uint32_t*>(params);
134 size_t used = 0; 137 char line[24 * 11 + 1];
135 for (int i = 0; i < 24 && used < sizeof(line); ++i) { 138 line[0] = '\0';
136 int n = std::snprintf(line + used, sizeof(line) - used, "%s%08x", i ? " " : "", 139 size_t used = 0;
137 static_cast<unsigned>(words[i])); 140 for (int i = 0; i < 24 && used < sizeof(line); ++i) {
138 if (n < 0) break; 141 int n = std::snprintf(line + used, sizeof(line) - used, "%s%08x", i ? " " : "",
139 used += static_cast<size_t>(n); 142 static_cast<unsigned>(words[i]));
143 if (n < 0) break;
144 used += static_cast<size_t>(n);
145 }
146 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice params[24] =%s\n", line);
147 } else {
148 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice params = null\n");
140 } 149 }
141 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice params[24] =%s\n", line);
142 } else {
143 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice params = null\n");
144 } 150 }
145 151
146 static std::atomic<bool> proxy_logged{false}; 152 static std::atomic<bool> proxy_logged{false};
@@ -162,24 +168,25 @@ HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, cons
162 if (FAILED(vhr)) { 168 if (FAILED(vhr)) {
163 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice: Vulkan device failed (hr=0x%08lx)\n", 169 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice: Vulkan device failed (hr=0x%08lx)\n",
164 static_cast<unsigned long>(vhr)); 170 static_cast<unsigned long>(vhr));
165 return vhr; 171 return result(method, vhr);
166 } 172 }
167 vhr = rt::d3d12_xs::create_device_proxy(vulkan, *riid, out); 173 vhr = rt::d3d12_xs::create_device_proxy(vulkan, *riid, out);
168 if (FAILED(vhr)) { 174 if (FAILED(vhr)) {
169 vulkan->Release(); 175 vulkan->Release();
170 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice: proxy over the Vulkan device failed " 176 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice: proxy over the Vulkan device failed "
171 "(hr=0x%08lx)\n", static_cast<unsigned long>(vhr)); 177 "(hr=0x%08lx)\n", static_cast<unsigned long>(vhr));
172 return vhr; 178 return result(method, vhr);
173 } 179 }
174 rt::d3d12::set_device_outer(vulkan, static_cast<IUnknown*>(*out)); 180 rt::d3d12::set_device_outer(vulkan, static_cast<IUnknown*>(*out));
175 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice -> proxy %p (Vulkan device %p)\n", *out, 181 if (!tracing)
176 static_cast<void*>(vulkan)); 182 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice -> proxy %p (Vulkan device %p)\n", *out,
177 return S_OK; 183 static_cast<void*>(vulkan));
184 return result(method, S_OK);
178 } 185 }
179#endif 186#endif
180 187
181 static auto create = reinterpret_cast<CreateDeviceFn>(host("D3D12CreateDevice")); 188 static auto create = reinterpret_cast<CreateDeviceFn>(host("D3D12CreateDevice"));
182 if (!create) return E_NOTIMPL; 189 if (!create) return result(method, E_NOTIMPL);
183 190
184 ID3D12Device* real = nullptr; 191 ID3D12Device* real = nullptr;
185 HRESULT hr = create(adapter, D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), 192 HRESULT hr = create(adapter, D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device),
@@ -188,7 +195,7 @@ HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, cons
188 if (real) real->Release(); 195 if (real) real->Release();
189 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice: PC D3D12CreateDevice failed (hr=0x%08lx)\n", 196 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice: PC D3D12CreateDevice failed (hr=0x%08lx)\n",
190 static_cast<unsigned long>(hr)); 197 static_cast<unsigned long>(hr));
191 return FAILED(hr) ? hr : E_FAIL; 198 return result(method, FAILED(hr) ? hr : E_FAIL);
192 } 199 }
193 200
194 hr = rt::d3d12_xs::create_device_proxy(real, *riid, out); 201 hr = rt::d3d12_xs::create_device_proxy(real, *riid, out);
@@ -197,11 +204,12 @@ HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, cons
197 real->Release(); 204 real->Release();
198 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice: proxy creation failed (hr=0x%08lx)\n", 205 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice: proxy creation failed (hr=0x%08lx)\n",
199 static_cast<unsigned long>(hr)); 206 static_cast<unsigned long>(hr));
200 return hr; 207 return result(method, hr);
201 } 208 }
202 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice -> proxy %p (PC device %p)\n", *out, 209 if (!tracing)
203 static_cast<void*>(real)); 210 std::fprintf(stderr, "[rt] d3d12_xs: D3D12XboxCreateDevice -> proxy %p (PC device %p)\n", *out,
204 return S_OK; 211 static_cast<void*>(real));
212 return result(method, S_OK);
205} 213}
206 214
207static_assert(std::is_same_v<decltype(&serialize_root_signature), SerializeFn>); 215static_assert(std::is_same_v<decltype(&serialize_root_signature), SerializeFn>);