From 454345da1e8d22f3612aa3fec6b1cf3027845d48 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Sun, 17 May 2015 16:33:48 -0700 Subject: [PATCH] vk: Add script for generating ifunc entry points This lets us generate a hash table for vkGetProcAddress and lets us call public functions internally without the public entrypoint overhead. --- .gitignore | 2 + src/vulkan/Makefile.am | 12 ++ src/vulkan/device.c | 186 ++++++++++++++-------------- src/vulkan/image.c | 10 +- src/vulkan/intel.c | 4 +- src/vulkan/meta.c | 22 ++-- src/vulkan/pipeline.c | 16 +-- src/vulkan/private.h | 7 +- src/vulkan/vk_gen.py | 266 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 403 insertions(+), 122 deletions(-) create mode 100644 src/vulkan/vk_gen.py diff --git a/.gitignore b/.gitignore index 21aa35cd36d..e395fd18803 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,5 @@ manifest.txt Makefile Makefile.in .install-mesa-links +entrypoints.c +entrypoints.h diff --git a/src/vulkan/Makefile.am b/src/vulkan/Makefile.am index af2cde5dbbe..8b53a089615 100644 --- a/src/vulkan/Makefile.am +++ b/src/vulkan/Makefile.am @@ -62,8 +62,20 @@ libvulkan_la_SOURCES = \ image.c \ meta.c \ intel.c \ + entrypoints.c \ + entrypoints.h \ compiler.cpp +BUILT_SOURCES = entrypoints.h entrypoints.c + +entrypoints.h : $(vulkan_include_HEADERS) vk_gen.py + $(AM_V_GEN)cat $(vulkan_include_HEADERS) | $(PYTHON2) vk_gen.py header > $@ + +entrypoints.c : $(vulkan_include_HEADERS) vk_gen.py + $(AM_V_GEN)cat $(vulkan_include_HEADERS) | $(PYTHON2) vk_gen.py code > $@ + +CLEANFILES = entrypoints.h entrypoints.c + bin_PROGRAMS = vk vk_SOURCES = vk.c diff --git a/src/vulkan/device.c b/src/vulkan/device.c index 0a80a201d03..d9398e05a24 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -114,7 +114,7 @@ static const VkAllocCallbacks default_alloc_callbacks = { .pfnFree = default_free }; -VkResult VKAPI vkCreateInstance( +VkResult anv_CreateInstance( const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance) { @@ -150,7 +150,7 @@ VkResult VKAPI vkCreateInstance( return VK_SUCCESS; } -VkResult VKAPI vkDestroyInstance( +VkResult anv_DestroyInstance( VkInstance _instance) { struct anv_instance *instance = (struct anv_instance *) _instance; @@ -160,7 +160,7 @@ VkResult VKAPI vkDestroyInstance( return VK_SUCCESS; } -VkResult VKAPI vkEnumeratePhysicalDevices( +VkResult anv_EnumeratePhysicalDevices( VkInstance _instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) @@ -174,7 +174,7 @@ VkResult VKAPI vkEnumeratePhysicalDevices( return VK_SUCCESS; } -VkResult VKAPI vkGetPhysicalDeviceInfo( +VkResult anv_GetPhysicalDeviceInfo( VkPhysicalDevice physicalDevice, VkPhysicalDeviceInfoType infoType, size_t* pDataSize, @@ -252,7 +252,7 @@ void * vkGetProcAddr( VkPhysicalDevice physicalDevice, const char* pName) { - return NULL; + return anv_lookup_entrypoint(pName); } static void @@ -275,7 +275,7 @@ parse_debug_flags(struct anv_device *device) } } -VkResult VKAPI vkCreateDevice( +VkResult anv_CreateDevice( VkPhysicalDevice _physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice) @@ -337,7 +337,7 @@ VkResult VKAPI vkCreateDevice( return vk_error(VK_ERROR_UNAVAILABLE); } -VkResult VKAPI vkDestroyDevice( +VkResult anv_DestroyDevice( VkDevice _device) { struct anv_device *device = (struct anv_device *) _device; @@ -358,7 +358,7 @@ VkResult VKAPI vkDestroyDevice( return VK_SUCCESS; } -VkResult VKAPI vkGetGlobalExtensionInfo( +VkResult anv_GetGlobalExtensionInfo( VkExtensionInfoType infoType, uint32_t extensionIndex, size_t* pDataSize, @@ -381,7 +381,7 @@ VkResult VKAPI vkGetGlobalExtensionInfo( } } -VkResult VKAPI vkGetPhysicalDeviceExtensionInfo( +VkResult anv_GetPhysicalDeviceExtensionInfo( VkPhysicalDevice physicalDevice, VkExtensionInfoType infoType, uint32_t extensionIndex, @@ -405,7 +405,7 @@ VkResult VKAPI vkGetPhysicalDeviceExtensionInfo( } } -VkResult VKAPI vkEnumerateLayers( +VkResult anv_EnumerateLayers( VkPhysicalDevice physicalDevice, size_t maxStringSize, size_t* pLayerCount, @@ -417,7 +417,7 @@ VkResult VKAPI vkEnumerateLayers( return VK_SUCCESS; } -VkResult VKAPI vkGetDeviceQueue( +VkResult anv_GetDeviceQueue( VkDevice _device, uint32_t queueNodeIndex, uint32_t queueIndex, @@ -559,7 +559,7 @@ anv_batch_emit_reloc(struct anv_batch *batch, location - batch->bo.map, bo, delta); } -VkResult VKAPI vkQueueSubmit( +VkResult anv_QueueSubmit( VkQueue _queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, @@ -591,7 +591,7 @@ VkResult VKAPI vkQueueSubmit( return VK_SUCCESS; } -VkResult VKAPI vkQueueAddMemReferences( +VkResult anv_QueueAddMemReferences( VkQueue queue, uint32_t count, const VkDeviceMemory* pMems) @@ -599,7 +599,7 @@ VkResult VKAPI vkQueueAddMemReferences( return VK_SUCCESS; } -VkResult VKAPI vkQueueRemoveMemReferences( +VkResult anv_QueueRemoveMemReferences( VkQueue queue, uint32_t count, const VkDeviceMemory* pMems) @@ -607,7 +607,7 @@ VkResult VKAPI vkQueueRemoveMemReferences( return VK_SUCCESS; } -VkResult VKAPI vkQueueWaitIdle( +VkResult anv_QueueWaitIdle( VkQueue _queue) { struct anv_queue *queue = (struct anv_queue *) _queue; @@ -615,7 +615,7 @@ VkResult VKAPI vkQueueWaitIdle( return vkDeviceWaitIdle((VkDevice) queue->device); } -VkResult VKAPI vkDeviceWaitIdle( +VkResult anv_DeviceWaitIdle( VkDevice _device) { struct anv_device *device = (struct anv_device *) _device; @@ -717,7 +717,7 @@ anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size) return VK_SUCCESS; } -VkResult VKAPI vkAllocMemory( +VkResult anv_AllocMemory( VkDevice _device, const VkMemoryAllocInfo* pAllocInfo, VkDeviceMemory* pMem) @@ -747,7 +747,7 @@ VkResult VKAPI vkAllocMemory( return result; } -VkResult VKAPI vkFreeMemory( +VkResult anv_FreeMemory( VkDevice _device, VkDeviceMemory _mem) { @@ -765,7 +765,7 @@ VkResult VKAPI vkFreeMemory( return VK_SUCCESS; } -VkResult VKAPI vkSetMemoryPriority( +VkResult anv_SetMemoryPriority( VkDevice device, VkDeviceMemory mem, VkMemoryPriority priority) @@ -773,7 +773,7 @@ VkResult VKAPI vkSetMemoryPriority( return VK_SUCCESS; } -VkResult VKAPI vkMapMemory( +VkResult anv_MapMemory( VkDevice _device, VkDeviceMemory _mem, VkDeviceSize offset, @@ -798,7 +798,7 @@ VkResult VKAPI vkMapMemory( return VK_SUCCESS; } -VkResult VKAPI vkUnmapMemory( +VkResult anv_UnmapMemory( VkDevice _device, VkDeviceMemory _mem) { @@ -809,7 +809,7 @@ VkResult VKAPI vkUnmapMemory( return VK_SUCCESS; } -VkResult VKAPI vkFlushMappedMemory( +VkResult anv_FlushMappedMemory( VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, @@ -820,7 +820,7 @@ VkResult VKAPI vkFlushMappedMemory( return VK_SUCCESS; } -VkResult VKAPI vkPinSystemMemory( +VkResult anv_PinSystemMemory( VkDevice device, const void* pSysMem, size_t memSize, @@ -829,7 +829,7 @@ VkResult VKAPI vkPinSystemMemory( return VK_SUCCESS; } -VkResult VKAPI vkGetMultiDeviceCompatibility( +VkResult anv_GetMultiDeviceCompatibility( VkPhysicalDevice physicalDevice0, VkPhysicalDevice physicalDevice1, VkPhysicalDeviceCompatibilityInfo* pInfo) @@ -837,7 +837,7 @@ VkResult VKAPI vkGetMultiDeviceCompatibility( return VK_UNSUPPORTED; } -VkResult VKAPI vkOpenSharedMemory( +VkResult anv_OpenSharedMemory( VkDevice device, const VkMemoryOpenInfo* pOpenInfo, VkDeviceMemory* pMem) @@ -845,7 +845,7 @@ VkResult VKAPI vkOpenSharedMemory( return VK_UNSUPPORTED; } -VkResult VKAPI vkOpenSharedSemaphore( +VkResult anv_OpenSharedSemaphore( VkDevice device, const VkSemaphoreOpenInfo* pOpenInfo, VkSemaphore* pSemaphore) @@ -853,7 +853,7 @@ VkResult VKAPI vkOpenSharedSemaphore( return VK_UNSUPPORTED; } -VkResult VKAPI vkOpenPeerMemory( +VkResult anv_OpenPeerMemory( VkDevice device, const VkPeerMemoryOpenInfo* pOpenInfo, VkDeviceMemory* pMem) @@ -861,7 +861,7 @@ VkResult VKAPI vkOpenPeerMemory( return VK_UNSUPPORTED; } -VkResult VKAPI vkOpenPeerImage( +VkResult anv_OpenPeerImage( VkDevice device, const VkPeerImageOpenInfo* pOpenInfo, VkImage* pImage, @@ -939,7 +939,7 @@ static VkResult (*anv_object_destructors[])(struct anv_device *device, [VK_OBJECT_TYPE_RENDER_PASS] = anv_free_destructor }; -VkResult VKAPI vkDestroyObject( +VkResult anv_DestroyObject( VkDevice _device, VkObjectType objType, VkObject object) @@ -988,7 +988,7 @@ fill_memory_requirements( } } -VkResult VKAPI vkGetObjectInfo( +VkResult anv_GetObjectInfo( VkDevice _device, VkObjectType objType, VkObject object, @@ -1013,7 +1013,7 @@ VkResult VKAPI vkGetObjectInfo( } -VkResult VKAPI vkQueueBindObjectMemory( +VkResult anv_QueueBindObjectMemory( VkQueue queue, VkObjectType objType, VkObject object, @@ -1043,7 +1043,7 @@ VkResult VKAPI vkQueueBindObjectMemory( return VK_SUCCESS; } -VkResult VKAPI vkQueueBindObjectMemoryRange( +VkResult anv_QueueBindObjectMemoryRange( VkQueue queue, VkObjectType objType, VkObject object, @@ -1056,7 +1056,7 @@ VkResult VKAPI vkQueueBindObjectMemoryRange( stub_return(VK_UNSUPPORTED); } -VkResult vkQueueBindImageMemoryRange( +VkResult anv_QueueBindImageMemoryRange( VkQueue queue, VkImage image, uint32_t allocationIdx, @@ -1067,7 +1067,7 @@ VkResult vkQueueBindImageMemoryRange( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkCreateFence( +VkResult anv_CreateFence( VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence) @@ -1075,7 +1075,7 @@ VkResult VKAPI vkCreateFence( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkResetFences( +VkResult anv_ResetFences( VkDevice device, uint32_t fenceCount, VkFence* pFences) @@ -1083,14 +1083,14 @@ VkResult VKAPI vkResetFences( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkGetFenceStatus( +VkResult anv_GetFenceStatus( VkDevice device, VkFence fence) { stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkWaitForFences( +VkResult anv_WaitForFences( VkDevice device, uint32_t fenceCount, const VkFence* pFences, @@ -1102,7 +1102,7 @@ VkResult VKAPI vkWaitForFences( // Queue semaphore functions -VkResult VKAPI vkCreateSemaphore( +VkResult anv_CreateSemaphore( VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, VkSemaphore* pSemaphore) @@ -1110,14 +1110,14 @@ VkResult VKAPI vkCreateSemaphore( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkQueueSignalSemaphore( +VkResult anv_QueueSignalSemaphore( VkQueue queue, VkSemaphore semaphore) { stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkQueueWaitSemaphore( +VkResult anv_QueueWaitSemaphore( VkQueue queue, VkSemaphore semaphore) { @@ -1126,7 +1126,7 @@ VkResult VKAPI vkQueueWaitSemaphore( // Event functions -VkResult VKAPI vkCreateEvent( +VkResult anv_CreateEvent( VkDevice device, const VkEventCreateInfo* pCreateInfo, VkEvent* pEvent) @@ -1134,21 +1134,21 @@ VkResult VKAPI vkCreateEvent( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkGetEventStatus( +VkResult anv_GetEventStatus( VkDevice device, VkEvent event) { stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkSetEvent( +VkResult anv_SetEvent( VkDevice device, VkEvent event) { stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkResetEvent( +VkResult anv_ResetEvent( VkDevice device, VkEvent event) { @@ -1163,7 +1163,7 @@ struct anv_query_pool { struct anv_bo bo; }; -VkResult VKAPI vkCreateQueryPool( +VkResult anv_CreateQueryPool( VkDevice _device, const VkQueryPoolCreateInfo* pCreateInfo, VkQueryPool* pQueryPool) @@ -1194,7 +1194,7 @@ VkResult VKAPI vkCreateQueryPool( return result; } -VkResult VKAPI vkGetQueryPoolResults( +VkResult anv_GetQueryPoolResults( VkDevice device, VkQueryPool queryPool, uint32_t startQuery, @@ -1208,7 +1208,7 @@ VkResult VKAPI vkGetQueryPoolResults( // Format capabilities -VkResult VKAPI vkGetFormatInfo( +VkResult anv_GetFormatInfo( VkDevice device, VkFormat format, VkFormatInfoType infoType, @@ -1220,7 +1220,7 @@ VkResult VKAPI vkGetFormatInfo( // Buffer functions -VkResult VKAPI vkCreateBuffer( +VkResult anv_CreateBuffer( VkDevice _device, const VkBufferCreateInfo* pCreateInfo, VkBuffer* pBuffer) @@ -1246,7 +1246,7 @@ VkResult VKAPI vkCreateBuffer( // Buffer view functions -VkResult VKAPI vkCreateBufferView( +VkResult anv_CreateBufferView( VkDevice _device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView) @@ -1320,7 +1320,7 @@ VkResult VKAPI vkCreateBufferView( // Sampler functions -VkResult VKAPI vkCreateSampler( +VkResult anv_CreateSampler( VkDevice _device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler) @@ -1410,7 +1410,7 @@ VkResult VKAPI vkCreateSampler( // Descriptor set functions -VkResult VKAPI vkCreateDescriptorSetLayout( +VkResult anv_CreateDescriptorSetLayout( VkDevice _device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout) @@ -1537,21 +1537,21 @@ VkResult VKAPI vkCreateDescriptorSetLayout( return VK_SUCCESS; } -VkResult VKAPI vkBeginDescriptorPoolUpdate( +VkResult anv_BeginDescriptorPoolUpdate( VkDevice device, VkDescriptorUpdateMode updateMode) { stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkEndDescriptorPoolUpdate( +VkResult anv_EndDescriptorPoolUpdate( VkDevice device, VkCmdBuffer cmd) { stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkCreateDescriptorPool( +VkResult anv_CreateDescriptorPool( VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, @@ -1561,14 +1561,14 @@ VkResult VKAPI vkCreateDescriptorPool( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkResetDescriptorPool( +VkResult anv_ResetDescriptorPool( VkDevice device, VkDescriptorPool descriptorPool) { stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkAllocDescriptorSets( +VkResult anv_AllocDescriptorSets( VkDevice _device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, @@ -1600,7 +1600,7 @@ VkResult VKAPI vkAllocDescriptorSets( return VK_UNSUPPORTED; } -void VKAPI vkClearDescriptorSets( +void anv_ClearDescriptorSets( VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, @@ -1609,7 +1609,7 @@ void VKAPI vkClearDescriptorSets( stub(); } -void VKAPI vkUpdateDescriptors( +void anv_UpdateDescriptors( VkDevice _device, VkDescriptorSet descriptorSet, uint32_t updateCount, @@ -1692,7 +1692,7 @@ clamp_int64(int64_t x, int64_t min, int64_t max) return max; } -VkResult VKAPI vkCreateDynamicViewportState( +VkResult anv_CreateDynamicViewportState( VkDevice _device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState) @@ -1777,7 +1777,7 @@ VkResult VKAPI vkCreateDynamicViewportState( return VK_SUCCESS; } -VkResult VKAPI vkCreateDynamicRasterState( +VkResult anv_CreateDynamicRasterState( VkDevice _device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState) @@ -1813,7 +1813,7 @@ VkResult VKAPI vkCreateDynamicRasterState( return VK_SUCCESS; } -VkResult VKAPI vkCreateDynamicColorBlendState( +VkResult anv_CreateDynamicColorBlendState( VkDevice _device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState) @@ -1833,7 +1833,7 @@ VkResult VKAPI vkCreateDynamicColorBlendState( return VK_SUCCESS; } -VkResult VKAPI vkCreateDynamicDepthStencilState( +VkResult anv_CreateDynamicDepthStencilState( VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState) @@ -1843,7 +1843,7 @@ VkResult VKAPI vkCreateDynamicDepthStencilState( // Command buffer functions -VkResult VKAPI vkCreateCommandBuffer( +VkResult anv_CreateCommandBuffer( VkDevice _device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer) @@ -1905,7 +1905,7 @@ VkResult VKAPI vkCreateCommandBuffer( return result; } -VkResult VKAPI vkBeginCommandBuffer( +VkResult anv_BeginCommandBuffer( VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo) { @@ -2049,7 +2049,7 @@ anv_cmd_buffer_process_relocs(struct anv_cmd_buffer *cmd_buffer, } } -VkResult VKAPI vkEndCommandBuffer( +VkResult anv_EndCommandBuffer( VkCmdBuffer cmdBuffer) { struct anv_cmd_buffer *cmd_buffer = (struct anv_cmd_buffer *) cmdBuffer; @@ -2099,7 +2099,7 @@ VkResult VKAPI vkEndCommandBuffer( return VK_SUCCESS; } -VkResult VKAPI vkResetCommandBuffer( +VkResult anv_ResetCommandBuffer( VkCmdBuffer cmdBuffer) { struct anv_cmd_buffer *cmd_buffer = (struct anv_cmd_buffer *) cmdBuffer; @@ -2111,7 +2111,7 @@ VkResult VKAPI vkResetCommandBuffer( // Command buffer building functions -void VKAPI vkCmdBindPipeline( +void anv_CmdBindPipeline( VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline _pipeline) @@ -2122,7 +2122,7 @@ void VKAPI vkCmdBindPipeline( cmd_buffer->dirty |= ANV_CMD_BUFFER_PIPELINE_DIRTY; } -void VKAPI vkCmdBindDynamicStateObject( +void anv_CmdBindDynamicStateObject( VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject dynamicState) @@ -2155,7 +2155,7 @@ void VKAPI vkCmdBindDynamicStateObject( }; } -void VKAPI vkCmdBindDescriptorSets( +void anv_CmdBindDescriptorSets( VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t firstSet, @@ -2205,7 +2205,7 @@ void VKAPI vkCmdBindDescriptorSets( cmd_buffer->dirty |= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY; } -void VKAPI vkCmdBindIndexBuffer( +void anv_CmdBindIndexBuffer( VkCmdBuffer cmdBuffer, VkBuffer _buffer, VkDeviceSize offset, @@ -2227,7 +2227,7 @@ void VKAPI vkCmdBindIndexBuffer( .BufferSize = buffer->size - offset); } -void VKAPI vkCmdBindVertexBuffers( +void anv_CmdBindVertexBuffers( VkCmdBuffer cmdBuffer, uint32_t startBinding, uint32_t bindingCount, @@ -2375,7 +2375,7 @@ anv_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer) cmd_buffer->dirty = 0; } -void VKAPI vkCmdDraw( +void anv_CmdDraw( VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, @@ -2395,7 +2395,7 @@ void VKAPI vkCmdDraw( .BaseVertexLocation = 0); } -void VKAPI vkCmdDrawIndexed( +void anv_CmdDrawIndexed( VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, @@ -2441,7 +2441,7 @@ anv_batch_lri(struct anv_batch *batch, uint32_t reg, uint32_t imm) #define GEN7_3DPRIM_START_INSTANCE 0x243C #define GEN7_3DPRIM_BASE_VERTEX 0x2440 -void VKAPI vkCmdDrawIndirect( +void anv_CmdDrawIndirect( VkCmdBuffer cmdBuffer, VkBuffer _buffer, VkDeviceSize offset, @@ -2466,7 +2466,7 @@ void VKAPI vkCmdDrawIndirect( .VertexAccessType = SEQUENTIAL); } -void VKAPI vkCmdDrawIndexedIndirect( +void anv_CmdDrawIndexedIndirect( VkCmdBuffer cmdBuffer, VkBuffer _buffer, VkDeviceSize offset, @@ -2491,7 +2491,7 @@ void VKAPI vkCmdDrawIndexedIndirect( .VertexAccessType = RANDOM); } -void VKAPI vkCmdDispatch( +void anv_CmdDispatch( VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, @@ -2500,7 +2500,7 @@ void VKAPI vkCmdDispatch( stub(); } -void VKAPI vkCmdDispatchIndirect( +void anv_CmdDispatchIndirect( VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset) @@ -2508,7 +2508,7 @@ void VKAPI vkCmdDispatchIndirect( stub(); } -void VKAPI vkCmdSetEvent( +void anv_CmdSetEvent( VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent) @@ -2516,7 +2516,7 @@ void VKAPI vkCmdSetEvent( stub(); } -void VKAPI vkCmdResetEvent( +void anv_CmdResetEvent( VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent) @@ -2524,7 +2524,7 @@ void VKAPI vkCmdResetEvent( stub(); } -void VKAPI vkCmdWaitEvents( +void anv_CmdWaitEvents( VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t eventCount, @@ -2535,7 +2535,7 @@ void VKAPI vkCmdWaitEvents( stub(); } -void VKAPI vkCmdPipelineBarrier( +void anv_CmdPipelineBarrier( VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t pipeEventCount, @@ -2556,7 +2556,7 @@ anv_batch_emit_ps_depth_count(struct anv_batch *batch, .Address = { bo, offset }); /* FIXME: This is only lower 32 bits */ } -void VKAPI vkCmdBeginQuery( +void anv_CmdBeginQuery( VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, @@ -2578,7 +2578,7 @@ void VKAPI vkCmdBeginQuery( } } -void VKAPI vkCmdEndQuery( +void anv_CmdEndQuery( VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot) @@ -2599,7 +2599,7 @@ void VKAPI vkCmdEndQuery( } } -void VKAPI vkCmdResetQueryPool( +void anv_CmdResetQueryPool( VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, @@ -2610,7 +2610,7 @@ void VKAPI vkCmdResetQueryPool( #define TIMESTAMP 0x44070 -void VKAPI vkCmdWriteTimestamp( +void anv_CmdWriteTimestamp( VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, @@ -2640,7 +2640,7 @@ void VKAPI vkCmdWriteTimestamp( } } -void VKAPI vkCmdCopyQueryPoolResults( +void anv_CmdCopyQueryPoolResults( VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, @@ -2653,7 +2653,7 @@ void VKAPI vkCmdCopyQueryPoolResults( stub(); } -void VKAPI vkCmdInitAtomicCounters( +void anv_CmdInitAtomicCounters( VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, @@ -2663,7 +2663,7 @@ void VKAPI vkCmdInitAtomicCounters( stub(); } -void VKAPI vkCmdLoadAtomicCounters( +void anv_CmdLoadAtomicCounters( VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, @@ -2674,7 +2674,7 @@ void VKAPI vkCmdLoadAtomicCounters( stub(); } -void VKAPI vkCmdSaveAtomicCounters( +void anv_CmdSaveAtomicCounters( VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, @@ -2685,7 +2685,7 @@ void VKAPI vkCmdSaveAtomicCounters( stub(); } -VkResult VKAPI vkCreateFramebuffer( +VkResult anv_CreateFramebuffer( VkDevice _device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer) @@ -2742,7 +2742,7 @@ VkResult VKAPI vkCreateFramebuffer( return VK_SUCCESS; } -VkResult VKAPI vkCreateRenderPass( +VkResult anv_CreateRenderPass( VkDevice _device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass) @@ -2793,7 +2793,7 @@ anv_cmd_buffer_fill_render_targets(struct anv_cmd_buffer *cmd_buffer) cmd_buffer->dirty |= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY; } -void VKAPI vkCmdBeginRenderPass( +void anv_CmdBeginRenderPass( VkCmdBuffer cmdBuffer, const VkRenderPassBegin* pRenderPassBegin) { @@ -2819,7 +2819,7 @@ void VKAPI vkCmdBeginRenderPass( anv_cmd_buffer_clear(cmd_buffer, pass); } -void VKAPI vkCmdEndRenderPass( +void anv_CmdEndRenderPass( VkCmdBuffer cmdBuffer, VkRenderPass renderPass) { diff --git a/src/vulkan/image.c b/src/vulkan/image.c index aae9fbf0e8c..812fba88b9f 100644 --- a/src/vulkan/image.c +++ b/src/vulkan/image.c @@ -224,7 +224,7 @@ static const struct anv_tile_mode_info { [WMAJOR] = { 128, 32 } }; -VkResult VKAPI vkCreateImage( +VkResult anv_CreateImage( VkDevice _device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage) @@ -279,7 +279,7 @@ VkResult VKAPI vkCreateImage( return VK_SUCCESS; } -VkResult VKAPI vkGetImageSubresourceInfo( +VkResult anv_GetImageSubresourceInfo( VkDevice device, VkImage image, const VkImageSubresource* pSubresource, @@ -342,7 +342,7 @@ create_surface_state(struct anv_device *device, return state; } -VkResult VKAPI vkCreateImageView( +VkResult anv_CreateImageView( VkDevice _device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView) @@ -373,7 +373,7 @@ VkResult VKAPI vkCreateImageView( return VK_SUCCESS; } -VkResult VKAPI vkCreateColorAttachmentView( +VkResult anv_CreateColorAttachmentView( VkDevice _device, const VkColorAttachmentViewCreateInfo* pCreateInfo, VkColorAttachmentView* pView) @@ -402,7 +402,7 @@ VkResult VKAPI vkCreateColorAttachmentView( return VK_SUCCESS; } -VkResult VKAPI vkCreateDepthStencilView( +VkResult anv_CreateDepthStencilView( VkDevice device, const VkDepthStencilViewCreateInfo* pCreateInfo, VkDepthStencilView* pView) diff --git a/src/vulkan/intel.c b/src/vulkan/intel.c index 52fadb1ab06..fbfed596397 100644 --- a/src/vulkan/intel.c +++ b/src/vulkan/intel.c @@ -29,9 +29,7 @@ #include "private.h" -#include - -VkResult VKAPI vkCreateDmaBufImageINTEL( +VkResult anv_CreateDmaBufImageINTEL( VkDevice _device, const VkDmaBufImageCreateInfo* pCreateInfo, VkDeviceMemory* pMem, diff --git a/src/vulkan/meta.c b/src/vulkan/meta.c index aa7b16aee34..c3679464151 100644 --- a/src/vulkan/meta.c +++ b/src/vulkan/meta.c @@ -628,7 +628,7 @@ meta_finish_blit(struct anv_cmd_buffer *cmd_buffer, anv_cmd_buffer_restore(cmd_buffer, saved_state); } -void VKAPI vkCmdCopyBuffer( +void anv_CmdCopyBuffer( VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, @@ -638,7 +638,7 @@ void VKAPI vkCmdCopyBuffer( stub(); } -void VKAPI vkCmdCopyImage( +void anv_CmdCopyImage( VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, @@ -650,7 +650,7 @@ void VKAPI vkCmdCopyImage( stub(); } -void VKAPI vkCmdBlitImage( +void anv_CmdBlitImage( VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, @@ -662,7 +662,7 @@ void VKAPI vkCmdBlitImage( stub(); } -void VKAPI vkCmdCopyBufferToImage( +void anv_CmdCopyBufferToImage( VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkImage destImage, @@ -673,7 +673,7 @@ void VKAPI vkCmdCopyBufferToImage( stub(); } -void VKAPI vkCmdCopyImageToBuffer( +void anv_CmdCopyImageToBuffer( VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, @@ -764,7 +764,7 @@ void VKAPI vkCmdCopyImageToBuffer( meta_finish_blit(cmd_buffer, &saved_state); } -void VKAPI vkCmdCloneImageData( +void anv_CmdCloneImageData( VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, @@ -774,7 +774,7 @@ void VKAPI vkCmdCloneImageData( stub(); } -void VKAPI vkCmdUpdateBuffer( +void anv_CmdUpdateBuffer( VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, @@ -784,7 +784,7 @@ void VKAPI vkCmdUpdateBuffer( stub(); } -void VKAPI vkCmdFillBuffer( +void anv_CmdFillBuffer( VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, @@ -794,7 +794,7 @@ void VKAPI vkCmdFillBuffer( stub(); } -void VKAPI vkCmdClearColorImage( +void anv_CmdClearColorImage( VkCmdBuffer cmdBuffer, VkImage image, VkImageLayout imageLayout, @@ -805,7 +805,7 @@ void VKAPI vkCmdClearColorImage( stub(); } -void VKAPI vkCmdClearDepthStencil( +void anv_CmdClearDepthStencil( VkCmdBuffer cmdBuffer, VkImage image, VkImageLayout imageLayout, @@ -817,7 +817,7 @@ void VKAPI vkCmdClearDepthStencil( stub(); } -void VKAPI vkCmdResolveImage( +void anv_CmdResolveImage( VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, diff --git a/src/vulkan/pipeline.c b/src/vulkan/pipeline.c index 60389e4bbba..6711d5e349f 100644 --- a/src/vulkan/pipeline.c +++ b/src/vulkan/pipeline.c @@ -31,7 +31,7 @@ // Shader functions -VkResult VKAPI vkCreateShader( +VkResult anv_CreateShader( VkDevice _device, const VkShaderCreateInfo* pCreateInfo, VkShader* pShader) @@ -214,7 +214,7 @@ emit_rs_state(struct anv_pipeline *pipeline, VkPipelineRsStateCreateInfo *info, } -VkResult VKAPI vkCreateGraphicsPipeline( +VkResult anv_CreateGraphicsPipeline( VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline) @@ -506,7 +506,7 @@ anv_pipeline_destroy(struct anv_pipeline *pipeline) return VK_SUCCESS; } -VkResult VKAPI vkCreateGraphicsPipelineDerivative( +VkResult anv_CreateGraphicsPipelineDerivative( VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline basePipeline, @@ -515,7 +515,7 @@ VkResult VKAPI vkCreateGraphicsPipelineDerivative( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkCreateComputePipeline( +VkResult anv_CreateComputePipeline( VkDevice device, const VkComputePipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline) @@ -523,7 +523,7 @@ VkResult VKAPI vkCreateComputePipeline( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkStorePipeline( +VkResult anv_StorePipeline( VkDevice device, VkPipeline pipeline, size_t* pDataSize, @@ -532,7 +532,7 @@ VkResult VKAPI vkStorePipeline( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkLoadPipeline( +VkResult anv_LoadPipeline( VkDevice device, size_t dataSize, const void* pData, @@ -541,7 +541,7 @@ VkResult VKAPI vkLoadPipeline( stub_return(VK_UNSUPPORTED); } -VkResult VKAPI vkLoadPipelineDerivative( +VkResult anv_LoadPipelineDerivative( VkDevice device, size_t dataSize, const void* pData, @@ -553,7 +553,7 @@ VkResult VKAPI vkLoadPipelineDerivative( // Pipeline layout functions -VkResult VKAPI vkCreatePipelineLayout( +VkResult anv_CreatePipelineLayout( VkDevice _device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout) diff --git a/src/vulkan/private.h b/src/vulkan/private.h index 554bd005a34..cf5b88f6a68 100644 --- a/src/vulkan/private.h +++ b/src/vulkan/private.h @@ -35,9 +35,9 @@ #define VK_PROTOTYPES #include +#include -#undef VKAPI -#define VKAPI __attribute__ ((visibility ("default"))) +#include "entrypoints.h" #include "brw_context.h" @@ -689,6 +689,9 @@ anv_cmd_buffer_clear(struct anv_cmd_buffer *cmd_buffer, void anv_cmd_buffer_fill_render_targets(struct anv_cmd_buffer *cmd_buffer); +void * +anv_lookup_entrypoint(const char *name); + #ifdef __cplusplus } #endif diff --git a/src/vulkan/vk_gen.py b/src/vulkan/vk_gen.py new file mode 100644 index 00000000000..b82c90f73aa --- /dev/null +++ b/src/vulkan/vk_gen.py @@ -0,0 +1,266 @@ +# coding=utf-8 +# +# Copyright © 2015 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +import fileinput, re, sys + +# Each function typedef in the vulkan.h header is all on one line and matches +# this regepx. We hope that won't change. + +p = re.compile('typedef ([^ ]*) *\(VKAPI \*PFN_vk([^(]*)\)(.*);') + +entrypoints = [] + +# We generate a static hash table for entry point lookup +# (vkGetProcAddress). We use a linear congruential generator for our hash +# function and a power-of-two size table. The prime numbers are determined +# experimentally. + +none = 0xffff +hash_size = 256 +u32_mask = 2**32 - 1 +hash_mask = hash_size - 1 + +prime_factor = 5024183 +prime_step = 19 + +def hash(name): + h = 0; + for c in name: + h = (h * prime_factor + ord(c)) & u32_mask + + return h + +opt_header = False +opt_code = False + +if (sys.argv[1] == "header"): + opt_header = True + sys.argv.pop() +elif (sys.argv[1] == "code"): + opt_code = True + sys.argv.pop() + +# Parse the entry points in the header + +i = 0 +for line in fileinput.input(): + m = p.match(line) + if (m): + fullname = "vk" + m.group(2) + h = hash(fullname) + entrypoints.append((m.group(1), m.group(2), m.group(3), i, h)) + i = i + 1 + +# For outputting entrypoints.h we generate a anv_EntryPoint() prototype +# per entry point. + +if opt_header: + for type, name, args, num, h in entrypoints: + print "%s anv_%s%s;" % (type, name, args) + print "%s anv_validate_%s%s;" % (type, name, args) + exit() + + + +print """/* + * Copyright © 2015 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/* This file generated from vk_gen.py, don't edit directly. */ + +#include "private.h" + +struct anv_entrypoint { + uint32_t name; + uint32_t hash; + void *function; + void *validate; +}; + +/* We use a big string constant to avoid lots of reloctions from the entry + * point table to lots of little strings. The entries in the entry point table + * store the index into this big string. + */ + +static const char strings[] =""" + +offsets = [] +i = 0; +for type, name, args, num, h in entrypoints: + print " \"vk%s\\0\"" % name + offsets.append(i) + i += 2 + len(name) + 1 +print """ ; + +/* Weak aliases for all potential validate functions. These will resolve to + * NULL if they're not defined, which lets the resolve_entrypoint() function + * either pick a validate wrapper if available or just plug in the actual + * entry point. + */ +""" + +for type, name, args, num, h in entrypoints: + print "%s anv_validate_%s%s __attribute__ ((weak));" % (type, name, args) + +# Now generate the table of all entry points and their validation functions + +print "\nstatic const struct anv_entrypoint entrypoints[] = {" +for type, name, args, num, h in entrypoints: + print " { %5d, 0x%08x, anv_%s, anv_validate_%s }," % (offsets[num], h, name, name) +print "};\n" + +print """ +#ifdef DEBUG +static bool enable_validate = true; +#else +static bool enable_validate = false; +#endif + +/* We can't use symbols that need resolving (like, oh, getenv) in the resolve + * function. This means that we have to determine whether or not to use the + * validation layer sometime before that. The constructor function attribute asks + * the dynamic linker to invoke determine_validate() at dlopen() time which + * works. + */ +static void __attribute__ ((constructor)) +determine_validate(void) +{ + const char *s = getenv("ANV_VALIDATE"); + + if (s) + enable_validate = atoi(s); +} + +static void * __attribute__ ((noinline)) +resolve_entrypoint(uint32_t index) +{ + if (enable_validate && entrypoints[index].validate) + return entrypoints[index].validate; + + return entrypoints[index].function; +} +""" + +# Now output ifuncs and their resolve helpers for all entry points. The +# resolve helper calls resolve_entrypoint() with the entry point index, which +# lets the resolver look it up in the table. + +for type, name, args, num, h in entrypoints: + print "static void *resolve_%s(void) { return resolve_entrypoint(%d); }" % (name, num) + print "%s vk%s%s\n __attribute__ ((ifunc (\"resolve_%s\"), visibility (\"default\")));\n" % (type, name, args, name) + +# Now generate the hash table used for entry point look up. This is a +# uint16_t table of entry point indices. We use 0xffff to indicate an entry +# in the hash table is empty. + +map = [none for f in xrange(hash_size)] +collisions = [0 for f in xrange(10)] +for type, name, args, num, h in entrypoints: + level = 0 + while map[h & hash_mask] != none: + h = h + prime_step + level = level + 1 + if level > 9: + collisions[9] += 1 + else: + collisions[level] += 1 + map[h & hash_mask] = num + +print "/* Hash table stats:" +print " * size %d entries" % hash_size +print " * collisions entries" +for i in xrange(10): + if (i == 9): + plus = "+" + else: + plus = " " + + print " * %2d%s %4d" % (i, plus, collisions[i]) +print " */\n" + +print "#define none 0x%04x\n" % none + +print "static const uint16_t map[] = {" +for i in xrange(0, hash_size, 8): + print " ", + for j in xrange(i, i + 8): + if map[j] & 0xffff == 0xffff: + print " none,", + else: + print "0x%04x," % (map[j] & 0xffff), + print + +print "};" + +# Finally we generate the hash table lookup function. The hash function and +# linear probing algorithm matches the hash table generated above. + +print """ +void * +anv_lookup_entrypoint(const char *name) +{ + static const uint32_t prime_factor = %d; + static const uint32_t prime_step = %d; + const struct anv_entrypoint *e; + uint32_t hash, h, i; + const char *p; + + hash = 0; + for (p = name; *p; p++) + hash = hash * prime_factor + *p; + + h = hash; + do { + i = map[h & %d]; + if (i == none) + return NULL; + e = &entrypoints[i]; + h += prime_step; + } while (e->hash != hash); + + if (strcmp(name, strings + e->name) != 0) + return NULL; + + return resolve_entrypoint(i); +} +""" % (prime_factor, prime_step, hash_mask) -- 2.30.2