diff --git a/Resources/Shaders/infinite_grid.frag b/Resources/Shaders/infinite_grid.frag index 307ed184..14fceda8 100644 --- a/Resources/Shaders/infinite_grid.frag +++ b/Resources/Shaders/infinite_grid.frag @@ -17,7 +17,7 @@ void main() { vec2 dudv = vec2(length(vec2(dFdx(uv.x), dFdy(uv.x))), length(vec2(dFdx(uv.y), dFdy(uv.y)))); - float lodLevel = max(0.0, log10((length(dudv) * gridMinPixelsBetweenCells) / gridCellSize) + 1.0); + float lodLevel = max(0.0, log_10((length(dudv) * gridMinPixelsBetweenCells) / gridCellSize) + 1.0); float lodFade = fract(lodLevel); float lod0 = gridCellSize * pow(10.0, floor(lodLevel + 0)); diff --git a/Resources/Shaders/utility.glsl b/Resources/Shaders/utility.glsl index 3e1ac3ca..9a1c9dcc 100644 --- a/Resources/Shaders/utility.glsl +++ b/Resources/Shaders/utility.glsl @@ -1,4 +1,5 @@ -float log10(float x) + +float log_10(float x) { return log(x) / log(10.0); } diff --git a/ZEngine/ZEngine/Hardwares/VulkanDevice.cpp b/ZEngine/ZEngine/Hardwares/VulkanDevice.cpp index 24fd083e..51273024 100644 --- a/ZEngine/ZEngine/Hardwares/VulkanDevice.cpp +++ b/ZEngine/ZEngine/Hardwares/VulkanDevice.cpp @@ -57,7 +57,10 @@ namespace ZEngine::Hardwares VkInstanceCreateInfo instance_create_info = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = VK_NULL_HANDLE, .flags = 0, .pApplicationInfo = &app_info}; - auto scratch = ZGetScratch(Arena); +#ifdef __APPLE__ + instance_create_info.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; +#endif + auto scratch = ZGetScratch(Arena); Array enabled_layer_name_collection; Array selected_layer_property_collection; @@ -71,7 +74,9 @@ namespace ZEngine::Hardwares validation_layer_name_collection.push("VK_LAYER_LUNARG_api_dump"); validation_layer_name_collection.push("VK_LAYER_KHRONOS_validation"); validation_layer_name_collection.push("VK_LAYER_LUNARG_monitor"); +#ifndef __APPLE__ validation_layer_name_collection.push("VK_LAYER_LUNARG_screenshot"); +#endif for (const char* layer_name : validation_layer_name_collection) { @@ -126,6 +131,9 @@ namespace ZEngine::Hardwares } } +#ifdef __APPLE__ + enabled_extension_layer_name_collection.push(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); +#endif instance_create_info.enabledLayerCount = enabled_layer_name_collection.size(); instance_create_info.ppEnabledLayerNames = enabled_layer_name_collection.data(); instance_create_info.enabledExtensionCount = enabled_extension_layer_name_collection.size(); @@ -175,16 +183,26 @@ namespace ZEngine::Hardwares for (VkPhysicalDevice physical_device : physical_device_collection) { - VkPhysicalDeviceProperties physical_device_properties; - VkPhysicalDeviceFeatures physical_device_feature; + VkPhysicalDeviceDescriptorIndexingProperties indexing_properties = {}; + indexing_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES; + + VkPhysicalDeviceProperties physical_device_properties; + VkPhysicalDeviceProperties2 physical_device_properties2 = {}; + physical_device_properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; + physical_device_properties2.pNext = &indexing_properties; + + VkPhysicalDeviceFeatures physical_device_feature; + vkGetPhysicalDeviceProperties(physical_device, &physical_device_properties); + vkGetPhysicalDeviceProperties2(physical_device, &physical_device_properties2); vkGetPhysicalDeviceFeatures(physical_device, &physical_device_feature); - if ((physical_device_feature.geometryShader == VK_TRUE) && (physical_device_feature.samplerAnisotropy == VK_TRUE) && ((physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) || (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU))) + if (/*(physical_device_feature.geometryShader == VK_TRUE) && (physical_device_feature.samplerAnisotropy == VK_TRUE) && */ ((physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) || (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU))) { - PhysicalDevice = physical_device; - PhysicalDeviceProperties = physical_device_properties; - PhysicalDeviceFeature = physical_device_feature; + PhysicalDevice = physical_device; + PhysicalDeviceProperties = physical_device_properties; + PhysicalDeviceDescriptorIndexingProperties = indexing_properties; + PhysicalDeviceFeature = physical_device_feature; vkGetPhysicalDeviceMemoryProperties(PhysicalDevice, &PhysicalDeviceMemoryProperties); break; } @@ -197,6 +215,9 @@ namespace ZEngine::Hardwares requested_device_extension_layer_name_collection.push(VK_KHR_SWAPCHAIN_EXTENSION_NAME); requested_device_extension_layer_name_collection.push(VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME); +#ifdef __APPLE__ + requested_device_extension_layer_name_collection.push("VK_KHR_portability_subset"); +#endif for (LayerProperty& layer : selected_layer_property_collection) { diff --git a/ZEngine/ZEngine/Hardwares/VulkanDevice.h b/ZEngine/ZEngine/Hardwares/VulkanDevice.h index 3fb34ede..5b200fea 100644 --- a/ZEngine/ZEngine/Hardwares/VulkanDevice.h +++ b/ZEngine/ZEngine/Hardwares/VulkanDevice.h @@ -534,62 +534,63 @@ namespace ZEngine::Hardwares */ struct VulkanDevice { - bool HasSeperateTransfertQueueFamily = false; - const char* ApplicationName = "Tetragrama"; - const char* EngineName = "ZEngine"; - uint32_t SwapchainImageCount = 3; - uint32_t SwapchainImageIndex = std::numeric_limits::max(); - uint32_t CurrentFrameIndex = std::numeric_limits::max(); - uint32_t PreviousFrameIndex = std::numeric_limits::max(); - uint32_t SwapchainImageWidth = std::numeric_limits::max(); - uint32_t SwapchainImageHeight = std::numeric_limits::max(); - uint32_t GraphicFamilyIndex = std::numeric_limits::max(); - uint32_t TransferFamilyIndex = std::numeric_limits::max(); - uint32_t EnqueuedCommandbufferIndex = 0; - uint32_t WriteDescriptorSetIndex = 0; - VkInstance Instance = VK_NULL_HANDLE; - VkSurfaceKHR Surface = VK_NULL_HANDLE; - VkSurfaceFormatKHR SurfaceFormat = {}; - VkPresentModeKHR PresentMode = {}; - VkPhysicalDeviceProperties PhysicalDeviceProperties = {}; - VkDevice LogicalDevice = VK_NULL_HANDLE; - VkPhysicalDevice PhysicalDevice = VK_NULL_HANDLE; - VkPhysicalDeviceFeatures PhysicalDeviceFeature = {}; - VkPhysicalDeviceMemoryProperties PhysicalDeviceMemoryProperties = {}; - VkSwapchainKHR SwapchainHandle = VK_NULL_HANDLE; - VmaAllocator VmaAllocatorValue = nullptr; - Core::Containers::Array DefaultDepthFormats = {}; - Rendering::Renderers::RenderPasses::Attachment* SwapchainAttachment = {}; - Core::Containers::Array SwapchainImageViews = {}; - Core::Containers::Array SwapchainFramebuffers = {}; - Core::Containers::Array SwapchainAcquiredSemaphores = {}; - Core::Containers::Array SwapchainRenderCompleteSemaphores = {}; - Core::Containers::Array SwapchainSignalFences = {}; - Core::Containers::Array EnqueuedCommandbuffers = {}; - Core::Containers::HashMap> ShaderCaches = {}; - std::set WriteBindlessDescriptorSetRequests = {}; - Rendering::Textures::TextureHandleManager GlobalTextures = {}; - Helpers::HandleManager Image2DBufferManager = {}; - Helpers::ThreadSafeQueue TextureHandleToUpdates = {}; - Helpers::ThreadSafeQueue TextureHandleToDispose = {}; - Helpers::HandleManager ShaderManager = {}; - Helpers::HandleManager VertexBufferSetManager = {}; - Helpers::HandleManager StorageBufferSetManager = {}; - Helpers::HandleManager IndirectBufferSetManager = {}; - Helpers::HandleManager IndexBufferSetManager = {}; - Helpers::HandleManager UniformBufferSetManager = {}; - Helpers::HandleManager DirtyResources = {}; - Helpers::HandleManager DirtyBuffers = {}; - Helpers::HandleManager DirtyBufferImages = {}; - std::atomic_bool RunningDirtyCollector = true; - std::atomic_uint IdleFrameCount = 0; - std::atomic_uint IdleFrameThreshold = SwapchainImageCount * 3 * 3; - std::condition_variable DirtyCollectorCond = {}; - std::mutex DirtyMutex = {}; - std::mutex Mutex = {}; - Windows::CoreWindow* CurrentWindow = nullptr; - ZEngine::Core::Memory::ArenaAllocator* Arena = nullptr; - AsyncResourceLoaderPtr AsyncResLoader = nullptr; + bool HasSeperateTransfertQueueFamily = false; + const char* ApplicationName = "Tetragrama"; + const char* EngineName = "ZEngine"; + uint32_t SwapchainImageCount = 3; + uint32_t SwapchainImageIndex = std::numeric_limits::max(); + uint32_t CurrentFrameIndex = std::numeric_limits::max(); + uint32_t PreviousFrameIndex = std::numeric_limits::max(); + uint32_t SwapchainImageWidth = std::numeric_limits::max(); + uint32_t SwapchainImageHeight = std::numeric_limits::max(); + uint32_t GraphicFamilyIndex = std::numeric_limits::max(); + uint32_t TransferFamilyIndex = std::numeric_limits::max(); + uint32_t EnqueuedCommandbufferIndex = 0; + uint32_t WriteDescriptorSetIndex = 0; + VkInstance Instance = VK_NULL_HANDLE; + VkSurfaceKHR Surface = VK_NULL_HANDLE; + VkSurfaceFormatKHR SurfaceFormat = {}; + VkPresentModeKHR PresentMode = {}; + VkPhysicalDeviceProperties PhysicalDeviceProperties = {}; + VkPhysicalDeviceDescriptorIndexingProperties PhysicalDeviceDescriptorIndexingProperties = {}; + VkDevice LogicalDevice = VK_NULL_HANDLE; + VkPhysicalDevice PhysicalDevice = VK_NULL_HANDLE; + VkPhysicalDeviceFeatures PhysicalDeviceFeature = {}; + VkPhysicalDeviceMemoryProperties PhysicalDeviceMemoryProperties = {}; + VkSwapchainKHR SwapchainHandle = VK_NULL_HANDLE; + VmaAllocator VmaAllocatorValue = nullptr; + Core::Containers::Array DefaultDepthFormats = {}; + Rendering::Renderers::RenderPasses::Attachment* SwapchainAttachment = {}; + Core::Containers::Array SwapchainImageViews = {}; + Core::Containers::Array SwapchainFramebuffers = {}; + Core::Containers::Array SwapchainAcquiredSemaphores = {}; + Core::Containers::Array SwapchainRenderCompleteSemaphores = {}; + Core::Containers::Array SwapchainSignalFences = {}; + Core::Containers::Array EnqueuedCommandbuffers = {}; + Core::Containers::HashMap> ShaderCaches = {}; + std::set WriteBindlessDescriptorSetRequests = {}; + Rendering::Textures::TextureHandleManager GlobalTextures = {}; + Helpers::HandleManager Image2DBufferManager = {}; + Helpers::ThreadSafeQueue TextureHandleToUpdates = {}; + Helpers::ThreadSafeQueue TextureHandleToDispose = {}; + Helpers::HandleManager ShaderManager = {}; + Helpers::HandleManager VertexBufferSetManager = {}; + Helpers::HandleManager StorageBufferSetManager = {}; + Helpers::HandleManager IndirectBufferSetManager = {}; + Helpers::HandleManager IndexBufferSetManager = {}; + Helpers::HandleManager UniformBufferSetManager = {}; + Helpers::HandleManager DirtyResources = {}; + Helpers::HandleManager DirtyBuffers = {}; + Helpers::HandleManager DirtyBufferImages = {}; + std::atomic_bool RunningDirtyCollector = true; + std::atomic_uint IdleFrameCount = 0; + std::atomic_uint IdleFrameThreshold = SwapchainImageCount * 3 * 3; + std::condition_variable DirtyCollectorCond = {}; + std::mutex DirtyMutex = {}; + std::mutex Mutex = {}; + Windows::CoreWindow* CurrentWindow = nullptr; + ZEngine::Core::Memory::ArenaAllocator* Arena = nullptr; + AsyncResourceLoaderPtr AsyncResLoader = nullptr; void Initialize(ZEngine::Core::Memory::ArenaAllocator* arena, Windows::CoreWindow* const window); void Deinitialize(); diff --git a/ZEngine/ZEngine/Rendering/Shaders/Shader.cpp b/ZEngine/ZEngine/Rendering/Shaders/Shader.cpp index a33db946..c411aca2 100644 --- a/ZEngine/ZEngine/Rendering/Shaders/Shader.cpp +++ b/ZEngine/ZEngine/Rendering/Shaders/Shader.cpp @@ -216,7 +216,7 @@ namespace ZEngine::Rendering::Shaders count = type.array[0]; if (count == 0) // Unsized arrays { - count = m_device->PhysicalDeviceProperties.limits.maxDescriptorSetSampledImages - 1; + count = m_device->PhysicalDeviceDescriptorIndexingProperties.maxPerStageDescriptorUpdateAfterBindSamplers - 1; } }