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:
@@ -30,8 +30,7 @@
|
||||
|
||||
#include "vk_capture.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
double now_ms()
|
||||
{
|
||||
LARGE_INTEGER f, c;
|
||||
@@ -44,15 +43,13 @@ int g_failures = 0;
|
||||
void check(bool ok, const char* what)
|
||||
{
|
||||
std::printf("%s %s\n", ok ? " ok:" : "FAIL:", what);
|
||||
if (!ok)
|
||||
{
|
||||
if (!ok) {
|
||||
++g_failures;
|
||||
}
|
||||
}
|
||||
|
||||
// Everything the test resolves from the device (superset of VkCapture::Fns + image-build helpers).
|
||||
struct DevFns
|
||||
{
|
||||
struct DevFns {
|
||||
PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
|
||||
PFN_vkGetDeviceQueue GetDeviceQueue;
|
||||
PFN_vkCreateCommandPool CreateCommandPool;
|
||||
@@ -94,10 +91,8 @@ VkPhysicalDeviceMemoryProperties g_memprops{};
|
||||
|
||||
bool find_mem(std::uint32_t type_bits, VkMemoryPropertyFlags want, std::uint32_t& out)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < g_memprops.memoryTypeCount; ++i)
|
||||
{
|
||||
if ((type_bits & (1u << i)) && (g_memprops.memoryTypes[i].propertyFlags & want) == want)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < g_memprops.memoryTypeCount; ++i) {
|
||||
if ((type_bits & (1u << i)) && (g_memprops.memoryTypes[i].propertyFlags & want) == want) {
|
||||
out = i;
|
||||
return true;
|
||||
}
|
||||
@@ -146,14 +141,12 @@ int main(int argc, char** argv)
|
||||
const std::uint32_t W = 1920, H = 1080; // the resolution where the stall was measured
|
||||
|
||||
HMODULE vk = LoadLibraryW(L"vulkan-1.dll");
|
||||
if (vk == nullptr)
|
||||
{
|
||||
if (vk == nullptr) {
|
||||
std::printf("SKIP vk_capture_perf_test (no vulkan-1.dll)\n");
|
||||
return 0;
|
||||
}
|
||||
auto gipa = reinterpret_cast<PFN_vkGetInstanceProcAddr>(GetProcAddress(vk, "vkGetInstanceProcAddr"));
|
||||
if (gipa == nullptr)
|
||||
{
|
||||
if (gipa == nullptr) {
|
||||
std::printf("SKIP vk_capture_perf_test (no vkGetInstanceProcAddr)\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -166,8 +159,7 @@ int main(int argc, char** argv)
|
||||
app.apiVersion = VK_API_VERSION_1_1;
|
||||
VkInstanceCreateInfo ci{VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
|
||||
ci.pApplicationInfo = &app;
|
||||
if (create == nullptr || create(&ci, nullptr, &instance) != VK_SUCCESS)
|
||||
{
|
||||
if (create == nullptr || create(&ci, nullptr, &instance) != VK_SUCCESS) {
|
||||
std::printf("SKIP vk_capture_perf_test (vkCreateInstance failed)\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -182,8 +174,7 @@ int main(int argc, char** argv)
|
||||
|
||||
std::uint32_t n = 0;
|
||||
EnumeratePhysicalDevices(instance, &n, nullptr);
|
||||
if (n == 0)
|
||||
{
|
||||
if (n == 0) {
|
||||
std::printf("SKIP vk_capture_perf_test (no physical devices)\n");
|
||||
DestroyInstance(instance, nullptr);
|
||||
return 0;
|
||||
@@ -197,16 +188,13 @@ int main(int argc, char** argv)
|
||||
std::vector<VkQueueFamilyProperties> qf(qn);
|
||||
GetPhysicalDeviceQueueFamilyProperties(gpu, &qn, qf.data());
|
||||
std::uint32_t qfam = UINT32_MAX;
|
||||
for (std::uint32_t i = 0; i < qn; ++i)
|
||||
{
|
||||
if (qf[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < qn; ++i) {
|
||||
if (qf[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
|
||||
qfam = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (qfam == UINT32_MAX)
|
||||
{
|
||||
if (qfam == UINT32_MAX) {
|
||||
std::printf("SKIP vk_capture_perf_test (no graphics queue)\n");
|
||||
DestroyInstance(instance, nullptr);
|
||||
return 0;
|
||||
@@ -221,8 +209,7 @@ int main(int argc, char** argv)
|
||||
dci.queueCreateInfoCount = 1;
|
||||
dci.pQueueCreateInfos = &qci;
|
||||
VkDevice device = VK_NULL_HANDLE;
|
||||
if (CreateDevice(gpu, &dci, nullptr, &device) != VK_SUCCESS)
|
||||
{
|
||||
if (CreateDevice(gpu, &dci, nullptr, &device) != VK_SUCCESS) {
|
||||
std::printf("SKIP vk_capture_perf_test (vkCreateDevice failed)\n");
|
||||
DestroyInstance(instance, nullptr);
|
||||
return 0;
|
||||
@@ -264,8 +251,8 @@ int main(int argc, char** argv)
|
||||
d.UnmapMemory = DFN(UnmapMemory);
|
||||
d.InvalidateMappedMemoryRanges = DFN(InvalidateMappedMemoryRanges);
|
||||
d.DeviceWaitIdle = DFN(DeviceWaitIdle);
|
||||
d.GetPhysicalDeviceMemoryProperties =
|
||||
reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(gipa(instance, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
d.GetPhysicalDeviceMemoryProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(
|
||||
gipa(instance, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
|
||||
d.GetPhysicalDeviceMemoryProperties(gpu, &g_memprops);
|
||||
|
||||
@@ -300,13 +287,11 @@ int main(int argc, char** argv)
|
||||
// --- Build the known source image (BGRA gradient) in PRESENT_SRC layout ------------------------
|
||||
const VkDeviceSize bytes = static_cast<VkDeviceSize>(W) * H * 4;
|
||||
std::vector<unsigned char> gradient(bytes);
|
||||
for (std::uint32_t y = 0; y < H; ++y)
|
||||
{
|
||||
for (std::uint32_t x = 0; x < W; ++x)
|
||||
{
|
||||
for (std::uint32_t y = 0; y < H; ++y) {
|
||||
for (std::uint32_t x = 0; x < W; ++x) {
|
||||
unsigned char* p = &gradient[(static_cast<size_t>(y) * W + x) * 4];
|
||||
p[0] = static_cast<unsigned char>(x & 0xFF); // B
|
||||
p[1] = static_cast<unsigned char>(y & 0xFF); // G
|
||||
p[0] = static_cast<unsigned char>(x & 0xFF); // B
|
||||
p[1] = static_cast<unsigned char>(y & 0xFF); // G
|
||||
p[2] = static_cast<unsigned char>((x + y) & 0xFF); // R
|
||||
p[3] = 255;
|
||||
}
|
||||
@@ -347,8 +332,7 @@ int main(int argc, char** argv)
|
||||
ici.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
ici.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
ici.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
if (d.CreateImage(device, &ici, nullptr, &img) != VK_SUCCESS)
|
||||
{
|
||||
if (d.CreateImage(device, &ici, nullptr, &img) != VK_SUCCESS) {
|
||||
std::printf("SKIP vk_capture_perf_test (CreateImage failed)\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -362,8 +346,7 @@ int main(int argc, char** argv)
|
||||
d.AllocateMemory(device, &mai, nullptr, &imgmem);
|
||||
d.BindImageMemory(device, img, imgmem, 0);
|
||||
}
|
||||
auto barrier = [&](VkCommandBuffer c, VkImageLayout from, VkImageLayout to, VkAccessFlags src,
|
||||
VkAccessFlags dst) {
|
||||
auto barrier = [&](VkCommandBuffer c, VkImageLayout from, VkImageLayout to, VkAccessFlags src, VkAccessFlags dst) {
|
||||
VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER};
|
||||
b.srcAccessMask = src;
|
||||
b.dstAccessMask = dst;
|
||||
@@ -373,8 +356,8 @@ int main(int argc, char** argv)
|
||||
b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
b.image = img;
|
||||
b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
d.CmdPipelineBarrier(c, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
|
||||
nullptr, 0, nullptr, 1, &b);
|
||||
d.CmdPipelineBarrier(c, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
|
||||
0, nullptr, 1, &b);
|
||||
};
|
||||
{
|
||||
VkCommandBufferBeginInfo bi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
|
||||
@@ -385,8 +368,8 @@ int main(int argc, char** argv)
|
||||
r.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
r.imageExtent = {W, H, 1};
|
||||
d.CmdCopyBufferToImage(cb, upbuf, img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &r);
|
||||
barrier(cb, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT);
|
||||
barrier(cb, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_ACCESS_MEMORY_READ_BIT);
|
||||
d.EndCommandBuffer(cb);
|
||||
submit_wait(cb);
|
||||
}
|
||||
@@ -417,24 +400,22 @@ int main(int argc, char** argv)
|
||||
bi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
d.ResetCommandBuffer(cb, 0);
|
||||
d.BeginCommandBuffer(cb, &bi);
|
||||
barrier(cb, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_ACCESS_MEMORY_READ_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
barrier(cb, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_ACCESS_MEMORY_READ_BIT,
|
||||
VK_ACCESS_TRANSFER_READ_BIT);
|
||||
VkBufferImageCopy r{};
|
||||
r.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
r.imageExtent = {W, H, 1};
|
||||
d.CmdCopyImageToBuffer(cb, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, ref_buf, 1, &r);
|
||||
barrier(cb, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_MEMORY_READ_BIT);
|
||||
barrier(cb, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_ACCESS_TRANSFER_READ_BIT,
|
||||
VK_ACCESS_MEMORY_READ_BIT);
|
||||
d.EndCommandBuffer(cb);
|
||||
submit_wait(cb);
|
||||
const auto* src = static_cast<const unsigned char*>(ref_mapped);
|
||||
const size_t row = static_cast<size_t>(W) * 4;
|
||||
for (std::uint32_t y = 0; y < H; ++y)
|
||||
{
|
||||
for (std::uint32_t y = 0; y < H; ++y) {
|
||||
const unsigned char* in = src + static_cast<size_t>(y) * row;
|
||||
unsigned char* o = ref_rgba.data() + static_cast<size_t>(y) * row;
|
||||
for (std::uint32_t x = 0; x < W; ++x)
|
||||
{
|
||||
for (std::uint32_t x = 0; x < W; ++x) {
|
||||
o[x * 4 + 0] = in[x * 4 + 2];
|
||||
o[x * 4 + 1] = in[x * 4 + 1];
|
||||
o[x * 4 + 2] = in[x * 4 + 0];
|
||||
@@ -448,8 +429,7 @@ int main(int argc, char** argv)
|
||||
sync_capture(); // warm
|
||||
double sync_ms = 0;
|
||||
const int iters = 8;
|
||||
for (int i = 0; i < iters; ++i)
|
||||
{
|
||||
for (int i = 0; i < iters; ++i) {
|
||||
const double t0 = now_ms();
|
||||
sync_capture();
|
||||
sync_ms += now_ms() - t0;
|
||||
@@ -460,8 +440,7 @@ int main(int argc, char** argv)
|
||||
double sut_ms = sync_ms; // in --sync repro mode the measured path IS the synchronous one
|
||||
bool image_ok = true;
|
||||
|
||||
if (!sync_repro)
|
||||
{
|
||||
if (!sync_repro) {
|
||||
// --- The fix under test: VkCapture (async reaper) -----------------------------------------
|
||||
coop::hook::VkCapture cap;
|
||||
cap.init(gpu, device, qfam, capture_fns(d), GetCurrentProcessId(), nullptr);
|
||||
@@ -477,11 +456,9 @@ int main(int argc, char** argv)
|
||||
};
|
||||
|
||||
// Warm up (first calls allocate staging / create the D3D texture on the reaper).
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
VkSemaphore sem = VK_NULL_HANDLE;
|
||||
if (cap.present(img, VK_FORMAT_B8G8R8A8_UNORM, W, H, nullptr, 0, sem))
|
||||
{
|
||||
if (cap.present(img, VK_FORMAT_B8G8R8A8_UNORM, W, H, nullptr, 0, sem)) {
|
||||
consume(sem);
|
||||
}
|
||||
Sleep(2);
|
||||
@@ -490,14 +467,12 @@ int main(int argc, char** argv)
|
||||
int queued = 0;
|
||||
double t = 0;
|
||||
const int loop = 240;
|
||||
for (int i = 0; i < loop; ++i)
|
||||
{
|
||||
for (int i = 0; i < loop; ++i) {
|
||||
VkSemaphore sem = VK_NULL_HANDLE;
|
||||
const double t0 = now_ms();
|
||||
const bool did = cap.present(img, VK_FORMAT_B8G8R8A8_UNORM, W, H, nullptr, 0, sem);
|
||||
t += now_ms() - t0;
|
||||
if (did)
|
||||
{
|
||||
if (did) {
|
||||
consume(sem);
|
||||
++queued;
|
||||
}
|
||||
@@ -511,12 +486,9 @@ int main(int argc, char** argv)
|
||||
Sleep(50);
|
||||
std::vector<unsigned char> got;
|
||||
std::uint32_t gw = 0, gh = 0;
|
||||
if (cap.last_frame(got, gw, gh) && gw == W && gh == H)
|
||||
{
|
||||
if (cap.last_frame(got, gw, gh) && gw == W && gh == H) {
|
||||
image_ok = std::memcmp(got.data(), ref_rgba.data(), bytes) == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
image_ok = false;
|
||||
}
|
||||
check(cap.frames_published() > 0, "VkCapture published frames");
|
||||
|
||||
Reference in New Issue
Block a user