"""
Base constants and utilities for Vulkan backend.
"""

import numpy as np
from pathlib import Path

_VULKAN_FALLBACKS = {
    "VK_STRUCTURE_TYPE_APPLICATION_INFO": None,
    "VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO": None,
    "VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET": None,
    "VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_INFO": None,
    "VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO": None,
    "VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO": None,
    "VK_STRUCTURE_TYPE_SUBMIT_INFO": None,
    "VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO": None,
    "VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO": None,
    "VK_STRUCTURE_TYPE_PUSH_CONSTANT_RANGE": None,
    "VK_API_VERSION_1_0": 0,
    "VK_QUEUE_COMPUTE_BIT": 0,
    "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT": 0,
    "VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT": 0,
    "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER": 0,
    "VK_SHADER_STAGE_COMPUTE_BIT": 0,
    "VK_SHARING_MODE_EXCLUSIVE": 0,
    "VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT": 0,
    "VK_MEMORY_PROPERTY_HOST_COHERENT_BIT": 0,
    "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT": 0,
    "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT": 0,
    "VK_COMMAND_BUFFER_LEVEL_PRIMARY": 0,
    "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT": 0,
    "VK_PIPELINE_BIND_POINT_COMPUTE": 0,
}

try:
    from vulkan import *
    VULKAN_AVAILABLE = True
    # After 'from vulkan import *', all Vulkan constants are in the namespace
    # and can be imported by other modules using 'from base import VK_...'
except ImportError:
    VULKAN_AVAILABLE = False
    pass

# Create dummy constants for type checking when Vulkan is not available
# or when a mocked `vulkan` module does not define them (e.g. RTD autodoc).
if "VK_MAKE_VERSION" not in globals():
    VK_MAKE_VERSION = lambda a, b, c: 0
for _name, _default in _VULKAN_FALLBACKS.items():
    if _name not in globals():
        globals()[_name] = _default

__all__ = ['VULKAN_AVAILABLE']
