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:
@@ -9,43 +9,36 @@
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
namespace coop::mock
|
||||
{
|
||||
namespace
|
||||
{
|
||||
namespace coop::mock {
|
||||
namespace {
|
||||
constexpr UINT kBackBuffers = 3; // DX12 rotates these explicitly -- the case the capture must get right
|
||||
|
||||
class Dx12Backend : public RenderBackend
|
||||
{
|
||||
public:
|
||||
class Dx12Backend : public RenderBackend {
|
||||
public:
|
||||
bool init(HWND hwnd, std::uint32_t width, std::uint32_t height) override
|
||||
{
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
|
||||
if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(device_.GetAddressOf()))))
|
||||
{
|
||||
if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(device_.GetAddressOf())))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
D3D12_COMMAND_QUEUE_DESC qd = {};
|
||||
qd.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
if (FAILED(device_->CreateCommandQueue(&qd, IID_PPV_ARGS(queue_.GetAddressOf()))))
|
||||
{
|
||||
if (FAILED(device_->CreateCommandQueue(&qd, IID_PPV_ARGS(queue_.GetAddressOf())))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ComPtr<IDXGIFactory4> factory;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(factory.GetAddressOf()))))
|
||||
{
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(factory.GetAddressOf())))) {
|
||||
return false;
|
||||
}
|
||||
// Uncapped (the mock is a perf fixture): a flip-model swapchain needs ALLOW_TEARING to run
|
||||
// free of vsync.
|
||||
ComPtr<IDXGIFactory5> factory5;
|
||||
BOOL tearing = FALSE;
|
||||
if (SUCCEEDED(factory.As(&factory5)))
|
||||
{
|
||||
if (SUCCEEDED(factory.As(&factory5))) {
|
||||
factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &tearing, sizeof(tearing));
|
||||
}
|
||||
tearing_ = tearing != 0;
|
||||
@@ -60,10 +53,8 @@ public:
|
||||
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
||||
desc.Flags = tearing_ ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0u;
|
||||
ComPtr<IDXGISwapChain1> sc1;
|
||||
if (FAILED(factory->CreateSwapChainForHwnd(queue_.Get(), hwnd, &desc, nullptr, nullptr,
|
||||
sc1.GetAddressOf())) ||
|
||||
FAILED(sc1.As(&swap_)))
|
||||
{
|
||||
if (FAILED(factory->CreateSwapChainForHwnd(queue_.Get(), hwnd, &desc, nullptr, nullptr, sc1.GetAddressOf()))
|
||||
|| FAILED(sc1.As(&swap_))) {
|
||||
return false;
|
||||
}
|
||||
factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
|
||||
@@ -71,36 +62,30 @@ public:
|
||||
D3D12_DESCRIPTOR_HEAP_DESC hd = {};
|
||||
hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
|
||||
hd.NumDescriptors = kBackBuffers;
|
||||
if (FAILED(device_->CreateDescriptorHeap(&hd, IID_PPV_ARGS(rtv_heap_.GetAddressOf()))))
|
||||
{
|
||||
if (FAILED(device_->CreateDescriptorHeap(&hd, IID_PPV_ARGS(rtv_heap_.GetAddressOf())))) {
|
||||
return false;
|
||||
}
|
||||
rtv_stride_ = device_->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE h = rtv_heap_->GetCPUDescriptorHandleForHeapStart();
|
||||
for (UINT i = 0; i < kBackBuffers; ++i)
|
||||
{
|
||||
if (FAILED(swap_->GetBuffer(i, IID_PPV_ARGS(targets_[i].GetAddressOf()))))
|
||||
{
|
||||
for (UINT i = 0; i < kBackBuffers; ++i) {
|
||||
if (FAILED(swap_->GetBuffer(i, IID_PPV_ARGS(targets_[i].GetAddressOf())))) {
|
||||
return false;
|
||||
}
|
||||
device_->CreateRenderTargetView(targets_[i].Get(), nullptr, h);
|
||||
rtv_handles_[i] = h;
|
||||
h.ptr += rtv_stride_;
|
||||
if (FAILED(device_->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
IID_PPV_ARGS(allocs_[i].GetAddressOf()))))
|
||||
{
|
||||
IID_PPV_ARGS(allocs_[i].GetAddressOf())))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (FAILED(device_->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocs_[0].Get(), nullptr,
|
||||
IID_PPV_ARGS(list_.GetAddressOf()))))
|
||||
{
|
||||
IID_PPV_ARGS(list_.GetAddressOf())))) {
|
||||
return false;
|
||||
}
|
||||
list_->Close();
|
||||
|
||||
if (FAILED(device_->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(fence_.GetAddressOf()))))
|
||||
{
|
||||
if (FAILED(device_->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(fence_.GetAddressOf())))) {
|
||||
return false;
|
||||
}
|
||||
fence_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
@@ -138,24 +123,19 @@ public:
|
||||
wait_for_gpu(); // simple per-frame sync (mock game: correctness over throughput)
|
||||
}
|
||||
|
||||
[[nodiscard]] const char* name() const override
|
||||
{
|
||||
return "dx12";
|
||||
}
|
||||
[[nodiscard]] const char* name() const override { return "dx12"; }
|
||||
|
||||
~Dx12Backend() override
|
||||
{
|
||||
if (fence_ != nullptr)
|
||||
{
|
||||
if (fence_ != nullptr) {
|
||||
wait_for_gpu();
|
||||
}
|
||||
if (fence_event_ != nullptr)
|
||||
{
|
||||
if (fence_event_ != nullptr) {
|
||||
CloseHandle(fence_event_);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
void transition(ID3D12Resource* res, D3D12_RESOURCE_STATES from, D3D12_RESOURCE_STATES to)
|
||||
{
|
||||
D3D12_RESOURCE_BARRIER b = {};
|
||||
@@ -171,8 +151,7 @@ private:
|
||||
{
|
||||
const UINT64 v = ++fence_value_;
|
||||
queue_->Signal(fence_.Get(), v);
|
||||
if (fence_->GetCompletedValue() < v)
|
||||
{
|
||||
if (fence_->GetCompletedValue() < v) {
|
||||
fence_->SetEventOnCompletion(v, fence_event_);
|
||||
WaitForSingleObject(fence_event_, INFINITE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user