Apply clang-format across the whole tree

Run clang-format (the repo's .clang-format: LLVM base, 120 cols, tabs,
Allman functions) over every source file so the tree is formatter-clean.
Whitespace only -- no behavior change; full x64 + x86 suites pass.

Also set SortIncludes: false in .clang-format. Windows include order is
load-bearing (windows.h must precede tlhelp32.h / mmreg.h / xinput.h /
dinput.h; winsock2.h must precede windows.h), and the default
alphabetical sort reorders tlhelp32.h ahead of windows.h -- a build
break. Leaving order alone keeps the manual, correct grouping.
This commit is contained in:
2026-07-12 11:52:53 +02:00
parent c684a15fb9
commit 30eccf749d
155 changed files with 3333 additions and 6171 deletions

View File

@@ -26,14 +26,12 @@
using namespace coop;
namespace
{
namespace {
int g_failures = 0;
void check(bool ok, const char* what)
{
if (!ok)
{
if (!ok) {
std::printf(" FAIL: %s\n", what);
++g_failures;
}
@@ -42,8 +40,7 @@ void check(bool ok, const char* what)
template <typename T>
void release(T*& p)
{
if (p)
{
if (p) {
p->Release();
p = nullptr;
}
@@ -66,8 +63,7 @@ int main()
{
// --- Host side: shared block named by our pid (the hook opens the same name). ---
SharedMemory shm;
if (!shm.create(shared_memory_name(GetCurrentProcessId()), sizeof(SharedBlock)))
{
if (!shm.create(shared_memory_name(GetCurrentProcessId()), sizeof(SharedBlock))) {
std::printf("FAIL: create shared memory\n");
return 1;
}
@@ -78,8 +74,7 @@ int main()
// --- D3D12 device + direct queue. SKIP if the machine has no D3D12. ---
ID3D12Device* device = nullptr;
if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device))) || device == nullptr)
{
if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device))) || device == nullptr) {
std::printf("SKIP: no D3D12 device on this machine\n");
return 0;
}
@@ -114,8 +109,7 @@ int main()
"create D3D12 swapchain");
IDXGISwapChain* swapchain = nullptr;
IDXGISwapChain3* sc3 = nullptr; // for GetCurrentBackBufferIndex
if (sc1 != nullptr)
{
if (sc1 != nullptr) {
sc1->QueryInterface(IID_PPV_ARGS(&swapchain));
sc1->QueryInterface(IID_PPV_ARGS(&sc3));
}
@@ -128,11 +122,9 @@ int main()
device->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&rtv_heap));
const UINT rtv_size = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
ID3D12Resource* render_targets[kBuffers] = {};
if (swapchain != nullptr && rtv_heap != nullptr)
{
if (swapchain != nullptr && rtv_heap != nullptr) {
D3D12_CPU_DESCRIPTOR_HANDLE rtv = rtv_heap->GetCPUDescriptorHandleForHeapStart();
for (UINT i = 0; i < kBuffers; ++i)
{
for (UINT i = 0; i < kBuffers; ++i) {
swapchain->GetBuffer(i, IID_PPV_ARGS(&render_targets[i]));
device->CreateRenderTargetView(render_targets[i], nullptr, rtv);
rtv.ptr += rtv_size;
@@ -143,8 +135,7 @@ int main()
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator));
ID3D12GraphicsCommandList* cmdlist = nullptr;
device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocator, nullptr, IID_PPV_ARGS(&cmdlist));
if (cmdlist != nullptr)
{
if (cmdlist != nullptr) {
cmdlist->Close();
}
ID3D12Fence* fence = nullptr;
@@ -159,8 +150,7 @@ int main()
const bool can_render =
swapchain != nullptr && sc3 != nullptr && allocator != nullptr && cmdlist != nullptr && fence != nullptr;
for (int frame = 0; frame < 4 && can_render; ++frame)
{
for (int frame = 0; frame < 4 && can_render; ++frame) {
const UINT idx = sc3->GetCurrentBackBufferIndex();
allocator->Reset();
cmdlist->Reset(allocator, nullptr);
@@ -188,8 +178,7 @@ int main()
// Block until the GPU finished this frame (keeps the test simple + correct).
queue->Signal(fence, ++fence_value);
if (fence->GetCompletedValue() < fence_value)
{
if (fence->GetCompletedValue() < fence_value) {
fence->SetEventOnCompletion(fence_value, fence_event);
WaitForSingleObject(fence_event, 1000);
}
@@ -200,8 +189,7 @@ int main()
static_cast<unsigned long long>(hook::present_frames_shared()), block->video.generation.load(),
block->video.width, block->video.height, block->video.format);
if (can_render)
{
if (can_render) {
check(hook::present_calls() >= 3, "Present detour fired for the D3D12 swapchain");
check(hook::present_frames_shared() > 0, "D3D12 backbuffer bridged into the shared texture");
check(block->video.generation.load() > 0, "video generation published to IPC");
@@ -211,18 +199,15 @@ int main()
ID3D11Device* devB = nullptr;
ID3D11DeviceContext* ctxB = nullptr;
if (SUCCEEDED(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION,
&devB, nullptr, &ctxB)))
{
&devB, nullptr, &ctxB))) {
ID3D11Device1* dev1 = nullptr;
devB->QueryInterface(IID_PPV_ARGS(&dev1));
const std::wstring name = video_share_name(GetCurrentProcessId());
ID3D11Texture2D* sharedB = nullptr;
IDXGIKeyedMutex* km = nullptr;
if (dev1 != nullptr &&
SUCCEEDED(dev1->OpenSharedResourceByName(name.c_str(),
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE,
IID_PPV_ARGS(&sharedB))))
{
if (dev1 != nullptr
&& SUCCEEDED(dev1->OpenSharedResourceByName(
name.c_str(), DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, IID_PPV_ARGS(&sharedB)))) {
sharedB->QueryInterface(IID_PPV_ARGS(&km));
D3D11_TEXTURE2D_DESC sd{};
sharedB->GetDesc(&sd);
@@ -232,32 +217,24 @@ int main()
sd.MiscFlags = 0;
ID3D11Texture2D* staging = nullptr;
check(SUCCEEDED(devB->CreateTexture2D(&sd, nullptr, &staging)), "create staging texture");
if (km != nullptr && staging != nullptr && km->AcquireSync(kVideoMutexKey, 1000) == S_OK)
{
if (km != nullptr && staging != nullptr && km->AcquireSync(kVideoMutexKey, 1000) == S_OK) {
ctxB->CopyResource(staging, sharedB);
km->ReleaseSync(kVideoMutexKey);
D3D11_MAPPED_SUBRESOURCE mapped{};
if (SUCCEEDED(ctxB->Map(staging, 0, D3D11_MAP_READ, 0, &mapped)))
{
if (SUCCEEDED(ctxB->Map(staging, 0, D3D11_MAP_READ, 0, &mapped))) {
const auto* px = static_cast<const std::uint8_t*>(mapped.pData);
std::printf("readback pixel0 = {%u,%u,%u,%u}\n", px[0], px[1], px[2], px[3]);
check(near_byte(px[0], 51) && near_byte(px[1], 102) && near_byte(px[2], 153),
"shared texture carries the D3D12-rendered color");
ctxB->Unmap(staging, 0);
}
else
{
} else {
check(false, "map staging texture");
}
}
else
{
} else {
check(false, "acquire keyed mutex + copy shared texture");
}
release(staging);
}
else
{
} else {
check(false, "open shared texture by name");
}
release(km);
@@ -292,8 +269,7 @@ int main()
auto present = [&] {
swapchain->Present(0, 0);
queue->Signal(fence, ++fence_value);
if (fence->GetCompletedValue() < fence_value)
{
if (fence->GetCompletedValue() < fence_value) {
fence->SetEventOnCompletion(fence_value, fence_event);
WaitForSingleObject(fence_event, 1000);
}
@@ -309,15 +285,13 @@ int main()
hook::remove_present_hooks();
if (fence_event != nullptr)
{
if (fence_event != nullptr) {
CloseHandle(fence_event);
}
release(fence);
release(cmdlist);
release(allocator);
for (UINT i = 0; i < kBuffers; ++i)
{
for (UINT i = 0; i < kBuffers; ++i) {
release(render_targets[i]);
}
release(rtv_heap);
@@ -330,7 +304,6 @@ int main()
DestroyWindow(hwnd);
UnregisterClassW(wc.lpszClassName, wc.hInstance);
std::printf(g_failures == 0 ? "DX12 PRESENT HOOK TEST PASS\n" : "DX12 PRESENT HOOK TEST FAILED (%d)\n",
g_failures);
std::printf(g_failures == 0 ? "DX12 PRESENT HOOK TEST PASS\n" : "DX12 PRESENT HOOK TEST FAILED (%d)\n", g_failures);
return g_failures == 0 ? 0 : 1;
}