dawn-cmake/src/dawn_native/vulkan/VulkanFunctions.cpp
David 'Digit' Turner b749d07ac9 Enable Vulkan for Chromium Fuchsia build.
Enable the Vulkan backend when building Dawn with
the Chromium build system for Fuchsia. To make this
work properly the following is required:

- Modify VulkanInfo.cpp and BackendVk.cpp to correctly probe
  the Fuchsia swapchain layer and its layer extension, as well
  as enabling them when creating a new VkInstance.

- Modify VulkanFunctions.cpp to load the Fuchsia swapchain
  related extension for this platform only.

- Provide a small mock GLFW library for Fuchsia under
  src/utils/Glfw3Fuchsia.cpp, since the upstream project
  does not support this platform at all. Its purpose is
  only to allow the creation of the right VulkanBinding
  instance, which depends on the creation of a display
  surface for latter swapchain creation.

- Add //third_party/fuchsia-sdk:vulkan_base and
  //third_party/fuchsia-sdk:vulkan_validation as
  data_deps of the libdawn_native_sources target in
  order to ensure that the Fuchsia package created by
  the build system will include the correct Vulkan
  libraries (loader and validation layers).

This builds correctly, and both dawn_unittests and
dawn_end2end_tests will run on a real Fuchsia device
or inside the Fuchsia emulator, using either GPU
virtualization or a software-based renderer.

Note: dawn_unittests will also run inside QEMU, but
not dawn_end2end_tests, since the latter requires
proper GPU emulation which is not available in this
environment.

NOTE: All end2end tests pass using a device with
      an "Intel HD Graphics 615 (Kaby Lake GT2)"
      adapter. However:

       - For some reason, a single test takes up
         to 129 seconds to pass
	 (BufferSetSubDataTests.ManySetSubData/Vulkan).

       - The test process crashes inside VkDestroyInstance(),
         apparently inside the Fuchsia-specific imagepipe
	 layer (which implements swapchain support).
	 This is likely a bug in the layer itself, and
	 not Dawn.

    Also, may end2end tests will crash when run inside
    the Fuchsia emulator (which uses GPU virtualization
    to talk to the host GPU). The crashes happen inside
    libvulkan-goldfish.so, the emulator-specific Vulkan
    ICD on this sytem. Not a Dawn bug either.

Bug=dawn:221
Change-Id: Id3598b673e8c6393f24db728b8da49fdde3cac76
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8963
Commit-Queue: David Turner <digit@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
2019-09-09 10:52:08 +00:00

271 lines
12 KiB
C++

// Copyright 2017 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn_native/vulkan/VulkanFunctions.h"
#include "common/DynamicLib.h"
#include "dawn_native/vulkan/VulkanInfo.h"
namespace dawn_native { namespace vulkan {
#define GET_GLOBAL_PROC(name) \
name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(nullptr, "vk" #name)); \
if (name == nullptr) { \
return DAWN_DEVICE_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \
}
MaybeError VulkanFunctions::LoadGlobalProcs(const DynamicLib& vulkanLib) {
if (!vulkanLib.GetProc(&GetInstanceProcAddr, "vkGetInstanceProcAddr")) {
return DAWN_DEVICE_LOST_ERROR("Couldn't get vkGetInstanceProcAddr");
}
GET_GLOBAL_PROC(CreateInstance);
GET_GLOBAL_PROC(EnumerateInstanceExtensionProperties);
GET_GLOBAL_PROC(EnumerateInstanceLayerProperties);
// Is not available in Vulkan 1.0, so allow nullptr
EnumerateInstanceVersion = reinterpret_cast<decltype(EnumerateInstanceVersion)>(
GetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion"));
return {};
}
#define GET_INSTANCE_PROC(name) \
name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #name)); \
if (name == nullptr) { \
return DAWN_DEVICE_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \
}
MaybeError VulkanFunctions::LoadInstanceProcs(VkInstance instance,
const VulkanGlobalInfo& globalInfo) {
// Load this proc first so that we can destroy the instance even if some other
// GET_INSTANCE_PROC fails
GET_INSTANCE_PROC(DestroyInstance);
GET_INSTANCE_PROC(CreateDevice);
GET_INSTANCE_PROC(DestroyDevice);
GET_INSTANCE_PROC(EnumerateDeviceExtensionProperties);
GET_INSTANCE_PROC(EnumerateDeviceLayerProperties);
GET_INSTANCE_PROC(EnumeratePhysicalDevices);
GET_INSTANCE_PROC(GetDeviceProcAddr);
GET_INSTANCE_PROC(GetPhysicalDeviceFeatures);
GET_INSTANCE_PROC(GetPhysicalDeviceFormatProperties);
GET_INSTANCE_PROC(GetPhysicalDeviceImageFormatProperties);
GET_INSTANCE_PROC(GetPhysicalDeviceMemoryProperties);
GET_INSTANCE_PROC(GetPhysicalDeviceProperties);
GET_INSTANCE_PROC(GetPhysicalDeviceQueueFamilyProperties);
GET_INSTANCE_PROC(GetPhysicalDeviceSparseImageFormatProperties);
if (globalInfo.debugReport) {
GET_INSTANCE_PROC(CreateDebugReportCallbackEXT);
GET_INSTANCE_PROC(DebugReportMessageEXT);
GET_INSTANCE_PROC(DestroyDebugReportCallbackEXT);
}
// Vulkan 1.1 is not required to report promoted extensions from 1.0
if (globalInfo.externalMemoryCapabilities ||
globalInfo.apiVersion >= VK_MAKE_VERSION(1, 1, 0)) {
GET_INSTANCE_PROC(GetPhysicalDeviceExternalBufferPropertiesKHR);
}
if (globalInfo.externalSemaphoreCapabilities ||
globalInfo.apiVersion >= VK_MAKE_VERSION(1, 1, 0)) {
GET_INSTANCE_PROC(GetPhysicalDeviceExternalSemaphorePropertiesKHR);
}
if (globalInfo.getPhysicalDeviceProperties2 ||
globalInfo.apiVersion >= VK_MAKE_VERSION(1, 1, 0)) {
GET_INSTANCE_PROC(GetPhysicalDeviceFeatures2KHR);
GET_INSTANCE_PROC(GetPhysicalDeviceProperties2KHR);
GET_INSTANCE_PROC(GetPhysicalDeviceFormatProperties2KHR);
GET_INSTANCE_PROC(GetPhysicalDeviceImageFormatProperties2KHR);
GET_INSTANCE_PROC(GetPhysicalDeviceQueueFamilyProperties2KHR);
GET_INSTANCE_PROC(GetPhysicalDeviceMemoryProperties2KHR);
GET_INSTANCE_PROC(GetPhysicalDeviceSparseImageFormatProperties2KHR);
}
if (globalInfo.surface) {
GET_INSTANCE_PROC(DestroySurfaceKHR);
GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceSupportKHR);
GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
GET_INSTANCE_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
}
#ifdef VK_USE_PLATFORM_FUCHSIA
if (globalInfo.fuchsiaImagePipeSurface) {
GET_INSTANCE_PROC(CreateImagePipeSurfaceFUCHSIA);
}
#endif
return {};
}
#define GET_DEVICE_PROC(name) \
name = reinterpret_cast<decltype(name)>(GetDeviceProcAddr(device, "vk" #name)); \
if (name == nullptr) { \
return DAWN_DEVICE_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \
}
MaybeError VulkanFunctions::LoadDeviceProcs(VkDevice device,
const VulkanDeviceKnobs& usedKnobs) {
GET_DEVICE_PROC(AllocateCommandBuffers);
GET_DEVICE_PROC(AllocateDescriptorSets);
GET_DEVICE_PROC(AllocateMemory);
GET_DEVICE_PROC(BeginCommandBuffer);
GET_DEVICE_PROC(BindBufferMemory);
GET_DEVICE_PROC(BindImageMemory);
GET_DEVICE_PROC(CmdBeginQuery);
GET_DEVICE_PROC(CmdBeginRenderPass);
GET_DEVICE_PROC(CmdBindDescriptorSets);
GET_DEVICE_PROC(CmdBindIndexBuffer);
GET_DEVICE_PROC(CmdBindPipeline);
GET_DEVICE_PROC(CmdBindVertexBuffers);
GET_DEVICE_PROC(CmdBlitImage);
GET_DEVICE_PROC(CmdClearAttachments);
GET_DEVICE_PROC(CmdClearColorImage);
GET_DEVICE_PROC(CmdClearDepthStencilImage);
GET_DEVICE_PROC(CmdCopyBuffer);
GET_DEVICE_PROC(CmdCopyBufferToImage);
GET_DEVICE_PROC(CmdCopyImage);
GET_DEVICE_PROC(CmdCopyImageToBuffer);
GET_DEVICE_PROC(CmdCopyQueryPoolResults);
GET_DEVICE_PROC(CmdDispatch);
GET_DEVICE_PROC(CmdDispatchIndirect);
GET_DEVICE_PROC(CmdDraw);
GET_DEVICE_PROC(CmdDrawIndexed);
GET_DEVICE_PROC(CmdDrawIndexedIndirect);
GET_DEVICE_PROC(CmdDrawIndirect);
GET_DEVICE_PROC(CmdEndQuery);
GET_DEVICE_PROC(CmdEndRenderPass);
GET_DEVICE_PROC(CmdExecuteCommands);
GET_DEVICE_PROC(CmdFillBuffer);
GET_DEVICE_PROC(CmdNextSubpass);
GET_DEVICE_PROC(CmdPipelineBarrier);
GET_DEVICE_PROC(CmdPushConstants);
GET_DEVICE_PROC(CmdResetEvent);
GET_DEVICE_PROC(CmdResetQueryPool);
GET_DEVICE_PROC(CmdResolveImage);
GET_DEVICE_PROC(CmdSetBlendConstants);
GET_DEVICE_PROC(CmdSetDepthBias);
GET_DEVICE_PROC(CmdSetDepthBounds);
GET_DEVICE_PROC(CmdSetEvent);
GET_DEVICE_PROC(CmdSetLineWidth);
GET_DEVICE_PROC(CmdSetScissor);
GET_DEVICE_PROC(CmdSetStencilCompareMask);
GET_DEVICE_PROC(CmdSetStencilReference);
GET_DEVICE_PROC(CmdSetStencilWriteMask);
GET_DEVICE_PROC(CmdSetViewport);
GET_DEVICE_PROC(CmdUpdateBuffer);
GET_DEVICE_PROC(CmdWaitEvents);
GET_DEVICE_PROC(CmdWriteTimestamp);
GET_DEVICE_PROC(CreateBuffer);
GET_DEVICE_PROC(CreateBufferView);
GET_DEVICE_PROC(CreateCommandPool);
GET_DEVICE_PROC(CreateComputePipelines);
GET_DEVICE_PROC(CreateDescriptorPool);
GET_DEVICE_PROC(CreateDescriptorSetLayout);
GET_DEVICE_PROC(CreateEvent);
GET_DEVICE_PROC(CreateFence);
GET_DEVICE_PROC(CreateFramebuffer);
GET_DEVICE_PROC(CreateGraphicsPipelines);
GET_DEVICE_PROC(CreateImage);
GET_DEVICE_PROC(CreateImageView);
GET_DEVICE_PROC(CreatePipelineCache);
GET_DEVICE_PROC(CreatePipelineLayout);
GET_DEVICE_PROC(CreateQueryPool);
GET_DEVICE_PROC(CreateRenderPass);
GET_DEVICE_PROC(CreateSampler);
GET_DEVICE_PROC(CreateSemaphore);
GET_DEVICE_PROC(CreateShaderModule);
GET_DEVICE_PROC(DestroyBuffer);
GET_DEVICE_PROC(DestroyBufferView);
GET_DEVICE_PROC(DestroyCommandPool);
GET_DEVICE_PROC(DestroyDescriptorPool);
GET_DEVICE_PROC(DestroyDescriptorSetLayout);
GET_DEVICE_PROC(DestroyEvent);
GET_DEVICE_PROC(DestroyFence);
GET_DEVICE_PROC(DestroyFramebuffer);
GET_DEVICE_PROC(DestroyImage);
GET_DEVICE_PROC(DestroyImageView);
GET_DEVICE_PROC(DestroyPipeline);
GET_DEVICE_PROC(DestroyPipelineCache);
GET_DEVICE_PROC(DestroyPipelineLayout);
GET_DEVICE_PROC(DestroyQueryPool);
GET_DEVICE_PROC(DestroyRenderPass);
GET_DEVICE_PROC(DestroySampler);
GET_DEVICE_PROC(DestroySemaphore);
GET_DEVICE_PROC(DestroyShaderModule);
GET_DEVICE_PROC(DeviceWaitIdle);
GET_DEVICE_PROC(EndCommandBuffer);
GET_DEVICE_PROC(FlushMappedMemoryRanges);
GET_DEVICE_PROC(FreeCommandBuffers);
GET_DEVICE_PROC(FreeDescriptorSets);
GET_DEVICE_PROC(FreeMemory);
GET_DEVICE_PROC(GetBufferMemoryRequirements);
GET_DEVICE_PROC(GetDeviceMemoryCommitment);
GET_DEVICE_PROC(GetDeviceQueue);
GET_DEVICE_PROC(GetEventStatus);
GET_DEVICE_PROC(GetFenceStatus);
GET_DEVICE_PROC(GetImageMemoryRequirements);
GET_DEVICE_PROC(GetImageSparseMemoryRequirements);
GET_DEVICE_PROC(GetImageSubresourceLayout);
GET_DEVICE_PROC(GetPipelineCacheData);
GET_DEVICE_PROC(GetQueryPoolResults);
GET_DEVICE_PROC(GetRenderAreaGranularity);
GET_DEVICE_PROC(InvalidateMappedMemoryRanges);
GET_DEVICE_PROC(MapMemory);
GET_DEVICE_PROC(MergePipelineCaches);
GET_DEVICE_PROC(QueueBindSparse);
GET_DEVICE_PROC(QueueSubmit);
GET_DEVICE_PROC(QueueWaitIdle);
GET_DEVICE_PROC(ResetCommandBuffer);
GET_DEVICE_PROC(ResetCommandPool);
GET_DEVICE_PROC(ResetDescriptorPool);
GET_DEVICE_PROC(ResetEvent);
GET_DEVICE_PROC(ResetFences);
GET_DEVICE_PROC(SetEvent);
GET_DEVICE_PROC(UnmapMemory);
GET_DEVICE_PROC(UpdateDescriptorSets);
GET_DEVICE_PROC(WaitForFences);
if (usedKnobs.debugMarker) {
GET_DEVICE_PROC(CmdDebugMarkerBeginEXT);
GET_DEVICE_PROC(CmdDebugMarkerEndEXT);
GET_DEVICE_PROC(CmdDebugMarkerInsertEXT);
}
if (usedKnobs.externalMemoryFD) {
GET_DEVICE_PROC(GetMemoryFdKHR);
GET_DEVICE_PROC(GetMemoryFdPropertiesKHR);
}
if (usedKnobs.externalSemaphoreFD) {
GET_DEVICE_PROC(ImportSemaphoreFdKHR);
GET_DEVICE_PROC(GetSemaphoreFdKHR);
}
if (usedKnobs.swapchain) {
GET_DEVICE_PROC(CreateSwapchainKHR);
GET_DEVICE_PROC(DestroySwapchainKHR);
GET_DEVICE_PROC(GetSwapchainImagesKHR);
GET_DEVICE_PROC(AcquireNextImageKHR);
GET_DEVICE_PROC(QueuePresentKHR);
}
return {};
}
}} // namespace dawn_native::vulkan