Files
mirage/tests/utils/mock_window.cpp
daiqingshuang 2f7d23bf26 Add Vulkan compute scheduler tests and supporting utilities
- Implemented ComputeSchedulerTest to validate device management, task scheduling, and resource cleanup for the compute scheduler.
- Created mock_window class for testing Vulkan surface creation, supporting both headless and windowed modes.
- Added shader_loader utility for loading SPIR-V shaders from files and providing minimal embedded shaders for testing.
- Introduced test_helpers for creating and destroying shader modules, validating device features, and finding memory types.
- Established VulkanTestBase and VulkanGPUTest classes to streamline Vulkan test setup and teardown processes.
2025-11-23 11:32:01 +08:00

69 lines
2.3 KiB
C++

#include "mock_window.h"
#include <stdexcept>
namespace mirage::render::vulkan::test {
auto mock_window::create(const create_info& info) -> std::expected<mock_window, std::string> {
// In headless mode, we don't create a real window
if (info.headless) {
return mock_window(info.width, info.height, true, nullptr);
}
// For non-headless mode, we would need platform-specific window creation
// For now, we'll just create a mock with nullptr handle
// In a real implementation, this would use GLFW or platform APIs
return mock_window(info.width, info.height, false, nullptr);
}
mock_window::mock_window(uint32_t width, uint32_t height, bool headless, void* native_handle)
: width_(width), height_(height), headless_(headless), native_handle_(native_handle) {
}
mock_window::~mock_window() {
// Cleanup would happen here
// In headless mode, nothing to clean up
// In window mode, would destroy platform window
}
mock_window::mock_window(mock_window&& other) noexcept
: width_(other.width_)
, height_(other.height_)
, headless_(other.headless_)
, native_handle_(other.native_handle_) {
other.width_ = 0;
other.height_ = 0;
other.headless_ = false;
other.native_handle_ = nullptr;
}
mock_window& mock_window::operator=(mock_window&& other) noexcept {
if (this != &other) {
width_ = other.width_;
height_ = other.height_;
headless_ = other.headless_;
native_handle_ = other.native_handle_;
other.width_ = 0;
other.height_ = 0;
other.headless_ = false;
other.native_handle_ = nullptr;
}
return *this;
}
auto mock_window::create_surface(vk::Instance instance) -> expected<vk::SurfaceKHR> {
if (headless_) {
// In headless mode, we can't create a real surface
// Tests should skip surface-dependent operations when headless
return std::unexpected(vk::Result::eErrorInitializationFailed);
}
// For non-headless mode, would create platform-specific surface
// This is a simplified implementation for testing
// Real implementation would use vkCreateWin32SurfaceKHR, vkCreateXlibSurfaceKHR, etc.
// Return an error for now since we don't have real window implementation
return std::unexpected(vk::Result::eErrorFeatureNotPresent);
}
} // namespace mirage::render::vulkan::test