// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #define VULKAN_HPP_NO_EXCEPTIONS #define VULKAN_HPP_NO_CONSTRUCTORS #define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 #include #include #include #include #include #include #include #include namespace gcn_test { struct DispatchSize { std::uint32_t x = 1, y = 1, z = 1; }; enum class Error { NoSuitableDevice, InstanceCreationFailed, DeviceCreationFailed, ShaderCreationFailed, BufferAllocationFailed, CommandSubmissionFailed, PushConstantTooLarge, OutputTooLarge, ExecutionFailed, }; struct ErrorInfo { Error code; std::string message; }; class Runner { public: static std::expected instance(); std::expected run_raw( std::span spirv, std::span push_constants, std::span output, DispatchSize dispatch = {} ); template std::expected run( std::span spirv, const PushT& push, DispatchSize dispatch = {} ) { static_assert(std::is_trivially_copyable_v); static_assert(std::is_trivially_copyable_v); OutputT result{}; auto r = run_raw( spirv, {reinterpret_cast(&push), sizeof(PushT)}, {reinterpret_cast(&result), sizeof(OutputT)}, dispatch ); if (!r) return std::unexpected(r.error()); return result; } template std::expected run( std::span spirv, DispatchSize dispatch = {} ) { static_assert(std::is_trivially_copyable_v); OutputT result{}; auto r = run_raw( spirv, {}, {reinterpret_cast(&result), sizeof(OutputT)}, dispatch ); if (!r) return std::unexpected(r.error()); return result; } ~Runner(); Runner(const Runner&) = delete; Runner& operator=(const Runner&) = delete; private: Runner() = default; std::expected initialize(); vk::Instance instance_; vk::PhysicalDevice physical_device_; vk::Device device_; vk::Queue queue_; std::uint32_t queue_family_ = 0; vk::CommandPool command_pool_; vk::CommandBuffer command_buffer_; // cached, reset per call vk::Fence fence_; // cached, reset per call vk::DescriptorSetLayout descriptor_set_layout_; // push-descriptor vk::PipelineLayout pipeline_layout_; std::uint32_t max_push_constant_size_ = 128; }; } // namespace gcn_test