# Copyright (C) 2018-2019 The ANGLE Project Authors.
-# Copyright (C) 2019 LunarG, Inc.
+# Copyright (C) 2019, 2023 LunarG, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
public_deps = [ "$vulkan_headers_dir:vulkan_headers" ]
data_deps = [ ":vulkan_gen_icd_json_file" ]
sources = [
- "icd/generated/mock_icd.cpp",
- "icd/generated/mock_icd.h",
+ "icd/mock_icd.h",
+ "icd/mock_icd.cpp",
+ "icd/generated/function_declarations.h",
+ "icd/generated/function_definitions.h",
+ ]
+ include_dirs = [
+ "icd",
+ "icd/generated",
]
if (is_win) {
sources += [ "icd/VkICD_mock_icd.def" ]
# limitations under the License.
# ~~~
-set(MOCK_ICD_NAME mock_icd)
-set(GENERATED generated)
-
-# Enable beta Vulkan extensions
-add_definitions(-DVK_ENABLE_BETA_EXTENSIONS)
-
if(WIN32)
add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DVK_USE_PLATFORM_WIN32_KHX -DWIN32_LEAN_AND_MEAN)
elseif(ANDROID)
endif()
# Copy or link the JSON files to the binary directory for ease of use in the build tree.
-set(ICD_JSON_FILES VkICD_${MOCK_ICD_NAME})
if(WIN32)
# extra setup for out-of-tree builds
if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
if(CMAKE_GENERATOR MATCHES "^Visual Studio.*")
- foreach(config_file ${ICD_JSON_FILES})
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${config_file}.json dst_json)
- add_custom_target(${config_file}-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
- set_target_properties(${config_file}-json PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
- endforeach(config_file)
+ file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/VkICD_mock_icd.json src_json)
+ file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/VkICD_mock_icd.json dst_json)
+ add_custom_target(VkICD_mock_icd-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
+ set_target_properties(VkICD_mock_icd-json PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
else()
- foreach(config_file ${ICD_JSON_FILES})
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${config_file}.json dst_json)
- add_custom_target(${config_file}-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
- endforeach(config_file)
+ file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/VkICD_mock_icd.json src_json)
+ file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/VkICD_mock_icd.json dst_json)
+ add_custom_target(VkICD_mock_icd-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
endif()
endif()
elseif(APPLE)
if(CMAKE_GENERATOR MATCHES "^Xcode.*")
add_custom_target(mk_icd_config_dir ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
- foreach(config_file ${ICD_JSON_FILES})
- add_custom_target(${config_file}-json ALL
- DEPENDS mk_icd_config_dir
- COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/macos/${config_file}.json
- $<CONFIG> ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${config_file}.json
- VERBATIM)
- endforeach(config_file)
+ add_custom_target(VkICD_mock_icd-json ALL
+ DEPENDS mk_icd_config_dir
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/macos/VkICD_mock_icd.json
+ $<CONFIG> ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/VkICD_mock_icd.json
+ VERBATIM)
else()
- foreach(config_file ${ICD_JSON_FILES})
- add_custom_target(${config_file}-json ALL
- COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/macos/${config_file}.json
- ${config_file}.json
- VERBATIM)
- endforeach(config_file)
+ add_custom_target(VkICD_mock_icd-json ALL
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/macos/VkICD_mock_icd.json
+ VkICD_mock_icd.json
+ VERBATIM)
endif()
endif()
else()
# extra setup for out-of-tree builds
if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
- foreach(config_file ${ICD_JSON_FILES})
- add_custom_target(${config_file}-json ALL
- COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json
- ${config_file}.json
- VERBATIM)
- endforeach(config_file)
+ add_custom_target(VkICD_mock_icd-json ALL
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/linux/VkICD_mock_icd.json
+ VkICD_mock_icd.json
+ VERBATIM)
endif()
endif()
# For ICD with a direct dependency on a project with the same name, use it.
if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
- foreach(config_file ${ICD_JSON_FILES})
- add_dependencies(${config_file}-json ${config_file})
- endforeach(config_file)
+ add_dependencies(VkICD_mock_icd-json VkICD_mock_icd)
endif()
-add_custom_target(generate_icd_files DEPENDS mock_icd.h mock_icd.cpp)
+add_custom_target(generate_icd_files DEPENDS mock_icd.cpp generated/function_definitions.h generated/function_declarations.h)
set_target_properties(generate_icd_files PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
-if(WIN32)
- macro(add_vk_icd target)
- file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/VkICD_${target}.def DEF_FILE)
- add_custom_target(copy-${target}-def-file ALL
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEF_FILE} VkICD_${target}.def
- VERBATIM)
- set_target_properties(copy-${target}-def-file PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
- add_library(VkICD_${target} SHARED ${ARGN} VkICD_${target}.def)
- target_link_libraries(VkICD_${target} PRIVATE Vulkan::Headers)
- if(INSTALL_ICD)
- install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_BINDIR})
- endif()
- endmacro()
-elseif(APPLE)
- macro(add_vk_icd target)
- add_library(VkICD_${target} SHARED ${ARGN})
- target_link_libraries(VkICD_${target} PRIVATE Vulkan::Headers)
- set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl")
- if(INSTALL_ICD)
- install(TARGETS VkICD_${target} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
- endif()
- endmacro()
-else()
- macro(add_vk_icd target)
- add_library(VkICD_${target} SHARED ${ARGN})
- target_link_libraries(VkICD_${target} PRIVATE Vulkan::Headers)
- set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl,-export-dynamic,-Bsymbolic,--exclude-libs,ALL")
- if((UNIX AND NOT APPLE) AND INSTALL_ICD) # i.e. Linux
- install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
- endif()
- if (ENABLE_ADDRESS_SANITIZER)
- target_compile_options(VkICD_${target} PUBLIC -fsanitize=address)
- target_link_options(VkICD_${target} PUBLIC -fsanitize=address)
- endif ()
- endmacro()
-endif()
-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated
${WAYLAND_CLIENT_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${PROJECT_BINARY_DIR}
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare")
endif()
-add_vk_icd(${MOCK_ICD_NAME} ${GENERATED}/mock_icd.cpp ${GENERATED}/mock_icd.h)
+
+if(WIN32)
+ file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/VkICD_mock_icd.def DEF_FILE)
+ add_custom_target(copy-mock_icd-def-file ALL
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEF_FILE} VkICD_mock_icd.def
+ VERBATIM)
+ set_target_properties(copy-mock_icd-def-file PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
+ add_library(VkICD_mock_icd SHARED mock_icd.cpp VkICD_mock_icd.def)
+ target_link_libraries(VkICD_mock_icd PRIVATE Vulkan::Headers)
+ if(INSTALL_ICD)
+ install(TARGETS VkICD_mock_icd DESTINATION ${CMAKE_INSTALL_BINDIR})
+ endif()
+elseif(APPLE)
+ add_library(VkICD_mock_icd SHARED mock_icd.cpp )
+ target_link_libraries(VkICD_mock_icd PRIVATE Vulkan::Headers)
+ set_target_properties(VkICD_mock_icd PROPERTIES LINK_FLAGS "-Wl")
+ if(INSTALL_ICD)
+ install(TARGETS VkICD_mock_icd DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+ endif()
+else()
+ add_library(VkICD_mock_icd SHARED mock_icd.cpp )
+ target_link_libraries(VkICD_mock_icd PRIVATE Vulkan::Headers)
+ set_target_properties(VkICD_mock_icd PROPERTIES LINK_FLAGS "-Wl,-export-dynamic,-Bsymbolic,--exclude-libs,ALL")
+ if((UNIX AND NOT APPLE) AND INSTALL_ICD) # i.e. Linux
+ install(TARGETS VkICD_mock_icd DESTINATION ${CMAKE_INSTALL_LIBDIR})
+ endif()
+ if (ENABLE_ADDRESS_SANITIZER)
+ target_compile_options(VkICD_mock_icd PUBLIC -fsanitize=address)
+ target_link_options(VkICD_mock_icd PUBLIC -fsanitize=address)
+ endif ()
+endif()
# JSON file(s) install targets. For Linux, need to remove the "./" from the library path before installing to system directories.
if((UNIX AND NOT APPLE) AND INSTALL_ICD) # i.e. Linux
- foreach(config_file ${ICD_JSON_FILES})
- add_custom_target(${config_file}-staging-json ALL
- COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/staging-json
- COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json ${CMAKE_CURRENT_BINARY_DIR}/staging-json
- COMMAND sed -i -e "/\"library_path\":/s$./libVkICD$libVkICD$"
- ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json
- VERBATIM
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json
- DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/vulkan/icd.d)
- endforeach(config_file)
+ add_custom_target(VkICD_mock_icd-staging-json ALL
+ COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/staging-json
+ COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/linux/VkICD_mock_icd.json ${CMAKE_CURRENT_BINARY_DIR}/staging-json
+ COMMAND sed -i -e "/\"library_path\":/s$./libVkICD$libVkICD$"
+ ${CMAKE_CURRENT_BINARY_DIR}/staging-json/VkICD_mock_icd.json
+ VERBATIM
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linux/VkICD_mock_icd.json)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/staging-json/VkICD_mock_icd.json
+ DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/vulkan/icd.d)
endif()
# Windows uses the JSON file as-is.
if(WIN32 AND INSTALL_ICD)
- foreach(config_file ${ICD_JSON_FILES})
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json DESTINATION ${CMAKE_INSTALL_BINDIR})
- endforeach()
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/windows/VkICD_mock_icd.json DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
-#pragma once
-
/*
** Copyright (c) 2015-2018, 2023 The Khronos Group Inc.
**
**
*/
-#include <unordered_map>
-#include <mutex>
-#include <string>
-#include <cstring>
-#include "vulkan/vk_icd.h"
-namespace vkmock {
+#pragma once
-using mutex_t = std::mutex;
-using lock_guard_t = std::lock_guard<mutex_t>;
-using unique_lock_t = std::unique_lock<mutex_t>;
-
-static mutex_t global_lock;
-static uint64_t global_unique_handle = 1;
-static const uint32_t SUPPORTED_LOADER_ICD_INTERFACE_VERSION = 5;
-static uint32_t loader_interface_version = 0;
-static bool negotiate_loader_icd_interface_called = false;
-static void* CreateDispObjHandle() {
- auto handle = new VK_LOADER_DATA;
- set_loader_magic_value(handle);
- return handle;
-}
-static void DestroyDispObjHandle(void* handle) {
- delete reinterpret_cast<VK_LOADER_DATA*>(handle);
-}
+#include <stdint.h>
+#include <string>
+#include <unordered_map>
+#include <vulkan/vulkan.h>
+
+namespace vkmock {
// Map of instance extension name to version
static const std::unordered_map<std::string, uint32_t> instance_extension_map = {
{"vkCmdDrawMeshTasksIndirectCountEXT", (void*)CmdDrawMeshTasksIndirectCountEXT},
};
-
} // namespace vkmock
**
*/
-#include "mock_icd.h"
-#include <stdlib.h>
-#include <algorithm>
-#include <array>
-#include <vector>
-#include "vk_typemap_helper.h"
-namespace vkmock {
-
-
-using std::unordered_map;
-
-static constexpr uint32_t icd_physical_device_count = 1;
-static unordered_map<VkInstance, std::array<VkPhysicalDevice, icd_physical_device_count>> physical_device_map;
-
-// Map device memory handle to any mapped allocations that we'll need to free on unmap
-static unordered_map<VkDeviceMemory, std::vector<void*>> mapped_memory_map;
-
-// Map device memory allocation handle to the size
-static unordered_map<VkDeviceMemory, VkDeviceSize> allocated_memory_size_map;
-
-static unordered_map<VkDevice, unordered_map<uint32_t, unordered_map<uint32_t, VkQueue>>> queue_map;
-static VkDeviceAddress current_available_address = 0x10000000;
-struct BufferState {
- VkDeviceSize size;
- VkDeviceAddress address;
-};
-static unordered_map<VkDevice, unordered_map<VkBuffer, BufferState>> buffer_map;
-static unordered_map<VkDevice, unordered_map<VkImage, VkDeviceSize>> image_memory_size_map;
-static unordered_map<VkCommandPool, std::vector<VkCommandBuffer>> command_pool_buffer_map;
-
-static constexpr uint32_t icd_swapchain_image_count = 1;
-static unordered_map<VkSwapchainKHR, VkImage[icd_swapchain_image_count]> swapchain_image_map;
-
-// TODO: Would like to codegen this but limits aren't in XML
-static VkPhysicalDeviceLimits SetLimits(VkPhysicalDeviceLimits *limits) {
- limits->maxImageDimension1D = 4096;
- limits->maxImageDimension2D = 4096;
- limits->maxImageDimension3D = 256;
- limits->maxImageDimensionCube = 4096;
- limits->maxImageArrayLayers = 256;
- limits->maxTexelBufferElements = 65536;
- limits->maxUniformBufferRange = 16384;
- limits->maxStorageBufferRange = 134217728;
- limits->maxPushConstantsSize = 128;
- limits->maxMemoryAllocationCount = 4096;
- limits->maxSamplerAllocationCount = 4000;
- limits->bufferImageGranularity = 1;
- limits->sparseAddressSpaceSize = 2147483648;
- limits->maxBoundDescriptorSets = 4;
- limits->maxPerStageDescriptorSamplers = 16;
- limits->maxPerStageDescriptorUniformBuffers = 12;
- limits->maxPerStageDescriptorStorageBuffers = 4;
- limits->maxPerStageDescriptorSampledImages = 16;
- limits->maxPerStageDescriptorStorageImages = 4;
- limits->maxPerStageDescriptorInputAttachments = 4;
- limits->maxPerStageResources = 128;
- limits->maxDescriptorSetSamplers = 96;
- limits->maxDescriptorSetUniformBuffers = 72;
- limits->maxDescriptorSetUniformBuffersDynamic = 8;
- limits->maxDescriptorSetStorageBuffers = 24;
- limits->maxDescriptorSetStorageBuffersDynamic = 4;
- limits->maxDescriptorSetSampledImages = 96;
- limits->maxDescriptorSetStorageImages = 24;
- limits->maxDescriptorSetInputAttachments = 4;
- limits->maxVertexInputAttributes = 16;
- limits->maxVertexInputBindings = 16;
- limits->maxVertexInputAttributeOffset = 2047;
- limits->maxVertexInputBindingStride = 2048;
- limits->maxVertexOutputComponents = 64;
- limits->maxTessellationGenerationLevel = 64;
- limits->maxTessellationPatchSize = 32;
- limits->maxTessellationControlPerVertexInputComponents = 64;
- limits->maxTessellationControlPerVertexOutputComponents = 64;
- limits->maxTessellationControlPerPatchOutputComponents = 120;
- limits->maxTessellationControlTotalOutputComponents = 2048;
- limits->maxTessellationEvaluationInputComponents = 64;
- limits->maxTessellationEvaluationOutputComponents = 64;
- limits->maxGeometryShaderInvocations = 32;
- limits->maxGeometryInputComponents = 64;
- limits->maxGeometryOutputComponents = 64;
- limits->maxGeometryOutputVertices = 256;
- limits->maxGeometryTotalOutputComponents = 1024;
- limits->maxFragmentInputComponents = 64;
- limits->maxFragmentOutputAttachments = 4;
- limits->maxFragmentDualSrcAttachments = 1;
- limits->maxFragmentCombinedOutputResources = 4;
- limits->maxComputeSharedMemorySize = 16384;
- limits->maxComputeWorkGroupCount[0] = 65535;
- limits->maxComputeWorkGroupCount[1] = 65535;
- limits->maxComputeWorkGroupCount[2] = 65535;
- limits->maxComputeWorkGroupInvocations = 128;
- limits->maxComputeWorkGroupSize[0] = 128;
- limits->maxComputeWorkGroupSize[1] = 128;
- limits->maxComputeWorkGroupSize[2] = 64;
- limits->subPixelPrecisionBits = 4;
- limits->subTexelPrecisionBits = 4;
- limits->mipmapPrecisionBits = 4;
- limits->maxDrawIndexedIndexValue = UINT32_MAX;
- limits->maxDrawIndirectCount = UINT16_MAX;
- limits->maxSamplerLodBias = 2.0f;
- limits->maxSamplerAnisotropy = 16;
- limits->maxViewports = 16;
- limits->maxViewportDimensions[0] = 4096;
- limits->maxViewportDimensions[1] = 4096;
- limits->viewportBoundsRange[0] = -8192;
- limits->viewportBoundsRange[1] = 8191;
- limits->viewportSubPixelBits = 0;
- limits->minMemoryMapAlignment = 64;
- limits->minTexelBufferOffsetAlignment = 16;
- limits->minUniformBufferOffsetAlignment = 16;
- limits->minStorageBufferOffsetAlignment = 16;
- limits->minTexelOffset = -8;
- limits->maxTexelOffset = 7;
- limits->minTexelGatherOffset = -8;
- limits->maxTexelGatherOffset = 7;
- limits->minInterpolationOffset = 0.0f;
- limits->maxInterpolationOffset = 0.5f;
- limits->subPixelInterpolationOffsetBits = 4;
- limits->maxFramebufferWidth = 4096;
- limits->maxFramebufferHeight = 4096;
- limits->maxFramebufferLayers = 256;
- limits->framebufferColorSampleCounts = 0x7F;
- limits->framebufferDepthSampleCounts = 0x7F;
- limits->framebufferStencilSampleCounts = 0x7F;
- limits->framebufferNoAttachmentsSampleCounts = 0x7F;
- limits->maxColorAttachments = 4;
- limits->sampledImageColorSampleCounts = 0x7F;
- limits->sampledImageIntegerSampleCounts = 0x7F;
- limits->sampledImageDepthSampleCounts = 0x7F;
- limits->sampledImageStencilSampleCounts = 0x7F;
- limits->storageImageSampleCounts = 0x7F;
- limits->maxSampleMaskWords = 1;
- limits->timestampComputeAndGraphics = VK_TRUE;
- limits->timestampPeriod = 1;
- limits->maxClipDistances = 8;
- limits->maxCullDistances = 8;
- limits->maxCombinedClipAndCullDistances = 8;
- limits->discreteQueuePriorities = 2;
- limits->pointSizeRange[0] = 1.0f;
- limits->pointSizeRange[1] = 64.0f;
- limits->lineWidthRange[0] = 1.0f;
- limits->lineWidthRange[1] = 8.0f;
- limits->pointSizeGranularity = 1.0f;
- limits->lineWidthGranularity = 1.0f;
- limits->strictLines = VK_TRUE;
- limits->standardSampleLocations = VK_TRUE;
- limits->optimalBufferCopyOffsetAlignment = 1;
- limits->optimalBufferCopyRowPitchAlignment = 1;
- limits->nonCoherentAtomSize = 256;
-
- return *limits;
-}
-
-void SetBoolArrayTrue(VkBool32* bool_array, uint32_t num_bools)
-{
- for (uint32_t i = 0; i < num_bools; ++i) {
- bool_array[i] = VK_TRUE;
- }
-}
+#pragma once
-VkDeviceSize GetImageSizeFromCreateInfo(const VkImageCreateInfo* pCreateInfo)
-{
- VkDeviceSize size = pCreateInfo->extent.width;
- size *= pCreateInfo->extent.height;
- size *= pCreateInfo->extent.depth;
- // TODO: A pixel size is 32 bytes. This accounts for the largest possible pixel size of any format. It could be changed to more accurate size if need be.
- size *= 32;
- size *= pCreateInfo->arrayLayers;
- size *= (pCreateInfo->mipLevels > 1 ? 2 : 1);
-
- switch (pCreateInfo->format) {
- case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
- case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
- case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
- case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16:
- case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16:
- case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16:
- case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
- case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
- case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
- size *= 3;
- break;
- case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
- case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
- case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
- case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16:
- case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
- case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
- size *= 2;
- break;
- default:
- break;
- }
-
- return size;
-}
+#include "mock_icd.h"
+#include "function_declarations.h"
+namespace vkmock {
static VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(
//Not a CREATE or DESTROY function
}
-
-
-static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
- // TODO: This function should only care about physical device functions and return nullptr for other functions
- const auto &item = name_to_funcptr_map.find(funcName);
- if (item != name_to_funcptr_map.end()) {
- return reinterpret_cast<PFN_vkVoidFunction>(item->second);
- }
- // Mock should intercept all functions so if we get here just return null
- return nullptr;
-}
-
} // namespace vkmock
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define EXPORT __attribute__((visibility("default")))
-#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
-#define EXPORT __attribute__((visibility("default")))
-#else
-#define EXPORT
-#endif
-
-extern "C" {
-
-EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName) {
- if (!vkmock::negotiate_loader_icd_interface_called) {
- vkmock::loader_interface_version = 1;
- }
- return vkmock::GetInstanceProcAddr(instance, pName);
-}
-
-EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance, const char* pName) {
- return vkmock::GetPhysicalDeviceProcAddr(instance, pName);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) {
- vkmock::negotiate_loader_icd_interface_called = true;
- vkmock::loader_interface_version = *pSupportedVersion;
- if (*pSupportedVersion > vkmock::SUPPORTED_LOADER_ICD_INTERFACE_VERSION) {
- *pSupportedVersion = vkmock::SUPPORTED_LOADER_ICD_INTERFACE_VERSION;
- }
- return VK_SUCCESS;
-}
-
-
-EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(
- VkInstance instance,
- VkSurfaceKHR surface,
- const VkAllocationCallbacks* pAllocator)
-{
- vkmock::DestroySurfaceKHR(instance, surface, pAllocator);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
- VkPhysicalDevice physicalDevice,
- uint32_t queueFamilyIndex,
- VkSurfaceKHR surface,
- VkBool32* pSupported)
-{
- return vkmock::GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, pSupported);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
-{
- return vkmock::GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, pSurfaceCapabilities);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- uint32_t* pSurfaceFormatCount,
- VkSurfaceFormatKHR* pSurfaceFormats)
-{
- return vkmock::GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- uint32_t* pPresentModeCount,
- VkPresentModeKHR* pPresentModes)
-{
- return vkmock::GetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, pPresentModes);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(
- VkInstance instance,
- const VkDisplaySurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-
-#ifdef VK_USE_PLATFORM_XLIB_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
- VkInstance instance,
- const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_XLIB_KHR */
-
-#ifdef VK_USE_PLATFORM_XCB_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
- VkInstance instance,
- const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_XCB_KHR */
-
-#ifdef VK_USE_PLATFORM_WAYLAND_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
- VkInstance instance,
- const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_WAYLAND_KHR */
-
-#ifdef VK_USE_PLATFORM_ANDROID_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
- VkInstance instance,
- const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_ANDROID_KHR */
-
-#ifdef VK_USE_PLATFORM_WIN32_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
- VkInstance instance,
- const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_WIN32_KHR */
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHR(
- VkDevice device,
- VkSurfaceKHR surface,
- VkDeviceGroupPresentModeFlagsKHR* pModes)
-{
- return vkmock::GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHR(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- uint32_t* pRectCount,
- VkRect2D* pRects)
-{
- return vkmock::GetPhysicalDevicePresentRectanglesKHR(physicalDevice, surface, pRectCount, pRects);
-}
-
-#ifdef VK_USE_PLATFORM_VI_NN
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN(
- VkInstance instance,
- const VkViSurfaceCreateInfoNN* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateViSurfaceNN(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_VI_NN */
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2EXT(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- VkSurfaceCapabilities2EXT* pSurfaceCapabilities)
-{
- return vkmock::GetPhysicalDeviceSurfaceCapabilities2EXT(physicalDevice, surface, pSurfaceCapabilities);
-}
-
-#ifdef VK_USE_PLATFORM_IOS_MVK
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(
- VkInstance instance,
- const VkIOSSurfaceCreateInfoMVK* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateIOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_IOS_MVK */
-
-#ifdef VK_USE_PLATFORM_MACOS_MVK
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(
- VkInstance instance,
- const VkMacOSSurfaceCreateInfoMVK* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateMacOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_MACOS_MVK */
-
-} // end extern "C"
-
-
--- /dev/null
+/*
+** Copyright (c) 2015-2018, 2023 The Khronos Group Inc.
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#include "mock_icd.h"
+#include "generated/function_definitions.h"
+
+namespace vkmock {
+
+static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char* funcName) {
+ // TODO: This function should only care about physical device functions and return nullptr for other functions
+ const auto& item = name_to_funcptr_map.find(funcName);
+ if (item != name_to_funcptr_map.end()) {
+ return reinterpret_cast<PFN_vkVoidFunction>(item->second);
+ }
+ // Mock should intercept all functions so if we get here just return null
+ return nullptr;
+}
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define EXPORT __attribute__((visibility("default")))
+#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
+#define EXPORT __attribute__((visibility("default")))
+#else
+#define EXPORT
+#endif
+
+} // namespace vkmock
+
+extern "C" {
+
+EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName) {
+ if (!vkmock::negotiate_loader_icd_interface_called) {
+ vkmock::loader_interface_version = 1;
+ }
+ return vkmock::GetInstanceProcAddr(instance, pName);
+}
+
+EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance, const char* pName) {
+ return vkmock::GetPhysicalDeviceProcAddr(instance, pName);
+}
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) {
+ vkmock::negotiate_loader_icd_interface_called = true;
+ vkmock::loader_interface_version = *pSupportedVersion;
+ if (*pSupportedVersion > vkmock::SUPPORTED_LOADER_ICD_INTERFACE_VERSION) {
+ *pSupportedVersion = vkmock::SUPPORTED_LOADER_ICD_INTERFACE_VERSION;
+ }
+ return VK_SUCCESS;
+}
+
+EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
+ const VkAllocationCallbacks* pAllocator) {
+ vkmock::DestroySurfaceKHR(instance, surface, pAllocator);
+}
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
+ uint32_t queueFamilyIndex, VkSurfaceKHR surface,
+ VkBool32* pSupported) {
+ return vkmock::GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, pSupported);
+}
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
+ VkSurfaceKHR surface,
+ VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) {
+ return vkmock::GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, pSurfaceCapabilities);
+}
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
+ uint32_t* pSurfaceFormatCount,
+ VkSurfaceFormatKHR* pSurfaceFormats) {
+ return vkmock::GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
+}
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
+ VkSurfaceKHR surface, uint32_t* pPresentModeCount,
+ VkPresentModeKHR* pPresentModes) {
+ return vkmock::GetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, pPresentModes);
+}
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(VkInstance instance,
+ const VkDisplaySurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface) {
+ return vkmock::CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
+}
+
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
+ return vkmock::CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
+}
+#endif /* VK_USE_PLATFORM_XLIB_KHR */
+
+#ifdef VK_USE_PLATFORM_XCB_KHR
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
+ return vkmock::CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
+}
+#endif /* VK_USE_PLATFORM_XCB_KHR */
+
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance,
+ const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
+ return vkmock::CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
+}
+#endif /* VK_USE_PLATFORM_WAYLAND_KHR */
+
+#ifdef VK_USE_PLATFORM_ANDROID_KHR
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(VkInstance instance,
+ const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
+ return vkmock::CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
+}
+#endif /* VK_USE_PLATFORM_ANDROID_KHR */
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
+ return vkmock::CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
+}
+#endif /* VK_USE_PLATFORM_WIN32_KHR */
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHR(VkDevice device, VkSurfaceKHR surface,
+ VkDeviceGroupPresentModeFlagsKHR* pModes) {
+ return vkmock::GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
+}
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
+ uint32_t* pRectCount, VkRect2D* pRects) {
+ return vkmock::GetPhysicalDevicePresentRectanglesKHR(physicalDevice, surface, pRectCount, pRects);
+}
+
+#ifdef VK_USE_PLATFORM_VI_NN
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
+ return vkmock::CreateViSurfaceNN(instance, pCreateInfo, pAllocator, pSurface);
+}
+#endif /* VK_USE_PLATFORM_VI_NN */
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
+ VkSurfaceKHR surface,
+ VkSurfaceCapabilities2EXT* pSurfaceCapabilities) {
+ return vkmock::GetPhysicalDeviceSurfaceCapabilities2EXT(physicalDevice, surface, pSurfaceCapabilities);
+}
+
+#ifdef VK_USE_PLATFORM_IOS_MVK
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
+ return vkmock::CreateIOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
+}
+#endif /* VK_USE_PLATFORM_IOS_MVK */
+
+#ifdef VK_USE_PLATFORM_MACOS_MVK
+
+EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
+ return vkmock::CreateMacOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
+}
+#endif /* VK_USE_PLATFORM_MACOS_MVK */
+
+} // end extern "C"
--- /dev/null
+/*
+** Copyright (c) 2015-2018, 2023 The Khronos Group Inc.
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#pragma once
+
+#include <stdlib.h>
+#include <cstring>
+
+#include <algorithm>
+#include <array>
+#include <mutex>
+#include <unordered_map>
+#include <string>
+#include <vector>
+
+#include "vulkan/vk_icd.h"
+#include "generated/vk_typemap_helper.h"
+
+namespace vkmock {
+
+using mutex_t = std::mutex;
+using lock_guard_t = std::lock_guard<mutex_t>;
+using unique_lock_t = std::unique_lock<mutex_t>;
+
+static mutex_t global_lock;
+static uint64_t global_unique_handle = 1;
+static const uint32_t SUPPORTED_LOADER_ICD_INTERFACE_VERSION = 5;
+static uint32_t loader_interface_version = 0;
+static bool negotiate_loader_icd_interface_called = false;
+static void* CreateDispObjHandle() {
+ auto handle = new VK_LOADER_DATA;
+ set_loader_magic_value(handle);
+ return handle;
+}
+static void DestroyDispObjHandle(void* handle) { delete reinterpret_cast<VK_LOADER_DATA*>(handle); }
+
+static constexpr uint32_t icd_physical_device_count = 1;
+static std::unordered_map<VkInstance, std::array<VkPhysicalDevice, icd_physical_device_count>> physical_device_map;
+
+// Map device memory handle to any mapped allocations that we'll need to free on unmap
+static std::unordered_map<VkDeviceMemory, std::vector<void*>> mapped_memory_map;
+
+// Map device memory allocation handle to the size
+static std::unordered_map<VkDeviceMemory, VkDeviceSize> allocated_memory_size_map;
+
+static std::unordered_map<VkDevice, std::unordered_map<uint32_t, std::unordered_map<uint32_t, VkQueue>>> queue_map;
+static VkDeviceAddress current_available_address = 0x10000000;
+struct BufferState {
+ VkDeviceSize size;
+ VkDeviceAddress address;
+};
+static std::unordered_map<VkDevice, std::unordered_map<VkBuffer, BufferState>> buffer_map;
+static std::unordered_map<VkDevice, std::unordered_map<VkImage, VkDeviceSize>> image_memory_size_map;
+static std::unordered_map<VkCommandPool, std::vector<VkCommandBuffer>> command_pool_buffer_map;
+
+static constexpr uint32_t icd_swapchain_image_count = 1;
+static std::unordered_map<VkSwapchainKHR, VkImage[icd_swapchain_image_count]> swapchain_image_map;
+
+// TODO: Would like to codegen this but limits aren't in XML
+static VkPhysicalDeviceLimits SetLimits(VkPhysicalDeviceLimits* limits) {
+ limits->maxImageDimension1D = 4096;
+ limits->maxImageDimension2D = 4096;
+ limits->maxImageDimension3D = 256;
+ limits->maxImageDimensionCube = 4096;
+ limits->maxImageArrayLayers = 256;
+ limits->maxTexelBufferElements = 65536;
+ limits->maxUniformBufferRange = 16384;
+ limits->maxStorageBufferRange = 134217728;
+ limits->maxPushConstantsSize = 128;
+ limits->maxMemoryAllocationCount = 4096;
+ limits->maxSamplerAllocationCount = 4000;
+ limits->bufferImageGranularity = 1;
+ limits->sparseAddressSpaceSize = 2147483648;
+ limits->maxBoundDescriptorSets = 4;
+ limits->maxPerStageDescriptorSamplers = 16;
+ limits->maxPerStageDescriptorUniformBuffers = 12;
+ limits->maxPerStageDescriptorStorageBuffers = 4;
+ limits->maxPerStageDescriptorSampledImages = 16;
+ limits->maxPerStageDescriptorStorageImages = 4;
+ limits->maxPerStageDescriptorInputAttachments = 4;
+ limits->maxPerStageResources = 128;
+ limits->maxDescriptorSetSamplers = 96;
+ limits->maxDescriptorSetUniformBuffers = 72;
+ limits->maxDescriptorSetUniformBuffersDynamic = 8;
+ limits->maxDescriptorSetStorageBuffers = 24;
+ limits->maxDescriptorSetStorageBuffersDynamic = 4;
+ limits->maxDescriptorSetSampledImages = 96;
+ limits->maxDescriptorSetStorageImages = 24;
+ limits->maxDescriptorSetInputAttachments = 4;
+ limits->maxVertexInputAttributes = 16;
+ limits->maxVertexInputBindings = 16;
+ limits->maxVertexInputAttributeOffset = 2047;
+ limits->maxVertexInputBindingStride = 2048;
+ limits->maxVertexOutputComponents = 64;
+ limits->maxTessellationGenerationLevel = 64;
+ limits->maxTessellationPatchSize = 32;
+ limits->maxTessellationControlPerVertexInputComponents = 64;
+ limits->maxTessellationControlPerVertexOutputComponents = 64;
+ limits->maxTessellationControlPerPatchOutputComponents = 120;
+ limits->maxTessellationControlTotalOutputComponents = 2048;
+ limits->maxTessellationEvaluationInputComponents = 64;
+ limits->maxTessellationEvaluationOutputComponents = 64;
+ limits->maxGeometryShaderInvocations = 32;
+ limits->maxGeometryInputComponents = 64;
+ limits->maxGeometryOutputComponents = 64;
+ limits->maxGeometryOutputVertices = 256;
+ limits->maxGeometryTotalOutputComponents = 1024;
+ limits->maxFragmentInputComponents = 64;
+ limits->maxFragmentOutputAttachments = 4;
+ limits->maxFragmentDualSrcAttachments = 1;
+ limits->maxFragmentCombinedOutputResources = 4;
+ limits->maxComputeSharedMemorySize = 16384;
+ limits->maxComputeWorkGroupCount[0] = 65535;
+ limits->maxComputeWorkGroupCount[1] = 65535;
+ limits->maxComputeWorkGroupCount[2] = 65535;
+ limits->maxComputeWorkGroupInvocations = 128;
+ limits->maxComputeWorkGroupSize[0] = 128;
+ limits->maxComputeWorkGroupSize[1] = 128;
+ limits->maxComputeWorkGroupSize[2] = 64;
+ limits->subPixelPrecisionBits = 4;
+ limits->subTexelPrecisionBits = 4;
+ limits->mipmapPrecisionBits = 4;
+ limits->maxDrawIndexedIndexValue = UINT32_MAX;
+ limits->maxDrawIndirectCount = UINT16_MAX;
+ limits->maxSamplerLodBias = 2.0f;
+ limits->maxSamplerAnisotropy = 16;
+ limits->maxViewports = 16;
+ limits->maxViewportDimensions[0] = 4096;
+ limits->maxViewportDimensions[1] = 4096;
+ limits->viewportBoundsRange[0] = -8192;
+ limits->viewportBoundsRange[1] = 8191;
+ limits->viewportSubPixelBits = 0;
+ limits->minMemoryMapAlignment = 64;
+ limits->minTexelBufferOffsetAlignment = 16;
+ limits->minUniformBufferOffsetAlignment = 16;
+ limits->minStorageBufferOffsetAlignment = 16;
+ limits->minTexelOffset = -8;
+ limits->maxTexelOffset = 7;
+ limits->minTexelGatherOffset = -8;
+ limits->maxTexelGatherOffset = 7;
+ limits->minInterpolationOffset = 0.0f;
+ limits->maxInterpolationOffset = 0.5f;
+ limits->subPixelInterpolationOffsetBits = 4;
+ limits->maxFramebufferWidth = 4096;
+ limits->maxFramebufferHeight = 4096;
+ limits->maxFramebufferLayers = 256;
+ limits->framebufferColorSampleCounts = 0x7F;
+ limits->framebufferDepthSampleCounts = 0x7F;
+ limits->framebufferStencilSampleCounts = 0x7F;
+ limits->framebufferNoAttachmentsSampleCounts = 0x7F;
+ limits->maxColorAttachments = 4;
+ limits->sampledImageColorSampleCounts = 0x7F;
+ limits->sampledImageIntegerSampleCounts = 0x7F;
+ limits->sampledImageDepthSampleCounts = 0x7F;
+ limits->sampledImageStencilSampleCounts = 0x7F;
+ limits->storageImageSampleCounts = 0x7F;
+ limits->maxSampleMaskWords = 1;
+ limits->timestampComputeAndGraphics = VK_TRUE;
+ limits->timestampPeriod = 1;
+ limits->maxClipDistances = 8;
+ limits->maxCullDistances = 8;
+ limits->maxCombinedClipAndCullDistances = 8;
+ limits->discreteQueuePriorities = 2;
+ limits->pointSizeRange[0] = 1.0f;
+ limits->pointSizeRange[1] = 64.0f;
+ limits->lineWidthRange[0] = 1.0f;
+ limits->lineWidthRange[1] = 8.0f;
+ limits->pointSizeGranularity = 1.0f;
+ limits->lineWidthGranularity = 1.0f;
+ limits->strictLines = VK_TRUE;
+ limits->standardSampleLocations = VK_TRUE;
+ limits->optimalBufferCopyOffsetAlignment = 1;
+ limits->optimalBufferCopyRowPitchAlignment = 1;
+ limits->nonCoherentAtomSize = 256;
+
+ return *limits;
+}
+
+void SetBoolArrayTrue(VkBool32* bool_array, uint32_t num_bools) {
+ for (uint32_t i = 0; i < num_bools; ++i) {
+ bool_array[i] = VK_TRUE;
+ }
+}
+
+VkDeviceSize GetImageSizeFromCreateInfo(const VkImageCreateInfo* pCreateInfo) {
+ VkDeviceSize size = pCreateInfo->extent.width;
+ size *= pCreateInfo->extent.height;
+ size *= pCreateInfo->extent.depth;
+ // TODO: A pixel size is 32 bytes. This accounts for the largest possible pixel size of any format. It could be changed to more
+ // accurate size if need be.
+ size *= 32;
+ size *= pCreateInfo->arrayLayers;
+ size *= (pCreateInfo->mipLevels > 1 ? 2 : 1);
+
+ switch (pCreateInfo->format) {
+ case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
+ case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
+ case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
+ case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16:
+ case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16:
+ case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16:
+ case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16:
+ case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16:
+ case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16:
+ case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
+ case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
+ case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
+ size *= 3;
+ break;
+ case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
+ case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
+ case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
+ case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16:
+ case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16:
+ case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16:
+ case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
+ case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
+ size *= 2;
+ break;
+ default:
+ break;
+ }
+
+ return size;
+}
+
+} // namespace vkmock
# output paths and the list of files in the path
files_to_gen = {str(os.path.join('icd','generated')) : ['vk_typemap_helper.h',
- 'mock_icd.h',
- 'mock_icd.cpp'],
+ 'function_definitions.h',
+ 'function_declarations.h'],
str(os.path.join('vulkaninfo','generated')): ['vulkaninfo.hpp']}
#base directory for the source repository
]
# Options for mock ICD header
- genOpts['mock_icd.h'] = [
+ genOpts['function_declarations.h'] = [
MockICDOutputGenerator,
MockICDGeneratorOptions(
conventions=conventions,
- filename='mock_icd.h',
+ filename='function_declarations.h',
directory=directory,
genpath=None,
apiname=apiname,
apientryp='VKAPI_PTR *',
alignFuncParam=48,
expandEnumerants=False,
- helper_file_type='mock_icd_header')
+ helper_file_type='mock_icd_function_declaration_implementation')
]
# Options for mock ICD cpp
- genOpts['mock_icd.cpp'] = [
+ genOpts['function_definitions.h'] = [
MockICDOutputGenerator,
MockICDGeneratorOptions(
conventions=conventions,
- filename='mock_icd.cpp',
+ filename='function_definitions.h',
directory=directory,
genpath=None,
apiname=apiname,
apientryp='VKAPI_PTR *',
alignFuncParam=48,
expandEnumerants=False,
- helper_file_type='mock_icd_source')
+ helper_file_type='mock_icd_function_definition_implementation')
]
# Options for vulkaninfo.hpp
startTimer(args.time)
reg.apiGen()
endTimer(args.time, '* Time to generate ' + options.filename + ' =')
- genTarget(args)
\ No newline at end of file
+ genTarget(args)
from generator import *
from common_codegen import *
-
-# Mock header code
-HEADER_C_CODE = '''
-using mutex_t = std::mutex;
-using lock_guard_t = std::lock_guard<mutex_t>;
-using unique_lock_t = std::unique_lock<mutex_t>;
-
-static mutex_t global_lock;
-static uint64_t global_unique_handle = 1;
-static const uint32_t SUPPORTED_LOADER_ICD_INTERFACE_VERSION = 5;
-static uint32_t loader_interface_version = 0;
-static bool negotiate_loader_icd_interface_called = false;
-static void* CreateDispObjHandle() {
- auto handle = new VK_LOADER_DATA;
- set_loader_magic_value(handle);
- return handle;
-}
-static void DestroyDispObjHandle(void* handle) {
- delete reinterpret_cast<VK_LOADER_DATA*>(handle);
-}
-'''
-
-# Manual code at the top of the cpp source file
-SOURCE_CPP_PREFIX = '''
-using std::unordered_map;
-
-static constexpr uint32_t icd_physical_device_count = 1;
-static unordered_map<VkInstance, std::array<VkPhysicalDevice, icd_physical_device_count>> physical_device_map;
-
-// Map device memory handle to any mapped allocations that we'll need to free on unmap
-static unordered_map<VkDeviceMemory, std::vector<void*>> mapped_memory_map;
-
-// Map device memory allocation handle to the size
-static unordered_map<VkDeviceMemory, VkDeviceSize> allocated_memory_size_map;
-
-static unordered_map<VkDevice, unordered_map<uint32_t, unordered_map<uint32_t, VkQueue>>> queue_map;
-static VkDeviceAddress current_available_address = 0x10000000;
-struct BufferState {
- VkDeviceSize size;
- VkDeviceAddress address;
-};
-static unordered_map<VkDevice, unordered_map<VkBuffer, BufferState>> buffer_map;
-static unordered_map<VkDevice, unordered_map<VkImage, VkDeviceSize>> image_memory_size_map;
-static unordered_map<VkCommandPool, std::vector<VkCommandBuffer>> command_pool_buffer_map;
-
-static constexpr uint32_t icd_swapchain_image_count = 1;
-static unordered_map<VkSwapchainKHR, VkImage[icd_swapchain_image_count]> swapchain_image_map;
-
-// TODO: Would like to codegen this but limits aren't in XML
-static VkPhysicalDeviceLimits SetLimits(VkPhysicalDeviceLimits *limits) {
- limits->maxImageDimension1D = 4096;
- limits->maxImageDimension2D = 4096;
- limits->maxImageDimension3D = 256;
- limits->maxImageDimensionCube = 4096;
- limits->maxImageArrayLayers = 256;
- limits->maxTexelBufferElements = 65536;
- limits->maxUniformBufferRange = 16384;
- limits->maxStorageBufferRange = 134217728;
- limits->maxPushConstantsSize = 128;
- limits->maxMemoryAllocationCount = 4096;
- limits->maxSamplerAllocationCount = 4000;
- limits->bufferImageGranularity = 1;
- limits->sparseAddressSpaceSize = 2147483648;
- limits->maxBoundDescriptorSets = 4;
- limits->maxPerStageDescriptorSamplers = 16;
- limits->maxPerStageDescriptorUniformBuffers = 12;
- limits->maxPerStageDescriptorStorageBuffers = 4;
- limits->maxPerStageDescriptorSampledImages = 16;
- limits->maxPerStageDescriptorStorageImages = 4;
- limits->maxPerStageDescriptorInputAttachments = 4;
- limits->maxPerStageResources = 128;
- limits->maxDescriptorSetSamplers = 96;
- limits->maxDescriptorSetUniformBuffers = 72;
- limits->maxDescriptorSetUniformBuffersDynamic = 8;
- limits->maxDescriptorSetStorageBuffers = 24;
- limits->maxDescriptorSetStorageBuffersDynamic = 4;
- limits->maxDescriptorSetSampledImages = 96;
- limits->maxDescriptorSetStorageImages = 24;
- limits->maxDescriptorSetInputAttachments = 4;
- limits->maxVertexInputAttributes = 16;
- limits->maxVertexInputBindings = 16;
- limits->maxVertexInputAttributeOffset = 2047;
- limits->maxVertexInputBindingStride = 2048;
- limits->maxVertexOutputComponents = 64;
- limits->maxTessellationGenerationLevel = 64;
- limits->maxTessellationPatchSize = 32;
- limits->maxTessellationControlPerVertexInputComponents = 64;
- limits->maxTessellationControlPerVertexOutputComponents = 64;
- limits->maxTessellationControlPerPatchOutputComponents = 120;
- limits->maxTessellationControlTotalOutputComponents = 2048;
- limits->maxTessellationEvaluationInputComponents = 64;
- limits->maxTessellationEvaluationOutputComponents = 64;
- limits->maxGeometryShaderInvocations = 32;
- limits->maxGeometryInputComponents = 64;
- limits->maxGeometryOutputComponents = 64;
- limits->maxGeometryOutputVertices = 256;
- limits->maxGeometryTotalOutputComponents = 1024;
- limits->maxFragmentInputComponents = 64;
- limits->maxFragmentOutputAttachments = 4;
- limits->maxFragmentDualSrcAttachments = 1;
- limits->maxFragmentCombinedOutputResources = 4;
- limits->maxComputeSharedMemorySize = 16384;
- limits->maxComputeWorkGroupCount[0] = 65535;
- limits->maxComputeWorkGroupCount[1] = 65535;
- limits->maxComputeWorkGroupCount[2] = 65535;
- limits->maxComputeWorkGroupInvocations = 128;
- limits->maxComputeWorkGroupSize[0] = 128;
- limits->maxComputeWorkGroupSize[1] = 128;
- limits->maxComputeWorkGroupSize[2] = 64;
- limits->subPixelPrecisionBits = 4;
- limits->subTexelPrecisionBits = 4;
- limits->mipmapPrecisionBits = 4;
- limits->maxDrawIndexedIndexValue = UINT32_MAX;
- limits->maxDrawIndirectCount = UINT16_MAX;
- limits->maxSamplerLodBias = 2.0f;
- limits->maxSamplerAnisotropy = 16;
- limits->maxViewports = 16;
- limits->maxViewportDimensions[0] = 4096;
- limits->maxViewportDimensions[1] = 4096;
- limits->viewportBoundsRange[0] = -8192;
- limits->viewportBoundsRange[1] = 8191;
- limits->viewportSubPixelBits = 0;
- limits->minMemoryMapAlignment = 64;
- limits->minTexelBufferOffsetAlignment = 16;
- limits->minUniformBufferOffsetAlignment = 16;
- limits->minStorageBufferOffsetAlignment = 16;
- limits->minTexelOffset = -8;
- limits->maxTexelOffset = 7;
- limits->minTexelGatherOffset = -8;
- limits->maxTexelGatherOffset = 7;
- limits->minInterpolationOffset = 0.0f;
- limits->maxInterpolationOffset = 0.5f;
- limits->subPixelInterpolationOffsetBits = 4;
- limits->maxFramebufferWidth = 4096;
- limits->maxFramebufferHeight = 4096;
- limits->maxFramebufferLayers = 256;
- limits->framebufferColorSampleCounts = 0x7F;
- limits->framebufferDepthSampleCounts = 0x7F;
- limits->framebufferStencilSampleCounts = 0x7F;
- limits->framebufferNoAttachmentsSampleCounts = 0x7F;
- limits->maxColorAttachments = 4;
- limits->sampledImageColorSampleCounts = 0x7F;
- limits->sampledImageIntegerSampleCounts = 0x7F;
- limits->sampledImageDepthSampleCounts = 0x7F;
- limits->sampledImageStencilSampleCounts = 0x7F;
- limits->storageImageSampleCounts = 0x7F;
- limits->maxSampleMaskWords = 1;
- limits->timestampComputeAndGraphics = VK_TRUE;
- limits->timestampPeriod = 1;
- limits->maxClipDistances = 8;
- limits->maxCullDistances = 8;
- limits->maxCombinedClipAndCullDistances = 8;
- limits->discreteQueuePriorities = 2;
- limits->pointSizeRange[0] = 1.0f;
- limits->pointSizeRange[1] = 64.0f;
- limits->lineWidthRange[0] = 1.0f;
- limits->lineWidthRange[1] = 8.0f;
- limits->pointSizeGranularity = 1.0f;
- limits->lineWidthGranularity = 1.0f;
- limits->strictLines = VK_TRUE;
- limits->standardSampleLocations = VK_TRUE;
- limits->optimalBufferCopyOffsetAlignment = 1;
- limits->optimalBufferCopyRowPitchAlignment = 1;
- limits->nonCoherentAtomSize = 256;
-
- return *limits;
-}
-
-void SetBoolArrayTrue(VkBool32* bool_array, uint32_t num_bools)
-{
- for (uint32_t i = 0; i < num_bools; ++i) {
- bool_array[i] = VK_TRUE;
- }
-}
-
-VkDeviceSize GetImageSizeFromCreateInfo(const VkImageCreateInfo* pCreateInfo)
-{
- VkDeviceSize size = pCreateInfo->extent.width;
- size *= pCreateInfo->extent.height;
- size *= pCreateInfo->extent.depth;
- // TODO: A pixel size is 32 bytes. This accounts for the largest possible pixel size of any format. It could be changed to more accurate size if need be.
- size *= 32;
- size *= pCreateInfo->arrayLayers;
- size *= (pCreateInfo->mipLevels > 1 ? 2 : 1);
-
- switch (pCreateInfo->format) {
- case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
- case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
- case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
- case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16:
- case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16:
- case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16:
- case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
- case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
- case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
- size *= 3;
- break;
- case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
- case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM:
- case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
- case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16:
- case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16:
- case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM:
- case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM:
- size *= 2;
- break;
- default:
- break;
- }
-
- return size;
-}
-'''
-
-# Manual code at the end of the cpp source file
-SOURCE_CPP_POSTFIX = '''
-
-static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
- // TODO: This function should only care about physical device functions and return nullptr for other functions
- const auto &item = name_to_funcptr_map.find(funcName);
- if (item != name_to_funcptr_map.end()) {
- return reinterpret_cast<PFN_vkVoidFunction>(item->second);
- }
- // Mock should intercept all functions so if we get here just return null
- return nullptr;
-}
-
-} // namespace vkmock
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define EXPORT __attribute__((visibility("default")))
-#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
-#define EXPORT __attribute__((visibility("default")))
-#else
-#define EXPORT
-#endif
-
-extern "C" {
-
-EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName) {
- if (!vkmock::negotiate_loader_icd_interface_called) {
- vkmock::loader_interface_version = 1;
- }
- return vkmock::GetInstanceProcAddr(instance, pName);
-}
-
-EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance, const char* pName) {
- return vkmock::GetPhysicalDeviceProcAddr(instance, pName);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) {
- vkmock::negotiate_loader_icd_interface_called = true;
- vkmock::loader_interface_version = *pSupportedVersion;
- if (*pSupportedVersion > vkmock::SUPPORTED_LOADER_ICD_INTERFACE_VERSION) {
- *pSupportedVersion = vkmock::SUPPORTED_LOADER_ICD_INTERFACE_VERSION;
- }
- return VK_SUCCESS;
-}
-
-
-EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(
- VkInstance instance,
- VkSurfaceKHR surface,
- const VkAllocationCallbacks* pAllocator)
-{
- vkmock::DestroySurfaceKHR(instance, surface, pAllocator);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
- VkPhysicalDevice physicalDevice,
- uint32_t queueFamilyIndex,
- VkSurfaceKHR surface,
- VkBool32* pSupported)
-{
- return vkmock::GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, pSupported);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
-{
- return vkmock::GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, pSurfaceCapabilities);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- uint32_t* pSurfaceFormatCount,
- VkSurfaceFormatKHR* pSurfaceFormats)
-{
- return vkmock::GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- uint32_t* pPresentModeCount,
- VkPresentModeKHR* pPresentModes)
-{
- return vkmock::GetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, pPresentModes);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(
- VkInstance instance,
- const VkDisplaySurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-
-#ifdef VK_USE_PLATFORM_XLIB_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
- VkInstance instance,
- const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_XLIB_KHR */
-
-#ifdef VK_USE_PLATFORM_XCB_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
- VkInstance instance,
- const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_XCB_KHR */
-
-#ifdef VK_USE_PLATFORM_WAYLAND_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
- VkInstance instance,
- const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_WAYLAND_KHR */
-
-#ifdef VK_USE_PLATFORM_ANDROID_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
- VkInstance instance,
- const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_ANDROID_KHR */
-
-#ifdef VK_USE_PLATFORM_WIN32_KHR
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
- VkInstance instance,
- const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_WIN32_KHR */
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHR(
- VkDevice device,
- VkSurfaceKHR surface,
- VkDeviceGroupPresentModeFlagsKHR* pModes)
-{
- return vkmock::GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
-}
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHR(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- uint32_t* pRectCount,
- VkRect2D* pRects)
-{
- return vkmock::GetPhysicalDevicePresentRectanglesKHR(physicalDevice, surface, pRectCount, pRects);
-}
-
-#ifdef VK_USE_PLATFORM_VI_NN
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN(
- VkInstance instance,
- const VkViSurfaceCreateInfoNN* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateViSurfaceNN(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_VI_NN */
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2EXT(
- VkPhysicalDevice physicalDevice,
- VkSurfaceKHR surface,
- VkSurfaceCapabilities2EXT* pSurfaceCapabilities)
-{
- return vkmock::GetPhysicalDeviceSurfaceCapabilities2EXT(physicalDevice, surface, pSurfaceCapabilities);
-}
-
-#ifdef VK_USE_PLATFORM_IOS_MVK
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(
- VkInstance instance,
- const VkIOSSurfaceCreateInfoMVK* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateIOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_IOS_MVK */
-
-#ifdef VK_USE_PLATFORM_MACOS_MVK
-
-EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(
- VkInstance instance,
- const VkMacOSSurfaceCreateInfoMVK* pCreateInfo,
- const VkAllocationCallbacks* pAllocator,
- VkSurfaceKHR* pSurface)
-{
- return vkmock::CreateMacOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface);
-}
-#endif /* VK_USE_PLATFORM_MACOS_MVK */
-
-} // end extern "C"
-
-'''
-
CUSTOM_C_INTERCEPTS = {
'vkCreateInstance': '''
// TODO: If loader ver <=4 ICD must fail with VK_ERROR_INCOMPATIBLE_DRIVER for all vkCreateInstance calls with
# Internal state - accumulators for different inner block text
self.sections = dict([(section, []) for section in self.ALL_SECTIONS])
self.intercepts = []
+ self.function_declarations = False
# Check if the parameter passed in is a pointer to an array
def paramIsArray(self, param):
# C-specific
#
# Multiple inclusion protection & C++ namespace.
- self.header = False
- if (genOpts.protectFile and self.genOpts.filename and 'h' == self.genOpts.filename[-1]):
- self.header = True
- write('#pragma once', file=self.outFile)
- self.newline()
- #
+ if (genOpts.protectFile and self.genOpts.filename == "function_declarations.h"):
+ self.function_declarations = True
+
# User-supplied prefix text, if any (list of strings)
if (genOpts.prefixText):
for s in genOpts.prefixText:
write(s, file=self.outFile)
- if self.header:
- write('#include <unordered_map>', file=self.outFile)
- write('#include <mutex>', file=self.outFile)
- write('#include <string>', file=self.outFile)
- write('#include <cstring>', file=self.outFile)
- write('#include "vulkan/vk_icd.h"', file=self.outFile)
- else:
- write('#include "mock_icd.h"', file=self.outFile)
- write('#include <stdlib.h>', file=self.outFile)
- write('#include <algorithm>', file=self.outFile)
- write('#include <array>', file=self.outFile)
- write('#include <vector>', file=self.outFile)
- write('#include "vk_typemap_helper.h"', file=self.outFile)
- write('namespace vkmock {', file=self.outFile)
- if self.header:
+ if self.function_declarations:
self.newline()
- write(HEADER_C_CODE, file=self.outFile)
# Include all of the extensions in ICD except specific ignored ones
device_exts = []
instance_exts = []
else:
device_exts.append(' {"%s", %s},' % (ext.attrib['name'], ext_version))
break
-
+ write('#pragma once\n',file=self.outFile)
+ write('#include <stdint.h>',file=self.outFile)
+ write('#include <string>',file=self.outFile)
+ write('#include <unordered_map>',file=self.outFile)
+ write('#include <vulkan/vulkan.h>',file=self.outFile)
+ self.newline()
+ write('namespace vkmock {\n', file=self.outFile)
write('// Map of instance extension name to version', file=self.outFile)
write('static const std::unordered_map<std::string, uint32_t> instance_extension_map = {', file=self.outFile)
write('\n'.join(instance_exts), file=self.outFile)
write('static const std::unordered_map<std::string, uint32_t> device_extension_map = {', file=self.outFile)
write('\n'.join(device_exts), file=self.outFile)
write('};', file=self.outFile)
-
else:
- self.newline()
- write(SOURCE_CPP_PREFIX, file=self.outFile)
+ write('#pragma once\n',file=self.outFile)
+ write('#include "mock_icd.h"',file=self.outFile)
+ write('#include "function_declarations.h"\n',file=self.outFile)
+ write('namespace vkmock {', file=self.outFile)
+
def endFile(self):
# C-specific
# Finish C++ namespace
self.newline()
- if self.header:
+ if self.function_declarations:
# record intercepted procedures
write('// Map of all APIs to be intercepted by this layer', file=self.outFile)
write('static const std::unordered_map<std::string, void*> name_to_funcptr_map = {', file=self.outFile)
write('\n'.join(self.intercepts), file=self.outFile)
write('};\n', file=self.outFile)
- self.newline()
- write('} // namespace vkmock', file=self.outFile)
- self.newline()
- else: # Loader-layer-interface, need to implement global interface functions
- write(SOURCE_CPP_POSTFIX, file=self.outFile)
+ write('} // namespace vkmock', file=self.outFile)
+ self.newline()
+
# Finish processing in superclass
OutputGenerator.endFile(self)
def beginFeature(self, interface, emit):
# Command generation
def genCmd(self, cmdinfo, name, alias):
decls = self.makeCDecls(cmdinfo.elem)
- if self.header: # In the header declare all intercepts
+ if self.function_declarations: # In the header declare all intercepts
self.appendSection('command', '')
self.appendSection('command', 'static %s' % (decls[0]))
if (self.featureExtraProtect != None):