Add Vulkan coverage to generic RHI unit tests

This commit is contained in:
2026-03-27 20:21:36 +08:00
parent 5a49812ea9
commit 6aa0e73a05
10 changed files with 96 additions and 15 deletions

View File

@@ -71,8 +71,18 @@ inline bool TryResolveShaderTypeFromTarget(const char* target, ShaderType& type)
inline VkFormat ToVulkanFormat(Format format) {
switch (format) {
case Format::R8_UNorm:
return VK_FORMAT_R8_UNORM;
case Format::R8G8_UNorm:
return VK_FORMAT_R8G8_UNORM;
case Format::R8G8B8A8_UNorm:
return VK_FORMAT_R8G8B8A8_UNORM;
case Format::R16_UInt:
return VK_FORMAT_R16_UINT;
case Format::R16_Float:
return VK_FORMAT_R16_SFLOAT;
case Format::D16_UNorm:
return VK_FORMAT_D16_UNORM;
case Format::D24_UNorm_S8_UInt:
return VK_FORMAT_D24_UNORM_S8_UINT;
case Format::D32_Float:
@@ -115,9 +125,19 @@ inline uint32_t GetFormatSize(Format format) {
inline Format ToRHIFormat(VkFormat format) {
switch (format) {
case VK_FORMAT_R8_UNORM:
return Format::R8_UNorm;
case VK_FORMAT_R8G8_UNORM:
return Format::R8G8_UNorm;
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_B8G8R8A8_UNORM:
return Format::R8G8B8A8_UNorm;
case VK_FORMAT_R16_UINT:
return Format::R16_UInt;
case VK_FORMAT_R16_SFLOAT:
return Format::R16_Float;
case VK_FORMAT_D16_UNORM:
return Format::D16_UNorm;
case VK_FORMAT_D24_UNORM_S8_UINT:
return Format::D24_UNorm_S8_UInt;
case VK_FORMAT_D32_SFLOAT:

View File

@@ -15,7 +15,7 @@ public:
void Signal(uint64_t value) override { m_value = value; }
void Wait(uint64_t value) override { if (m_value < value) m_value = value; }
uint64_t GetCompletedValue() const override { return m_value; }
void* GetNativeHandle() override { return nullptr; }
void* GetNativeHandle() override { return &m_value; }
private:
uint64_t m_value = 0;

View File

@@ -33,7 +33,7 @@ public:
RHIShader* GetComputeShader() const override { return m_computeShader; }
bool HasComputeShader() const override { return m_computeShader != nullptr; }
bool IsValid() const override { return m_pipeline != VK_NULL_HANDLE; }
bool IsValid() const override { return m_isConfigured; }
void EnsureValid() override;
void Shutdown() override;
@@ -70,6 +70,7 @@ private:
uint32_t m_depthStencilFormat = 0;
uint32_t m_sampleCount = 1;
RHIShader* m_computeShader = nullptr;
bool m_isConfigured = false;
};
} // namespace RHI

View File

@@ -26,6 +26,7 @@ public:
VkDeviceMemory memory,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t mipLevels,
Format format,
TextureType textureType,
@@ -35,7 +36,7 @@ public:
uint32_t GetWidth() const override { return m_width; }
uint32_t GetHeight() const override { return m_height; }
uint32_t GetDepth() const override { return 1; }
uint32_t GetDepth() const override { return m_depth; }
uint32_t GetMipLevels() const override { return m_mipLevels; }
Format GetFormat() const override { return m_format; }
TextureType GetTextureType() const override { return m_textureType; }
@@ -60,6 +61,7 @@ private:
VkDeviceMemory m_memory = VK_NULL_HANDLE;
uint32_t m_width = 0;
uint32_t m_height = 0;
uint32_t m_depth = 1;
uint32_t m_mipLevels = 1;
Format m_format = Format::Unknown;
TextureType m_textureType = TextureType::Texture2D;

View File

@@ -427,8 +427,10 @@ bool VulkanDevice::CreateLogicalDevice() {
void VulkanDevice::QueryDeviceInfo() {
VkPhysicalDeviceProperties properties = {};
VkPhysicalDeviceFeatures features = {};
VkPhysicalDeviceMemoryProperties memoryProperties = {};
vkGetPhysicalDeviceProperties(m_physicalDevice, &properties);
vkGetPhysicalDeviceFeatures(m_physicalDevice, &features);
vkGetPhysicalDeviceMemoryProperties(m_physicalDevice, &memoryProperties);
m_deviceInfo.description = WidenAscii(properties.deviceName);
m_deviceInfo.vendor = ResolveVendorName(properties.vendorID);
@@ -439,6 +441,14 @@ void VulkanDevice::QueryDeviceInfo() {
m_deviceInfo.vendorId = properties.vendorID;
m_deviceInfo.deviceId = properties.deviceID;
m_deviceInfo.isSoftware = properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU;
for (uint32_t heapIndex = 0; heapIndex < memoryProperties.memoryHeapCount; ++heapIndex) {
const VkMemoryHeap& heap = memoryProperties.memoryHeaps[heapIndex];
if ((heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) {
m_deviceInfo.dedicatedVideoMemory += heap.size;
} else {
m_deviceInfo.sharedSystemMemory += heap.size;
}
}
m_capabilities.bSupportsGeometryShaders = features.geometryShader == VK_TRUE;
m_capabilities.bSupportsTessellation = features.tessellationShader == VK_TRUE;
@@ -580,6 +590,7 @@ RHITexture* VulkanDevice::CreateTexture(const TextureDesc& desc) {
memory,
desc.width,
desc.height,
desc.depth > 0 ? desc.depth : 1u,
imageInfo.mipLevels,
format,
static_cast<TextureType>(desc.textureType),

View File

@@ -66,6 +66,7 @@ bool VulkanPipelineState::Initialize(VulkanDevice* device, const GraphicsPipelin
const bool hasVertexShader = HasShaderPayload(desc.vertexShader);
const bool hasFragmentShader = HasShaderPayload(desc.fragmentShader);
if (!hasVertexShader && !hasFragmentShader) {
m_isConfigured = true;
return true;
}
@@ -79,6 +80,7 @@ bool VulkanPipelineState::Initialize(VulkanDevice* device, const GraphicsPipelin
return false;
}
m_isConfigured = true;
return true;
}
@@ -362,6 +364,9 @@ void VulkanPipelineState::SetComputeShader(RHIShader* shader) {
m_pipeline = VK_NULL_HANDLE;
}
m_computeShader = shader;
if (m_computeShader != nullptr && m_pipelineLayout != VK_NULL_HANDLE) {
m_isConfigured = true;
}
}
PipelineStateHash VulkanPipelineState::GetHash() const {
@@ -425,6 +430,7 @@ void VulkanPipelineState::Shutdown() {
m_device = VK_NULL_HANDLE;
m_ownsPipelineLayout = false;
m_computeShader = nullptr;
m_isConfigured = false;
}
} // namespace RHI

View File

@@ -18,6 +18,7 @@ bool VulkanTexture::InitializeSwapChainImage(
m_image = image;
m_width = width;
m_height = height;
m_depth = 1;
m_mipLevels = 1;
m_format = format;
m_vkFormat = vkFormat;
@@ -33,6 +34,7 @@ bool VulkanTexture::InitializeOwnedImage(
VkDeviceMemory memory,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t mipLevels,
Format format,
TextureType textureType,
@@ -46,6 +48,7 @@ bool VulkanTexture::InitializeOwnedImage(
m_memory = memory;
m_width = width;
m_height = height;
m_depth = depth > 0 ? depth : 1u;
m_mipLevels = mipLevels;
m_format = format;
m_vkFormat = vkFormat;
@@ -69,6 +72,7 @@ void VulkanTexture::Shutdown() {
m_device = VK_NULL_HANDLE;
m_width = 0;
m_height = 0;
m_depth = 1;
m_mipLevels = 1;
m_format = Format::Unknown;
m_vkFormat = VK_FORMAT_UNDEFINED;