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:
@@ -28,15 +28,13 @@
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -45,8 +43,7 @@ void check(bool ok, const char* what)
|
||||
template <typename T>
|
||||
void release(T*& p)
|
||||
{
|
||||
if (p)
|
||||
{
|
||||
if (p) {
|
||||
p->Release();
|
||||
p = nullptr;
|
||||
}
|
||||
@@ -68,8 +65,7 @@ int main()
|
||||
{
|
||||
// --- Host side: SharedBlock (named by our pid) so the hook's IpcClient connects.
|
||||
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;
|
||||
}
|
||||
@@ -82,8 +78,7 @@ int main()
|
||||
check(ipc.connect(10, 5), "IPC client connect");
|
||||
|
||||
// --- Install the Present hook (inline-hooks IDXGISwapChain::Present). ---
|
||||
if (!hook::install_present_hooks(ipc))
|
||||
{
|
||||
if (!hook::install_present_hooks(ipc)) {
|
||||
std::printf("SKIP: could not install the Present hook (no D3D11 device?)\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -114,22 +109,18 @@ int main()
|
||||
ID3D11DeviceContext* ctx = nullptr;
|
||||
HRESULT hr = D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0,
|
||||
D3D11_SDK_VERSION, &scd, &swapchain, &device, nullptr, &ctx);
|
||||
if (FAILED(hr) || swapchain == nullptr)
|
||||
{
|
||||
if (FAILED(hr) || swapchain == nullptr) {
|
||||
std::printf("SKIP: could not create a D3D11 swapchain (hr=0x%08lX)\n", static_cast<unsigned long>(hr));
|
||||
hook::remove_present_hooks();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Clear the backbuffer to the known color, then Present (fires the detour).
|
||||
for (int frame = 0; frame < 3; ++frame)
|
||||
{
|
||||
for (int frame = 0; frame < 3; ++frame) {
|
||||
ID3D11Texture2D* back = nullptr;
|
||||
if (SUCCEEDED(swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&back))))
|
||||
{
|
||||
if (SUCCEEDED(swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&back)))) {
|
||||
ID3D11RenderTargetView* rtv = nullptr;
|
||||
if (SUCCEEDED(device->CreateRenderTargetView(back, nullptr, &rtv)))
|
||||
{
|
||||
if (SUCCEEDED(device->CreateRenderTargetView(back, nullptr, &rtv))) {
|
||||
ctx->ClearRenderTargetView(rtv, kClear);
|
||||
ctx->Flush();
|
||||
rtv->Release();
|
||||
@@ -141,8 +132,8 @@ int main()
|
||||
|
||||
std::printf("present_calls=%llu frames_shared=%llu video{gen=%u %ux%u fmt=%u}\n",
|
||||
static_cast<unsigned long long>(hook::present_calls()),
|
||||
static_cast<unsigned long long>(hook::present_frames_shared()),
|
||||
block->video.generation.load(), block->video.width, block->video.height, block->video.format);
|
||||
static_cast<unsigned long long>(hook::present_frames_shared()), block->video.generation.load(),
|
||||
block->video.width, block->video.height, block->video.format);
|
||||
|
||||
check(hook::present_calls() >= 3, "Present detour fired");
|
||||
check(hook::present_frames_shared() > 0, "backbuffer copied into the shared texture");
|
||||
@@ -156,19 +147,16 @@ 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)))
|
||||
{
|
||||
if (SUCCEEDED(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION,
|
||||
&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{};
|
||||
@@ -180,33 +168,25 @@ int main()
|
||||
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 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);
|
||||
@@ -222,11 +202,9 @@ int main()
|
||||
{
|
||||
auto render = [&] {
|
||||
ID3D11Texture2D* back = nullptr;
|
||||
if (SUCCEEDED(swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&back))))
|
||||
{
|
||||
if (SUCCEEDED(swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&back)))) {
|
||||
ID3D11RenderTargetView* rtv = nullptr;
|
||||
if (SUCCEEDED(device->CreateRenderTargetView(back, nullptr, &rtv)))
|
||||
{
|
||||
if (SUCCEEDED(device->CreateRenderTargetView(back, nullptr, &rtv))) {
|
||||
ctx->ClearRenderTargetView(rtv, kClear);
|
||||
ctx->Flush();
|
||||
rtv->Release();
|
||||
|
||||
Reference in New Issue
Block a user