Inside the companion
Vulkan · Signal Garden
Query a device and study a clear-color window with explicit frame and presentation lifetimes.
Project files 6
Exercise allocation boundaries
Alignment, zero inputs, overflow, and exact-budget cases without a GPU.
#include "contracts.hpp"
#include <iostream>
#include <limits>
int main() {
using signal_garden::align_up;
using signal_garden::checked_bytes;
const auto max = std::numeric_limits<std::size_t>::max();
const bool ok = align_up(0, 256) == 0 && align_up(257, 256) == 512 &&
align_up(9, 3) == 9 && align_up(10, 3) == 12 && !align_up(1, 0) &&
!align_up(max, 2) && align_up(max, 1) == max &&
checked_bytes(1024, 32, 32768) == 32768 &&
!checked_bytes(1025, 32, 32768) && !checked_bytes(max, 2, max) &&
checked_bytes(0, 32, 32768) == 0 && !checked_bytes(4, 0, 100);
if (!ok) { std::cerr << "allocation contract test failed\n"; return 1; }
std::cout << "alignment and allocation-boundary tests passed\n";
}
This is the file included with the course. Copy and download give you its complete source.
Taking your work offline? Download all course companions
