From 7a45afd5a572228a5a23d212c8d7b7642eaf0f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sat, 26 Jan 2019 15:26:46 -0800 Subject: [PATCH] VK: WIP. --- src/renderer_vk.cpp | 264 +++++++++++++++++++++++++++++++++++--------- src/renderer_vk.h | 203 ++++++++++++++++++---------------- 2 files changed, 320 insertions(+), 147 deletions(-) diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 008d9dcd6..f9760f04e 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -224,6 +224,61 @@ VK_IMPORT_DEVICE }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) ); + struct Extension + { + enum Enum + { + EXT_debug_utils, + EXT_debug_report, + + Count + }; + + const char* m_name; + uint32_t m_minVersion; + bool m_supported; + bool m_initialize; + }; + + // Extension registry + // + static Extension s_extension[] = + { + { "VK_EXT_debug_utils", 1, false, BGFX_CONFIG_DEBUG_OBJECT_NAME }, + { "VK_EXT_debug_report", 1, false, BGFX_CONFIG_DEBUG }, + }; + BX_STATIC_ASSERT(Extension::Count == BX_COUNTOF(s_extension) ); + + void updateExtension(const char* _name, uint32_t _version) + { + bx::StringView ext(_name); + + bool supported = false; + for (uint32_t ii = 0; ii < Extension::Count; ++ii) + { + Extension& extension = s_extension[ii]; + if (!extension.m_supported + && extension.m_initialize) + { + if ( 0 == bx::strCmp(ext, extension.m_name) + && _version >= extension.m_minVersion) + { + extension.m_supported = true; + supported = true; + break; + } + } + } + + BX_TRACE("\tv%-3d %s%s" + , _version + , _name + , supported ? " (supported)" : "", _name + ); + + BX_UNUSED(supported); + } + static const VkFormat s_attribType[][4][2] = { { // Uint8 @@ -357,6 +412,12 @@ VK_IMPORT_DEVICE internalFreeNotification, }; + VkResult VKAPI_PTR stubSetDebugUtilsObjectNameEXT(VkDevice _device, const VkDebugUtilsObjectNameInfoEXT* _nameInfo) + { + BX_UNUSED(_device, _nameInfo); + return VK_SUCCESS; + } + static const char* s_debugReportObjectType[] = { "Unknown", @@ -455,21 +516,21 @@ VK_IMPORT_DEVICE && 0 < numExtensionProperties) { VkExtensionProperties extensionProperties[64]; - numExtensionProperties = bx::uint32_min(numExtensionProperties, BX_COUNTOF(extensionProperties) ); + numExtensionProperties = bx::min(numExtensionProperties, BX_COUNTOF(extensionProperties) ); result = enumerateExtensionProperties(_physicalDevice , NULL , &numExtensionProperties , extensionProperties ); - BX_TRACE("\tGlobal extensions (%d):" + BX_TRACE("Global extensions (%d):" , numExtensionProperties ); for (uint32_t extension = 0; extension < numExtensionProperties; ++extension) { - BX_TRACE("\t\t%s (s: 0x%08x)" - , extensionProperties[extension].extensionName + updateExtension( + extensionProperties[extension].extensionName , extensionProperties[extension].specVersion ); } @@ -484,10 +545,10 @@ VK_IMPORT_DEVICE && 0 < numLayerProperties) { VkLayerProperties layerProperties[64]; - numLayerProperties = bx::uint32_min(numLayerProperties, BX_COUNTOF(layerProperties) ); + numLayerProperties = bx::min(numLayerProperties, BX_COUNTOF(layerProperties) ); result = enumerateLayerProperties(_physicalDevice, &numLayerProperties, layerProperties); - char indent = VK_NULL_HANDLE == _physicalDevice ? ' ' : '\t'; + char indent = VK_NULL_HANDLE == _physicalDevice ? '\0' : '\t'; BX_UNUSED(indent); BX_TRACE("%cLayer extensions (%d):" @@ -514,7 +575,7 @@ VK_IMPORT_DEVICE && 0 < numExtensionProperties) { VkExtensionProperties extensionProperties[64]; - numExtensionProperties = bx::uint32_min(numExtensionProperties, BX_COUNTOF(extensionProperties) ); + numExtensionProperties = bx::min(numExtensionProperties, BX_COUNTOF(extensionProperties) ); result = enumerateExtensionProperties(_physicalDevice , layerProperties[layer].layerName , &numExtensionProperties @@ -570,6 +631,35 @@ VK_IMPORT_DEVICE return ""; } + template + VkObjectType getType(); + + template<> VkObjectType getType() { return VK_OBJECT_TYPE_BUFFER; } + template<> VkObjectType getType() { return VK_OBJECT_TYPE_SHADER_MODULE; } + + template + static BX_NO_INLINE void setDebugObjectName(VkDevice _device, Ty _object, const char* _format, ...) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_OBJECT_NAME) ) + { + char temp[2048]; + va_list argList; + va_start(argList, _format); + int32_t size = bx::min(sizeof(temp)-1, bx::vsnprintf(temp, sizeof(temp), _format, argList) ); + va_end(argList); + temp[size] = '\0'; + + VkDebugUtilsObjectNameInfoEXT ni; + ni.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; + ni.pNext = NULL; + ni.objectType = getType(); + ni.objectHandle = uint64_t(_object.vk); + ni.pObjectName = temp; + + VK_CHECK(vkSetDebugUtilsObjectNameEXT(_device, &ni) ); + } + } + void setImageMemoryBarrier(VkCommandBuffer _commandBuffer, VkImage _image, VkImageLayout _oldLayout, VkImageLayout _newLayout) { BX_CHECK(true @@ -811,16 +901,27 @@ VK_IMPORT /*not used*/ "" }; - const char* enabledExtension[] = + uint32_t numEnabledExtensions = 2; + + const char* enabledExtension[Extension::Count + numEnabledExtensions] = { VK_KHR_SURFACE_EXTENSION_NAME, KHR_SURFACE_EXTENSION_NAME, -#if BGFX_CONFIG_DEBUG - VK_EXT_DEBUG_REPORT_EXTENSION_NAME, -#endif // BGFX_CONFIG_DEBUG - /*not used*/ "" }; + for (uint32_t ii = 0; ii < Extension::Count; ++ii) + { + const Extension& extension = s_extension[ii]; + + if (extension.m_supported + && extension.m_initialize) + { + enabledExtension[numEnabledExtensions++] = extension.m_name; + BX_TRACE("%d: %s", numEnabledExtensions, extension.m_name); + } + } + + VkInstanceCreateInfo ici; ici.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; ici.pNext = NULL; @@ -828,7 +929,7 @@ VK_IMPORT ici.pApplicationInfo = &appInfo; ici.enabledLayerCount = BX_COUNTOF(enabledLayerNames) - 1; ici.ppEnabledLayerNames = enabledLayerNames; - ici.enabledExtensionCount = BX_COUNTOF(enabledExtension) - 1; + ici.enabledExtensionCount = numEnabledExtensions; ici.ppEnabledExtensionNames = enabledExtension; if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) @@ -868,7 +969,7 @@ VK_IMPORT_INSTANCE m_debugReportCallback = VK_NULL_HANDLE; - if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) + if (s_extension[Extension::EXT_debug_report].m_supported) { VkDebugReportCallbackCreateInfoEXT drcb; drcb.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; @@ -903,7 +1004,7 @@ VK_IMPORT_INSTANCE } VkPhysicalDevice physicalDevices[4]; - numPhysicalDevices = bx::uint32_min(numPhysicalDevices, BX_COUNTOF(physicalDevices) ); + numPhysicalDevices = bx::min(numPhysicalDevices, BX_COUNTOF(physicalDevices) ); result = vkEnumeratePhysicalDevices(m_instance , &numPhysicalDevices , physicalDevices @@ -978,7 +1079,7 @@ VK_IMPORT_INSTANCE g_caps.deviceId = uint16_t(m_deviceProperties.deviceID); g_caps.limits.maxTextureSize = m_deviceProperties.limits.maxImageDimension2D; - g_caps.limits.maxFBAttachments = uint8_t(bx::uint32_min(m_deviceProperties.limits.maxFragmentOutputAttachments, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); + g_caps.limits.maxFBAttachments = bx::min(m_deviceProperties.limits.maxFragmentOutputAttachments, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); g_caps.limits.maxComputeBindings = BGFX_MAX_COMPUTE_BINDINGS; { @@ -1060,7 +1161,7 @@ VK_IMPORT_INSTANCE ); VkQueueFamilyProperties queueFamilyPropertices[10] = {}; - queueFamilyPropertyCount = bx::uint32_min(queueFamilyPropertyCount, BX_COUNTOF(queueFamilyPropertices) ); + queueFamilyPropertyCount = bx::min(queueFamilyPropertyCount, BX_COUNTOF(queueFamilyPropertices) ); vkGetPhysicalDeviceQueueFamilyProperties(m_physicalDevice , &queueFamilyPropertyCount , queueFamilyPropertices @@ -1359,7 +1460,7 @@ VK_IMPORT_DEVICE } VkSurfaceFormatKHR surfaceFormats[10]; - numSurfaceFormats = bx::uint32_min(numSurfaceFormats, BX_COUNTOF(surfaceFormats) ); + numSurfaceFormats = bx::min(numSurfaceFormats, BX_COUNTOF(surfaceFormats) ); vkGetPhysicalDeviceSurfaceFormatsKHR(m_physicalDevice, m_surface, &numSurfaceFormats, surfaceFormats); // find the best match... @@ -1374,7 +1475,7 @@ VK_IMPORT_DEVICE } VkPresentModeKHR presentModes[10]; - numPresentModes = bx::uint32_min(numPresentModes, BX_COUNTOF(presentModes) ); + numPresentModes = bx::min(numPresentModes, BX_COUNTOF(presentModes) ); vkGetPhysicalDeviceSurfacePresentModesKHR(m_physicalDevice, m_surface, &numPresentModes, presentModes); // find the best match... @@ -1706,9 +1807,10 @@ VK_IMPORT_DEVICE VkDescriptorSetLayoutBinding dslb[] = { -// { DslBinding::CombinedImageSampler, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, VK_SHADER_STAGE_ALL, NULL }, - { DslBinding::UniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_ALL, NULL }, -// { DslBinding::StorageBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, VK_SHADER_STAGE_ALL, NULL }, +// { DslBinding::CombinedImageSampler, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, VK_SHADER_STAGE_ALL, NULL }, + { DslBinding::VertexUniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_ALL, NULL }, + { DslBinding::FragmentUniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, NULL }, +// { DslBinding::StorageBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, VK_SHADER_STAGE_ALL, NULL }, }; VkDescriptorPoolCreateInfo dpci; @@ -1781,6 +1883,11 @@ VK_IMPORT_DEVICE errorState = ErrorState::DescriptorCreated; + if (NULL == vkSetDebugUtilsObjectNameEXT) + { + vkSetDebugUtilsObjectNameEXT = stubSetDebugUtilsObjectNameEXT; + } + return true; error: @@ -2016,7 +2123,7 @@ VK_IMPORT_DEVICE void updateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override { BX_UNUSED(_handle, _offset, _size, _mem); -// m_indexBuffers[_handle.idx].update(m_commandBuffer, _offset, bx::uint32_min(_size, _mem->size), _mem->data); +// m_indexBuffers[_handle.idx].update(m_commandBuffer, _offset, bx::min(_size, _mem->size), _mem->data); } void destroyDynamicIndexBuffer(IndexBufferHandle _handle) override @@ -2033,7 +2140,7 @@ VK_IMPORT_DEVICE void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override { BX_UNUSED(_handle, _offset, _size, _mem); -// m_vertexBuffers[_handle.idx].update(m_commandBuffer, _offset, bx::uint32_min(_size, _mem->size), _mem->data); +// m_vertexBuffers[_handle.idx].update(m_commandBuffer, _offset, bx::min(_size, _mem->size), _mem->data); } void destroyDynamicVertexBuffer(VertexBufferHandle _handle) override @@ -2153,13 +2260,38 @@ VK_IMPORT_DEVICE BX_UNUSED(_handle); } - void setMarker(const char* /*_marker*/, uint16_t /*_len*/) override + void setMarker(const char* _marker, uint16_t _len) override { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + BX_UNUSED(_marker, _len); + } } virtual void setName(Handle _handle, const char* _name, uint16_t _len) override { - BX_UNUSED(_handle, _name, _len) + switch (_handle.type) + { + case Handle::IndexBuffer: + setDebugObjectName(m_device, m_indexBuffers[_handle.idx].m_buffer, "%.*s", _len, _name); + break; + + case Handle::Shader: + setDebugObjectName(m_device, m_shaders[_handle.idx].m_module, "%.*s", _len, _name); + break; + + case Handle::Texture: +// setDebugObjectName(m_device, m_textures[_handle.idx].m_ptr, "%.*s", _len, _name); + break; + + case Handle::VertexBuffer: + setDebugObjectName(m_device, m_vertexBuffers[_handle.idx].m_buffer, "%.*s", _len, _name); + break; + + default: + BX_CHECK(false, "Invalid handle type?! %d", _handle.type); + break; + } } void submitBlit(BlitState& _bs, uint16_t _view); @@ -2281,20 +2413,22 @@ VK_IMPORT_DEVICE void commitShaderUniforms(VkCommandBuffer _commandBuffer, ProgramHandle _program) { const ProgramVK& program = m_program[_program.idx]; - VkDescriptorBufferInfo descriptorBufferInfo; - uint32_t total = 0 - + program.m_vsh->m_size - + (NULL != program.m_fsh ? program.m_fsh->m_size : 0) - ; + + const uint32_t align = uint32_t(m_deviceProperties.limits.minUniformBufferOffsetAlignment); + const uint32_t vsize = bx::strideAlign(program.m_vsh->m_size, align); + const uint32_t fsize = bx::strideAlign( (NULL != program.m_fsh ? program.m_fsh->m_size : 0), align); + const uint32_t total = vsize + fsize; + if (0 < total) { - uint8_t* data = (uint8_t*)m_scratchBuffer[m_backBufferColorIdx].allocUbv(descriptorBufferInfo, total); + ScratchBufferVK& sb = m_scratchBuffer[m_backBufferColorIdx]; - uint32_t size = program.m_vsh->m_size; - bx::memCopy(data, m_vsScratch, size); - data += size; + uint8_t* data = (uint8_t*)sb.allocUbv(vsize, fsize); - if (NULL != program.m_fsh) + bx::memCopy(data, m_vsScratch, program.m_vsh->m_size); + data += vsize; + + if (0 != fsize) { bx::memCopy(data, m_fsScratch, program.m_fsh->m_size); } @@ -2304,8 +2438,7 @@ VK_IMPORT_DEVICE , m_pipelineLayout , 0 , 1 - , &m_scratchBuffer[m_backBufferColorIdx].m_descriptorSet - [m_scratchBuffer[m_backBufferColorIdx].m_currentDs - 1] + , &sb.m_descriptorSet[sb.m_currentDs - 1] , 0 , NULL ); @@ -2903,7 +3036,7 @@ VK_IMPORT_DEVICE // if (isValid(fbh) ) // { // const FrameBufferVK& fb = m_frameBuffers[fbh.idx]; -// numMrt = bx::uint32_max(1, fb.m_num); +// numMrt = bx::max(1, fb.m_num); // } VkClearAttachment attachments[BGFX_CONFIG_MAX_FRAME_BUFFERS]; @@ -2918,7 +3051,7 @@ VK_IMPORT_DEVICE { attachments[mrt].colorAttachment = mrt; attachments[mrt].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); + uint8_t index = bx::min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); bx::memCopy(&attachments[mrt].clearValue.color.float32, _palette[index], 16); ++mrt; } @@ -3205,30 +3338,54 @@ VK_DESTROY m_currentDs = 0; } - void* ScratchBufferVK::allocUbv(VkDescriptorBufferInfo& _descriptorBufferInfo, uint32_t _size) + void* ScratchBufferVK::allocUbv(uint32_t _vsize, uint32_t _fsize) { - uint32_t total = bx::strideAlign(_size - , uint32_t(s_renderVK->m_deviceProperties.limits.minUniformBufferOffsetAlignment) - ); - _descriptorBufferInfo.buffer = m_buffer; - _descriptorBufferInfo.offset = m_pos; - _descriptorBufferInfo.range = total; + VkDescriptorBufferInfo dbi[2]; + + dbi[0].buffer = m_buffer; + dbi[0].offset = m_pos; + dbi[0].range = _vsize; + + VkWriteDescriptorSet wds[2]; - VkWriteDescriptorSet wds[1]; wds[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; wds[0].pNext = NULL; wds[0].dstSet = m_descriptorSet[m_currentDs]; - wds[0].dstBinding = DslBinding::UniformBuffer; + wds[0].dstBinding = DslBinding::VertexUniformBuffer; wds[0].dstArrayElement = 0; wds[0].descriptorCount = 1; wds[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; wds[0].pImageInfo = NULL; - wds[0].pBufferInfo = &_descriptorBufferInfo; + wds[0].pBufferInfo = &dbi[0]; wds[0].pTexelBufferView = NULL; - vkUpdateDescriptorSets(s_renderVK->m_device, BX_COUNTOF(wds), wds, 0, NULL); + + uint32_t numWds = 1; + + if (0 != _fsize) + { + dbi[1].buffer = m_buffer; + dbi[1].offset = m_pos + _vsize; + dbi[1].range = _fsize; + + wds[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + wds[1].pNext = NULL; + wds[1].dstSet = m_descriptorSet[m_currentDs]; + wds[1].dstBinding = DslBinding::FragmentUniformBuffer; + wds[1].dstArrayElement = 0; + wds[1].descriptorCount = 1; + wds[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + wds[1].pImageInfo = NULL; + wds[1].pBufferInfo = &dbi[1]; + wds[1].pTexelBufferView = NULL; + + ++numWds; + } + + vkUpdateDescriptorSets(s_renderVK->m_device, numWds, wds, 0, NULL); void* data = &m_data[m_pos]; - m_pos += total; + + m_pos += _vsize + _fsize; ++m_currentDs; return data; @@ -3570,6 +3727,9 @@ VK_DESTROY smci.flags = 0; smci.codeSize = m_code->size; smci.pCode = (const uint32_t*)m_code->data; + +// disassemble(bx::getDebugOut(), m_code->data, m_code->size); + VK_CHECK(vkCreateShaderModule( s_renderVK->m_device , &smci diff --git a/src/renderer_vk.h b/src/renderer_vk.h index c25a7e7d2..96815cfd8 100644 --- a/src/renderer_vk.h +++ b/src/renderer_vk.h @@ -80,99 +80,111 @@ VK_IMPORT_INSTANCE_FUNC(true, vkDebugReportMessageEXT); \ VK_IMPORT_INSTANCE_PLATFORM -#define VK_IMPORT_DEVICE \ - VK_IMPORT_DEVICE_FUNC(false, vkGetDeviceQueue); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateSwapchainKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroySwapchainKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkGetSwapchainImagesKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkAcquireNextImageKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkQueuePresentKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateFence); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyFence); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateSemaphore); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroySemaphore); \ - VK_IMPORT_DEVICE_FUNC(false, vkResetFences); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateCommandPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyCommandPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkResetCommandPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkAllocateCommandBuffers); \ - VK_IMPORT_DEVICE_FUNC(false, vkFreeCommandBuffers); \ - VK_IMPORT_DEVICE_FUNC(false, vkGetBufferMemoryRequirements); \ - VK_IMPORT_DEVICE_FUNC(false, vkGetImageMemoryRequirements); \ - VK_IMPORT_DEVICE_FUNC(false, vkAllocateMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkFreeMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateImageView); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyImageView); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateFramebuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyFramebuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateRenderPass); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyRenderPass); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateShaderModule); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyShaderModule); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreatePipelineCache); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipelineCache); \ - VK_IMPORT_DEVICE_FUNC(false, vkGetPipelineCacheData); \ - VK_IMPORT_DEVICE_FUNC(false, vkMergePipelineCaches); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateGraphicsPipelines); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateComputePipelines); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipeline); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreatePipelineLayout); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipelineLayout); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateSampler); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroySampler); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateDescriptorSetLayout); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyDescriptorSetLayout); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateDescriptorPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyDescriptorPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkResetDescriptorPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkAllocateDescriptorSets); \ - VK_IMPORT_DEVICE_FUNC(false, vkFreeDescriptorSets); \ - VK_IMPORT_DEVICE_FUNC(false, vkUpdateDescriptorSets); \ - VK_IMPORT_DEVICE_FUNC(false, vkQueueSubmit); \ - VK_IMPORT_DEVICE_FUNC(false, vkQueueWaitIdle); \ - VK_IMPORT_DEVICE_FUNC(false, vkDeviceWaitIdle); \ - VK_IMPORT_DEVICE_FUNC(false, vkWaitForFences); \ - VK_IMPORT_DEVICE_FUNC(false, vkBeginCommandBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkEndCommandBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdPipelineBarrier); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBeginRenderPass); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdEndRenderPass); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdSetViewport); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDraw); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndexed); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndirect); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndexedIndirect); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDispatch); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDispatchIndirect); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBindPipeline); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdSetStencilReference); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdSetBlendConstants); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdSetScissor); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBindDescriptorSets); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBindIndexBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBindVertexBuffers); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdUpdateBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdClearColorImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdClearDepthStencilImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdClearAttachments); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdResolveImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdCopyBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkMapMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkUnmapMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkFlushMappedMemoryRanges); \ - VK_IMPORT_DEVICE_FUNC(false, vkInvalidateMappedMemoryRanges); \ - VK_IMPORT_DEVICE_FUNC(false, vkBindBufferMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkBindImageMemory); \ - /* VK_EXT_debug_marker */ \ - VK_IMPORT_DEVICE_FUNC(true, vkDebugMarkerSetObjectTagEXT); \ - VK_IMPORT_DEVICE_FUNC(true, vkDebugMarkerSetObjectNameEXT); \ - VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerBeginEXT); \ - VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerEndEXT); \ - VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerInsertEXT); \ +#define VK_IMPORT_DEVICE \ + VK_IMPORT_DEVICE_FUNC(false, vkGetDeviceQueue); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateSwapchainKHR); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroySwapchainKHR); \ + VK_IMPORT_DEVICE_FUNC(false, vkGetSwapchainImagesKHR); \ + VK_IMPORT_DEVICE_FUNC(false, vkAcquireNextImageKHR); \ + VK_IMPORT_DEVICE_FUNC(false, vkQueuePresentKHR); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateFence); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyFence); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateSemaphore); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroySemaphore); \ + VK_IMPORT_DEVICE_FUNC(false, vkResetFences); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateCommandPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyCommandPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkResetCommandPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkAllocateCommandBuffers); \ + VK_IMPORT_DEVICE_FUNC(false, vkFreeCommandBuffers); \ + VK_IMPORT_DEVICE_FUNC(false, vkGetBufferMemoryRequirements); \ + VK_IMPORT_DEVICE_FUNC(false, vkGetImageMemoryRequirements); \ + VK_IMPORT_DEVICE_FUNC(false, vkAllocateMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkFreeMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateImageView); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyImageView); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateFramebuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyFramebuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateRenderPass); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyRenderPass); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateShaderModule); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyShaderModule); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreatePipelineCache); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipelineCache); \ + VK_IMPORT_DEVICE_FUNC(false, vkGetPipelineCacheData); \ + VK_IMPORT_DEVICE_FUNC(false, vkMergePipelineCaches); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateGraphicsPipelines); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateComputePipelines); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipeline); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreatePipelineLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipelineLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateSampler); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroySampler); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateDescriptorSetLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyDescriptorSetLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateDescriptorPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyDescriptorPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkResetDescriptorPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkAllocateDescriptorSets); \ + VK_IMPORT_DEVICE_FUNC(false, vkFreeDescriptorSets); \ + VK_IMPORT_DEVICE_FUNC(false, vkUpdateDescriptorSets); \ + VK_IMPORT_DEVICE_FUNC(false, vkQueueSubmit); \ + VK_IMPORT_DEVICE_FUNC(false, vkQueueWaitIdle); \ + VK_IMPORT_DEVICE_FUNC(false, vkDeviceWaitIdle); \ + VK_IMPORT_DEVICE_FUNC(false, vkWaitForFences); \ + VK_IMPORT_DEVICE_FUNC(false, vkBeginCommandBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkEndCommandBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdPipelineBarrier); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBeginRenderPass); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdEndRenderPass); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdSetViewport); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDraw); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndexed); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndirect); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndexedIndirect); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDispatch); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDispatchIndirect); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBindPipeline); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdSetStencilReference); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdSetBlendConstants); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdSetScissor); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBindDescriptorSets); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBindIndexBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBindVertexBuffers); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdUpdateBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdClearColorImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdClearDepthStencilImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdClearAttachments); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdResolveImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdCopyBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkMapMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkUnmapMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkFlushMappedMemoryRanges); \ + VK_IMPORT_DEVICE_FUNC(false, vkInvalidateMappedMemoryRanges); \ + VK_IMPORT_DEVICE_FUNC(false, vkBindBufferMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkBindImageMemory); \ + /* VK_EXT_debug_marker */ \ + VK_IMPORT_DEVICE_FUNC(true, vkDebugMarkerSetObjectTagEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkDebugMarkerSetObjectNameEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerBeginEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerEndEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerInsertEXT); \ + /* VK_EXT_debug_utils */ \ + VK_IMPORT_DEVICE_FUNC(true, vkSetDebugUtilsObjectNameEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkSetDebugUtilsObjectTagEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkQueueBeginDebugUtilsLabelEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkQueueEndDebugUtilsLabelEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkQueueInsertDebugUtilsLabelEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdBeginDebugUtilsLabelEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdEndDebugUtilsLabelEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdInsertDebugUtilsLabelEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCreateDebugUtilsMessengerEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkDestroyDebugUtilsMessengerEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkSubmitDebugUtilsMessageEXT); \ #define VK_DESTROY \ VK_DESTROY_FUNC(Buffer); \ @@ -228,7 +240,8 @@ VK_DESTROY enum Enum { // CombinedImageSampler, - UniformBuffer, + VertexUniformBuffer, + FragmentUniformBuffer, // StorageBuffer, Count @@ -300,7 +313,7 @@ VK_DESTROY void create(uint32_t _size, uint32_t _maxDescriptors); void destroy(); void reset(VkDescriptorBufferInfo& _gpuAddress); - void* allocUbv(VkDescriptorBufferInfo& _gpuAddress, uint32_t _size); + void* allocUbv(uint32_t _vsize, uint32_t _fsize); VkDescriptorSet* m_descriptorSet; VkBuffer m_buffer;