From 027efebd48bc34225f0412f25833d91649e4c55e Mon Sep 17 00:00:00 2001 From: Caleb Burke Date: Wed, 26 Aug 2026 11:42:49 -0700 Subject: [PATCH] removing compute smoke test --- engine/include/sophia/compute_smoke_test.hpp | 14 --- engine/src/compute_smoke_test.cpp | 112 ------------------- 2 files changed, 126 deletions(-) delete mode 100644 engine/include/sophia/compute_smoke_test.hpp delete mode 100644 engine/src/compute_smoke_test.cpp diff --git a/engine/include/sophia/compute_smoke_test.hpp b/engine/include/sophia/compute_smoke_test.hpp deleted file mode 100644 index 2267190..0000000 --- a/engine/include/sophia/compute_smoke_test.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include - -namespace sophia { - -// Minimal end-to-end compute dispatch: compiles the GLSL compute shader at -// `computeShaderPath`, builds the descriptor/pipeline layer around a small -// storage buffer, dispatches it, reads the buffer back, and verifies the -// result against what the shader is expected to compute. Logs the outcome -// and throws std::runtime_error if the GPU result doesn't match. -void runComputeSmokeTest(const std::string& computeShaderPath); - -} // namespace sophia diff --git a/engine/src/compute_smoke_test.cpp b/engine/src/compute_smoke_test.cpp deleted file mode 100644 index 393d32a..0000000 --- a/engine/src/compute_smoke_test.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "buffer.hpp" -#include "descriptors/descriptor_pool.hpp" -#include "descriptors/descriptor_set_layout.hpp" -#include "descriptors/descriptor_writer.hpp" -#include "device.hpp" -#include "pipelines/compute_pipeline.hpp" -#include "shader.hpp" - -namespace sophia { - -namespace { - -constexpr u32 kElementCount = 256; -constexpr u32 kWorkgroupSize = 64; - -} // namespace - -void runComputeSmokeTest(const std::string& computeShaderPath) { - auto device = Device::Builder().headless().build(); - - Buffer buffer{*device, sizeof(f32), kElementCount, - vk::BufferUsageFlagBits::eStorageBuffer, - vk::MemoryPropertyFlagBits::eHostVisible | - vk::MemoryPropertyFlagBits::eHostCoherent}; - - std::vector input(kElementCount); - for (u32 i = 0; i < kElementCount; i++) { - input[i] = static_cast(i); - } - - buffer.map(); - buffer.writeToBuffer(input.data(), sizeof(f32) * kElementCount); - buffer.unmap(); - - auto shader = Shader::Builder() - .fromGLSL(computeShaderPath) - .setStage(ShaderStage::COMPUTE) - .build(); - - auto setLayout = DescriptorSetLayout::Builder(*device) - .addBinding(0, vk::DescriptorType::eStorageBuffer, - vk::ShaderStageFlagBits::eCompute) - .build(); - - auto pool = DescriptorPool::Builder(*device) - .addPoolSize(vk::DescriptorType::eStorageBuffer, 1) - .setMaxSets(1) - .build(); - - vk::DescriptorBufferInfo bufferInfo = buffer.descriptorInfo(); - vk::DescriptorSet descriptorSet; - if (!DescriptorWriter(*setLayout, *pool) - .writeBuffer(0, &bufferInfo) - .build(descriptorSet)) { - log::fatal("compute smoke test: failed to allocate descriptor set"); - throw std::runtime_error( - "compute smoke test: failed to allocate descriptor set"); - } - - vk::DescriptorSetLayout rawSetLayout = setLayout->getDescriptorSetLayout(); - vk::PipelineLayoutCreateInfo pipelineLayoutInfo{}; - pipelineLayoutInfo.setLayoutCount = 1; - pipelineLayoutInfo.pSetLayouts = &rawSetLayout; - - vk::UniquePipelineLayout pipelineLayout = - device->get()->createPipelineLayoutUnique(pipelineLayoutInfo); - - std::unique_ptr computePipeline = - ComputePipeline::Builder(*device) - .setShader(*shader) - .setPipelineLayout(pipelineLayout.get()) - .build(); - - vk::CommandBuffer commandBuffer = device->beginSingleTimeCommands(); - computePipeline->bind(commandBuffer); - commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eCompute, - pipelineLayout.get(), 0, descriptorSet, {}); - commandBuffer.dispatch((kElementCount + kWorkgroupSize - 1) / kWorkgroupSize, - 1, 1); - device->endSingleTimeCommands(commandBuffer); - - std::vector output(kElementCount); - buffer.map(); - std::memcpy(output.data(), buffer.getMappedMemory(), - sizeof(f32) * kElementCount); - buffer.unmap(); - - u32 mismatches = 0; - for (u32 i = 0; i < kElementCount; i++) { - f32 expected = input[i] * 2.0f; - if (std::fabs(output[i] - expected) > 1e-4f) { - mismatches++; - } - } - - if (mismatches > 0) { - log::fatal("compute smoke test FAILED:", mismatches, "/", kElementCount, - "elements mismatched"); - throw std::runtime_error("compute smoke test: GPU result did not match"); - } - - log::info("compute smoke test PASSED:", kElementCount, "elements verified"); -} - -} // namespace sophia