// Copyright 2018 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INCLUDE_DAWN_NATIVE_VULKANBACKEND_H_ #define INCLUDE_DAWN_NATIVE_VULKANBACKEND_H_ #include <vulkan/vulkan.h> #include <array> #include <vector> #include "dawn/native/DawnNative.h" namespace dawn::native::vulkan { DAWN_NATIVE_EXPORT VkInstance GetInstance(WGPUDevice device); DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetInstanceProcAddr(WGPUDevice device, const char* pName); enum class NeedsDedicatedAllocation { … }; struct DAWN_NATIVE_EXPORT ExternalImageDescriptorVk : ExternalImageDescriptor { … }; struct ExternalImageExportInfoVk : ExternalImageExportInfo { … }; // Can't use DAWN_PLATFORM_IS(LINUX) since header included in both Dawn and Chrome #if defined(__linux__) || defined(__Fuchsia__) // Common properties of external images represented by FDs. On successful import the file // descriptor's ownership is transferred to the Dawn implementation and they shouldn't be // used outside of Dawn again. TODO(enga): Also transfer ownership in the error case so the // caller can assume the FD is always consumed. struct DAWN_NATIVE_EXPORT ExternalImageDescriptorFD : ExternalImageDescriptorVk { … }; // Descriptor for opaque file descriptor image import struct DAWN_NATIVE_EXPORT ExternalImageDescriptorOpaqueFD : ExternalImageDescriptorFD { … }; // The plane-wise offset and stride. struct DAWN_NATIVE_EXPORT PlaneLayout { … }; // Descriptor for dma-buf file descriptor image import struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDmaBuf : ExternalImageDescriptorFD { … }; // Info struct that is written to in |ExportVulkanImage|. struct DAWN_NATIVE_EXPORT ExternalImageExportInfoFD : ExternalImageExportInfoVk { … }; struct DAWN_NATIVE_EXPORT ExternalImageExportInfoOpaqueFD : ExternalImageExportInfoFD { … }; struct DAWN_NATIVE_EXPORT ExternalImageExportInfoDmaBuf : ExternalImageExportInfoFD { … }; #ifdef __ANDROID__ // Descriptor for AHardwareBuffer image import struct DAWN_NATIVE_EXPORT ExternalImageDescriptorAHardwareBuffer : ExternalImageDescriptorVk { public: ExternalImageDescriptorAHardwareBuffer(); struct AHardwareBuffer* handle; // The AHardwareBuffer which contains the memory of the image std::vector<int> waitFDs; // File descriptors of semaphores which will be waited on protected: using ExternalImageDescriptorVk::ExternalImageDescriptorVk; }; struct DAWN_NATIVE_EXPORT ExternalImageExportInfoAHardwareBuffer : ExternalImageExportInfoFD { ExternalImageExportInfoAHardwareBuffer(); }; #endif // __ANDROID__ #endif // defined(__linux__) || defined(__Fuchsia__) // Imports external memory into a Vulkan image. Internally, this uses external memory / // semaphore extensions to import the image and wait on the provided synchronizaton // primitives before the texture can be used. // On failure, returns a nullptr. DAWN_NATIVE_EXPORT WGPUTexture WrapVulkanImage(WGPUDevice device, const ExternalImageDescriptorVk* descriptor); // Exports external memory from a Vulkan image. This must be called on wrapped textures // before they are destroyed. It writes the semaphore to wait on and the old/new image // layouts to |info|. Pass VK_IMAGE_LAYOUT_UNDEFINED as |desiredLayout| if you don't want to // perform a layout transition. DAWN_NATIVE_EXPORT bool ExportVulkanImage(WGPUTexture texture, VkImageLayout desiredLayout, ExternalImageExportInfoVk* info); // |ExportVulkanImage| with default desiredLayout of VK_IMAGE_LAYOUT_UNDEFINED. DAWN_NATIVE_EXPORT bool ExportVulkanImage(WGPUTexture texture, ExternalImageExportInfoVk* info); } // namespace dawn::native::vulkan #endif // INCLUDE_DAWN_NATIVE_VULKANBACKEND_H_