Home | History | Annotate | Download | only in loader
      1 /*
      2  *
      3  * Copyright (c) 2015 The Khronos Group Inc.
      4  * Copyright (c) 2015 Valve Corporation
      5  * Copyright (c) 2015 LunarG, Inc.
      6  *
      7  * Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *     http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  *
     19  * Author: Jon Ashburn <jon (at) lunarg.com>
     20  */
     21 
     22 #include <string.h>
     23 #include "debug_report.h"
     24 #include "wsi.h"
     25 #include "extensions.h"
     26 
     27 static inline void *trampolineGetProcAddr(struct loader_instance *inst,
     28                                           const char *funcName) {
     29     // Don't include or check global functions
     30     if (!strcmp(funcName, "vkGetInstanceProcAddr"))
     31         return (PFN_vkVoidFunction)vkGetInstanceProcAddr;
     32     if (!strcmp(funcName, "vkDestroyInstance"))
     33         return (PFN_vkVoidFunction)vkDestroyInstance;
     34     if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
     35         return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices;
     36     if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
     37         return (PFN_vkVoidFunction)vkGetPhysicalDeviceFeatures;
     38     if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
     39         return (PFN_vkVoidFunction)vkGetPhysicalDeviceFormatProperties;
     40     if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
     41         return (PFN_vkVoidFunction)vkGetPhysicalDeviceImageFormatProperties;
     42     if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
     43         return (
     44             PFN_vkVoidFunction)vkGetPhysicalDeviceSparseImageFormatProperties;
     45     if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
     46         return (PFN_vkVoidFunction)vkGetPhysicalDeviceProperties;
     47     if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
     48         return (PFN_vkVoidFunction)vkGetPhysicalDeviceQueueFamilyProperties;
     49     if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
     50         return (PFN_vkVoidFunction)vkGetPhysicalDeviceMemoryProperties;
     51     if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
     52         return (PFN_vkVoidFunction)vkEnumerateDeviceLayerProperties;
     53     if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
     54         return (PFN_vkVoidFunction)vkEnumerateDeviceExtensionProperties;
     55     if (!strcmp(funcName, "vkCreateDevice"))
     56         return (PFN_vkVoidFunction)vkCreateDevice;
     57     if (!strcmp(funcName, "vkGetDeviceProcAddr"))
     58         return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
     59     if (!strcmp(funcName, "vkDestroyDevice"))
     60         return (PFN_vkVoidFunction)vkDestroyDevice;
     61     if (!strcmp(funcName, "vkGetDeviceQueue"))
     62         return (PFN_vkVoidFunction)vkGetDeviceQueue;
     63     if (!strcmp(funcName, "vkQueueSubmit"))
     64         return (PFN_vkVoidFunction)vkQueueSubmit;
     65     if (!strcmp(funcName, "vkQueueWaitIdle"))
     66         return (PFN_vkVoidFunction)vkQueueWaitIdle;
     67     if (!strcmp(funcName, "vkDeviceWaitIdle"))
     68         return (PFN_vkVoidFunction)vkDeviceWaitIdle;
     69     if (!strcmp(funcName, "vkAllocateMemory"))
     70         return (PFN_vkVoidFunction)vkAllocateMemory;
     71     if (!strcmp(funcName, "vkFreeMemory"))
     72         return (PFN_vkVoidFunction)vkFreeMemory;
     73     if (!strcmp(funcName, "vkMapMemory"))
     74         return (PFN_vkVoidFunction)vkMapMemory;
     75     if (!strcmp(funcName, "vkUnmapMemory"))
     76         return (PFN_vkVoidFunction)vkUnmapMemory;
     77     if (!strcmp(funcName, "vkFlushMappedMemoryRanges"))
     78         return (PFN_vkVoidFunction)vkFlushMappedMemoryRanges;
     79     if (!strcmp(funcName, "vkInvalidateMappedMemoryRanges"))
     80         return (PFN_vkVoidFunction)vkInvalidateMappedMemoryRanges;
     81     if (!strcmp(funcName, "vkGetDeviceMemoryCommitment"))
     82         return (PFN_vkVoidFunction)vkGetDeviceMemoryCommitment;
     83     if (!strcmp(funcName, "vkGetImageSparseMemoryRequirements"))
     84         return (PFN_vkVoidFunction)vkGetImageSparseMemoryRequirements;
     85     if (!strcmp(funcName, "vkGetImageMemoryRequirements"))
     86         return (PFN_vkVoidFunction)vkGetImageMemoryRequirements;
     87     if (!strcmp(funcName, "vkGetBufferMemoryRequirements"))
     88         return (PFN_vkVoidFunction)vkGetBufferMemoryRequirements;
     89     if (!strcmp(funcName, "vkBindImageMemory"))
     90         return (PFN_vkVoidFunction)vkBindImageMemory;
     91     if (!strcmp(funcName, "vkBindBufferMemory"))
     92         return (PFN_vkVoidFunction)vkBindBufferMemory;
     93     if (!strcmp(funcName, "vkQueueBindSparse"))
     94         return (PFN_vkVoidFunction)vkQueueBindSparse;
     95     if (!strcmp(funcName, "vkCreateFence"))
     96         return (PFN_vkVoidFunction)vkCreateFence;
     97     if (!strcmp(funcName, "vkDestroyFence"))
     98         return (PFN_vkVoidFunction)vkDestroyFence;
     99     if (!strcmp(funcName, "vkGetFenceStatus"))
    100         return (PFN_vkVoidFunction)vkGetFenceStatus;
    101     if (!strcmp(funcName, "vkResetFences"))
    102         return (PFN_vkVoidFunction)vkResetFences;
    103     if (!strcmp(funcName, "vkWaitForFences"))
    104         return (PFN_vkVoidFunction)vkWaitForFences;
    105     if (!strcmp(funcName, "vkCreateSemaphore"))
    106         return (PFN_vkVoidFunction)vkCreateSemaphore;
    107     if (!strcmp(funcName, "vkDestroySemaphore"))
    108         return (PFN_vkVoidFunction)vkDestroySemaphore;
    109     if (!strcmp(funcName, "vkCreateEvent"))
    110         return (PFN_vkVoidFunction)vkCreateEvent;
    111     if (!strcmp(funcName, "vkDestroyEvent"))
    112         return (PFN_vkVoidFunction)vkDestroyEvent;
    113     if (!strcmp(funcName, "vkGetEventStatus"))
    114         return (PFN_vkVoidFunction)vkGetEventStatus;
    115     if (!strcmp(funcName, "vkSetEvent"))
    116         return (PFN_vkVoidFunction)vkSetEvent;
    117     if (!strcmp(funcName, "vkResetEvent"))
    118         return (PFN_vkVoidFunction)vkResetEvent;
    119     if (!strcmp(funcName, "vkCreateQueryPool"))
    120         return (PFN_vkVoidFunction)vkCreateQueryPool;
    121     if (!strcmp(funcName, "vkDestroyQueryPool"))
    122         return (PFN_vkVoidFunction)vkDestroyQueryPool;
    123     if (!strcmp(funcName, "vkGetQueryPoolResults"))
    124         return (PFN_vkVoidFunction)vkGetQueryPoolResults;
    125     if (!strcmp(funcName, "vkCreateBuffer"))
    126         return (PFN_vkVoidFunction)vkCreateBuffer;
    127     if (!strcmp(funcName, "vkDestroyBuffer"))
    128         return (PFN_vkVoidFunction)vkDestroyBuffer;
    129     if (!strcmp(funcName, "vkCreateBufferView"))
    130         return (PFN_vkVoidFunction)vkCreateBufferView;
    131     if (!strcmp(funcName, "vkDestroyBufferView"))
    132         return (PFN_vkVoidFunction)vkDestroyBufferView;
    133     if (!strcmp(funcName, "vkCreateImage"))
    134         return (PFN_vkVoidFunction)vkCreateImage;
    135     if (!strcmp(funcName, "vkDestroyImage"))
    136         return (PFN_vkVoidFunction)vkDestroyImage;
    137     if (!strcmp(funcName, "vkGetImageSubresourceLayout"))
    138         return (PFN_vkVoidFunction)vkGetImageSubresourceLayout;
    139     if (!strcmp(funcName, "vkCreateImageView"))
    140         return (PFN_vkVoidFunction)vkCreateImageView;
    141     if (!strcmp(funcName, "vkDestroyImageView"))
    142         return (PFN_vkVoidFunction)vkDestroyImageView;
    143     if (!strcmp(funcName, "vkCreateShaderModule"))
    144         return (PFN_vkVoidFunction)vkCreateShaderModule;
    145     if (!strcmp(funcName, "vkDestroyShaderModule"))
    146         return (PFN_vkVoidFunction)vkDestroyShaderModule;
    147     if (!strcmp(funcName, "vkCreatePipelineCache"))
    148         return (PFN_vkVoidFunction)vkCreatePipelineCache;
    149     if (!strcmp(funcName, "vkDestroyPipelineCache"))
    150         return (PFN_vkVoidFunction)vkDestroyPipelineCache;
    151     if (!strcmp(funcName, "vkGetPipelineCacheData"))
    152         return (PFN_vkVoidFunction)vkGetPipelineCacheData;
    153     if (!strcmp(funcName, "vkMergePipelineCaches"))
    154         return (PFN_vkVoidFunction)vkMergePipelineCaches;
    155     if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
    156         return (PFN_vkVoidFunction)vkCreateGraphicsPipelines;
    157     if (!strcmp(funcName, "vkCreateComputePipelines"))
    158         return (PFN_vkVoidFunction)vkCreateComputePipelines;
    159     if (!strcmp(funcName, "vkDestroyPipeline"))
    160         return (PFN_vkVoidFunction)vkDestroyPipeline;
    161     if (!strcmp(funcName, "vkCreatePipelineLayout"))
    162         return (PFN_vkVoidFunction)vkCreatePipelineLayout;
    163     if (!strcmp(funcName, "vkDestroyPipelineLayout"))
    164         return (PFN_vkVoidFunction)vkDestroyPipelineLayout;
    165     if (!strcmp(funcName, "vkCreateSampler"))
    166         return (PFN_vkVoidFunction)vkCreateSampler;
    167     if (!strcmp(funcName, "vkDestroySampler"))
    168         return (PFN_vkVoidFunction)vkDestroySampler;
    169     if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
    170         return (PFN_vkVoidFunction)vkCreateDescriptorSetLayout;
    171     if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
    172         return (PFN_vkVoidFunction)vkDestroyDescriptorSetLayout;
    173     if (!strcmp(funcName, "vkCreateDescriptorPool"))
    174         return (PFN_vkVoidFunction)vkCreateDescriptorPool;
    175     if (!strcmp(funcName, "vkDestroyDescriptorPool"))
    176         return (PFN_vkVoidFunction)vkDestroyDescriptorPool;
    177     if (!strcmp(funcName, "vkResetDescriptorPool"))
    178         return (PFN_vkVoidFunction)vkResetDescriptorPool;
    179     if (!strcmp(funcName, "vkAllocateDescriptorSets"))
    180         return (PFN_vkVoidFunction)vkAllocateDescriptorSets;
    181     if (!strcmp(funcName, "vkFreeDescriptorSets"))
    182         return (PFN_vkVoidFunction)vkFreeDescriptorSets;
    183     if (!strcmp(funcName, "vkUpdateDescriptorSets"))
    184         return (PFN_vkVoidFunction)vkUpdateDescriptorSets;
    185     if (!strcmp(funcName, "vkCreateFramebuffer"))
    186         return (PFN_vkVoidFunction)vkCreateFramebuffer;
    187     if (!strcmp(funcName, "vkDestroyFramebuffer"))
    188         return (PFN_vkVoidFunction)vkDestroyFramebuffer;
    189     if (!strcmp(funcName, "vkCreateRenderPass"))
    190         return (PFN_vkVoidFunction)vkCreateRenderPass;
    191     if (!strcmp(funcName, "vkDestroyRenderPass"))
    192         return (PFN_vkVoidFunction)vkDestroyRenderPass;
    193     if (!strcmp(funcName, "vkGetRenderAreaGranularity"))
    194         return (PFN_vkVoidFunction)vkGetRenderAreaGranularity;
    195     if (!strcmp(funcName, "vkCreateCommandPool"))
    196         return (PFN_vkVoidFunction)vkCreateCommandPool;
    197     if (!strcmp(funcName, "vkDestroyCommandPool"))
    198         return (PFN_vkVoidFunction)vkDestroyCommandPool;
    199     if (!strcmp(funcName, "vkResetCommandPool"))
    200         return (PFN_vkVoidFunction)vkResetCommandPool;
    201     if (!strcmp(funcName, "vkAllocateCommandBuffers"))
    202         return (PFN_vkVoidFunction)vkAllocateCommandBuffers;
    203     if (!strcmp(funcName, "vkFreeCommandBuffers"))
    204         return (PFN_vkVoidFunction)vkFreeCommandBuffers;
    205     if (!strcmp(funcName, "vkBeginCommandBuffer"))
    206         return (PFN_vkVoidFunction)vkBeginCommandBuffer;
    207     if (!strcmp(funcName, "vkEndCommandBuffer"))
    208         return (PFN_vkVoidFunction)vkEndCommandBuffer;
    209     if (!strcmp(funcName, "vkResetCommandBuffer"))
    210         return (PFN_vkVoidFunction)vkResetCommandBuffer;
    211     if (!strcmp(funcName, "vkCmdBindPipeline"))
    212         return (PFN_vkVoidFunction)vkCmdBindPipeline;
    213     if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
    214         return (PFN_vkVoidFunction)vkCmdBindDescriptorSets;
    215     if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
    216         return (PFN_vkVoidFunction)vkCmdBindVertexBuffers;
    217     if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
    218         return (PFN_vkVoidFunction)vkCmdBindIndexBuffer;
    219     if (!strcmp(funcName, "vkCmdSetViewport"))
    220         return (PFN_vkVoidFunction)vkCmdSetViewport;
    221     if (!strcmp(funcName, "vkCmdSetScissor"))
    222         return (PFN_vkVoidFunction)vkCmdSetScissor;
    223     if (!strcmp(funcName, "vkCmdSetLineWidth"))
    224         return (PFN_vkVoidFunction)vkCmdSetLineWidth;
    225     if (!strcmp(funcName, "vkCmdSetDepthBias"))
    226         return (PFN_vkVoidFunction)vkCmdSetDepthBias;
    227     if (!strcmp(funcName, "vkCmdSetBlendConstants"))
    228         return (PFN_vkVoidFunction)vkCmdSetBlendConstants;
    229     if (!strcmp(funcName, "vkCmdSetDepthBounds"))
    230         return (PFN_vkVoidFunction)vkCmdSetDepthBounds;
    231     if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
    232         return (PFN_vkVoidFunction)vkCmdSetStencilCompareMask;
    233     if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
    234         return (PFN_vkVoidFunction)vkCmdSetStencilWriteMask;
    235     if (!strcmp(funcName, "vkCmdSetStencilReference"))
    236         return (PFN_vkVoidFunction)vkCmdSetStencilReference;
    237     if (!strcmp(funcName, "vkCmdDraw"))
    238         return (PFN_vkVoidFunction)vkCmdDraw;
    239     if (!strcmp(funcName, "vkCmdDrawIndexed"))
    240         return (PFN_vkVoidFunction)vkCmdDrawIndexed;
    241     if (!strcmp(funcName, "vkCmdDrawIndirect"))
    242         return (PFN_vkVoidFunction)vkCmdDrawIndirect;
    243     if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
    244         return (PFN_vkVoidFunction)vkCmdDrawIndexedIndirect;
    245     if (!strcmp(funcName, "vkCmdDispatch"))
    246         return (PFN_vkVoidFunction)vkCmdDispatch;
    247     if (!strcmp(funcName, "vkCmdDispatchIndirect"))
    248         return (PFN_vkVoidFunction)vkCmdDispatchIndirect;
    249     if (!strcmp(funcName, "vkCmdCopyBuffer"))
    250         return (PFN_vkVoidFunction)vkCmdCopyBuffer;
    251     if (!strcmp(funcName, "vkCmdCopyImage"))
    252         return (PFN_vkVoidFunction)vkCmdCopyImage;
    253     if (!strcmp(funcName, "vkCmdBlitImage"))
    254         return (PFN_vkVoidFunction)vkCmdBlitImage;
    255     if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
    256         return (PFN_vkVoidFunction)vkCmdCopyBufferToImage;
    257     if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
    258         return (PFN_vkVoidFunction)vkCmdCopyImageToBuffer;
    259     if (!strcmp(funcName, "vkCmdUpdateBuffer"))
    260         return (PFN_vkVoidFunction)vkCmdUpdateBuffer;
    261     if (!strcmp(funcName, "vkCmdFillBuffer"))
    262         return (PFN_vkVoidFunction)vkCmdFillBuffer;
    263     if (!strcmp(funcName, "vkCmdClearColorImage"))
    264         return (PFN_vkVoidFunction)vkCmdClearColorImage;
    265     if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
    266         return (PFN_vkVoidFunction)vkCmdClearDepthStencilImage;
    267     if (!strcmp(funcName, "vkCmdClearAttachments"))
    268         return (PFN_vkVoidFunction)vkCmdClearAttachments;
    269     if (!strcmp(funcName, "vkCmdResolveImage"))
    270         return (PFN_vkVoidFunction)vkCmdResolveImage;
    271     if (!strcmp(funcName, "vkCmdSetEvent"))
    272         return (PFN_vkVoidFunction)vkCmdSetEvent;
    273     if (!strcmp(funcName, "vkCmdResetEvent"))
    274         return (PFN_vkVoidFunction)vkCmdResetEvent;
    275     if (!strcmp(funcName, "vkCmdWaitEvents"))
    276         return (PFN_vkVoidFunction)vkCmdWaitEvents;
    277     if (!strcmp(funcName, "vkCmdPipelineBarrier"))
    278         return (PFN_vkVoidFunction)vkCmdPipelineBarrier;
    279     if (!strcmp(funcName, "vkCmdBeginQuery"))
    280         return (PFN_vkVoidFunction)vkCmdBeginQuery;
    281     if (!strcmp(funcName, "vkCmdEndQuery"))
    282         return (PFN_vkVoidFunction)vkCmdEndQuery;
    283     if (!strcmp(funcName, "vkCmdResetQueryPool"))
    284         return (PFN_vkVoidFunction)vkCmdResetQueryPool;
    285     if (!strcmp(funcName, "vkCmdWriteTimestamp"))
    286         return (PFN_vkVoidFunction)vkCmdWriteTimestamp;
    287     if (!strcmp(funcName, "vkCmdCopyQueryPoolResults"))
    288         return (PFN_vkVoidFunction)vkCmdCopyQueryPoolResults;
    289     if (!strcmp(funcName, "vkCmdPushConstants"))
    290         return (PFN_vkVoidFunction)vkCmdPushConstants;
    291     if (!strcmp(funcName, "vkCmdBeginRenderPass"))
    292         return (PFN_vkVoidFunction)vkCmdBeginRenderPass;
    293     if (!strcmp(funcName, "vkCmdNextSubpass"))
    294         return (PFN_vkVoidFunction)vkCmdNextSubpass;
    295     if (!strcmp(funcName, "vkCmdEndRenderPass"))
    296         return (PFN_vkVoidFunction)vkCmdEndRenderPass;
    297     if (!strcmp(funcName, "vkCmdExecuteCommands"))
    298         return (PFN_vkVoidFunction)vkCmdExecuteCommands;
    299 
    300     // Instance extensions
    301     void *addr;
    302     if (debug_report_instance_gpa(inst, funcName, &addr))
    303         return addr;
    304 
    305     if (wsi_swapchain_instance_gpa(inst, funcName, &addr))
    306         return addr;
    307 
    308     if (extension_instance_gpa(inst, funcName, &addr))
    309         return addr;
    310 
    311     addr = loader_dev_ext_gpa(inst, funcName);
    312     return addr;
    313 }
    314 
    315 static inline void *globalGetProcAddr(const char *name) {
    316     if (!name || name[0] != 'v' || name[1] != 'k')
    317         return NULL;
    318 
    319     name += 2;
    320     if (!strcmp(name, "CreateInstance"))
    321         return (void *)vkCreateInstance;
    322     if (!strcmp(name, "EnumerateInstanceExtensionProperties"))
    323         return (void *)vkEnumerateInstanceExtensionProperties;
    324     if (!strcmp(name, "EnumerateInstanceLayerProperties"))
    325         return (void *)vkEnumerateInstanceLayerProperties;
    326 
    327     return NULL;
    328 }
    329 
    330 /* These functions require special handling by the loader.
    331 *  They are not just generic trampoline code entrypoints.
    332 *  Thus GPA must return loader entrypoint for these instead of first function
    333 *  in the chain. */
    334 static inline void *loader_non_passthrough_gipa(const char *name) {
    335     if (!name || name[0] != 'v' || name[1] != 'k')
    336         return NULL;
    337 
    338     name += 2;
    339     if (!strcmp(name, "CreateInstance"))
    340         return (void *)vkCreateInstance;
    341     if (!strcmp(name, "DestroyInstance"))
    342         return (void *)vkDestroyInstance;
    343     if (!strcmp(name, "GetDeviceProcAddr"))
    344         return (void *)vkGetDeviceProcAddr;
    345     // remove once no longer locks
    346     if (!strcmp(name, "EnumeratePhysicalDevices"))
    347         return (void *)vkEnumeratePhysicalDevices;
    348     if (!strcmp(name, "EnumerateDeviceExtensionProperties"))
    349         return (void *)vkEnumerateDeviceExtensionProperties;
    350     if (!strcmp(name, "EnumerateDeviceLayerProperties"))
    351         return (void *)vkEnumerateDeviceLayerProperties;
    352     if (!strcmp(name, "GetInstanceProcAddr"))
    353         return (void *)vkGetInstanceProcAddr;
    354     if (!strcmp(name, "CreateDevice"))
    355         return (void *)vkCreateDevice;
    356 
    357     return NULL;
    358 }
    359 
    360 static inline void *loader_non_passthrough_gdpa(const char *name) {
    361     if (!name || name[0] != 'v' || name[1] != 'k')
    362         return NULL;
    363 
    364     name += 2;
    365 
    366     if (!strcmp(name, "GetDeviceProcAddr"))
    367         return (void *)vkGetDeviceProcAddr;
    368     if (!strcmp(name, "DestroyDevice"))
    369         return (void *)vkDestroyDevice;
    370     if (!strcmp(name, "GetDeviceQueue"))
    371         return (void *)vkGetDeviceQueue;
    372     if (!strcmp(name, "AllocateCommandBuffers"))
    373         return (void *)vkAllocateCommandBuffers;
    374 
    375     return NULL;
    376 }
    377