diff options
-rw-r--r-- | vulkan/api/vulkan.api | 19 | ||||
-rw-r--r-- | vulkan/doc/implementors_guide/implementors_guide.adoc | 37 | ||||
-rw-r--r-- | vulkan/doc/implementors_guide/implementors_guide.html | 53 | ||||
-rw-r--r-- | vulkan/include/vulkan/vk_android_native_buffer.h | 38 | ||||
-rw-r--r-- | vulkan/libvulkan/code-generator.tmpl | 28 | ||||
-rw-r--r-- | vulkan/libvulkan/driver.cpp | 22 | ||||
-rw-r--r-- | vulkan/libvulkan/driver.h | 1 | ||||
-rw-r--r-- | vulkan/libvulkan/driver_gen.cpp | 3 | ||||
-rw-r--r-- | vulkan/libvulkan/driver_gen.h | 1 | ||||
-rw-r--r-- | vulkan/libvulkan/swapchain.cpp | 36 | ||||
-rw-r--r-- | vulkan/nulldrv/null_driver.cpp | 6 | ||||
-rw-r--r-- | vulkan/nulldrv/null_driver_gen.h | 4 |
12 files changed, 164 insertions, 84 deletions
diff --git a/vulkan/api/vulkan.api b/vulkan/api/vulkan.api index 5a67d36430..a89fed93cd 100644 --- a/vulkan/api/vulkan.api +++ b/vulkan/api/vulkan.api @@ -2908,14 +2908,20 @@ class VkWin32SurfaceCreateInfoKHR { platform.HWND hwnd } +@internal class Gralloc1Usage { + u64 consumer + u64 producer +} + @extension("VK_ANDROID_native_buffer") class VkNativeBufferANDROID { VkStructureType sType const void* pNext platform.buffer_handle_t handle - int stride - int format - int usage + s32 stride + s32 format + s32 usage + Gralloc1Usage usage2 } @extension("VK_ANDROID_native_buffer") @@ -5833,21 +5839,24 @@ cmd VkResult vkGetPhysicalDeviceWin32PresentationSupportKHR( } @extension("VK_ANDROID_native_buffer") +@optional cmd VkResult vkGetSwapchainGrallocUsageANDROID( VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, - int* grallocUsage) { + s32* grallocUsage) { return ? } @extension("VK_ANDROID_native_buffer") +@optional cmd VkResult vkGetSwapchainGrallocUsage2ANDROID( VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, - int* grallocUsage) { + u64* grallocConsumerUsage, + u64* grallocProducerUsage) { return ? } diff --git a/vulkan/doc/implementors_guide/implementors_guide.adoc b/vulkan/doc/implementors_guide/implementors_guide.adoc index 009472a510..24af950f6a 100644 --- a/vulkan/doc/implementors_guide/implementors_guide.adoc +++ b/vulkan/doc/implementors_guide/implementors_guide.adoc @@ -47,19 +47,7 @@ Our goal is to allow layers to be ported with only build-environment changes bet The +vk_wsi_swapchin+ and +vk_wsi_device_swapchain+ extensions are primarily be implemented by the platform and live in +libvulkan.so+. The +VkSwapchain+ object and all interaction with +ANativeWindow+ will be handled by the platform and not exposed to drivers. The WSI implementation will rely on a few private interfaces to the driver for this implementation. These will be loaded through the driver's +vkGetDeviceProcAddr+ functions, after passing through any enabled layers. -Implementations may need swapchain buffers to be allocated with implementation-defined private gralloc usage flags. When creating a swapchain, the platform will ask the driver to translate the requested format and image usage flags into gralloc usage flags by calling -[source,c] ----- -VkResult VKAPI vkGetSwapchainGrallocUsageANDROID( - VkDevice device, - VkFormat format, - VkImageUsageFlags imageUsage, - int* grallocUsage -); ----- -The +format+ and +imageUsage+ parameters are taken from the +VkSwapchainCreateInfoKHR+ structure. The driver should fill +*grallocUsage+ with the gralloc usage flags it requires for that format and usage. These will be combined with the usage flags requested by the swapchain consumer when allocating buffers. - -Implementations may further need swapchain buffers to be allocated with implementation-defined private gralloc usage flags that depend not only on +format+ and +imageUsage+, but also on the intended usage of the swapchain. The additional usage bits are defined as +Implementations may need swapchain buffers to be allocated with implementation-defined private gralloc usage flags that depend not only on +format+ and +imageUsage+, but also on the intended usage of the swapchain. The swapchain usage bits are defined as [source,c] ---- typedef enum VkSwapchainImageUsageFlagBitsANDROID { @@ -69,7 +57,7 @@ typedef enum VkSwapchainImageUsageFlagBitsANDROID { typedef VkFlags VkSwapchainImageUsageFlagsANDROID; ---- -If the driver provides the +vkGetSwapchainGrallocUsage2ANDROID+ function, the platform will use it in preference to +vkGetSwapchainGrallocUsageANDROID+ when translating a requested format, image usage flags, and swapchain image usage flags into gralloc usage flags. +vkGetSwapchainGrallocUsage2ANDROID+ behaves in the same way as +vkGetSwapchainGrallocUsageANDROID+, and is declared as +Implementations may need swapchain buffers to be allocated with implementation-defined private gralloc usage flags. When creating a swapchain, the platform will ask the driver to translate the requested format and image usage flags into gralloc usage flags by calling [source,c] ---- VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID( @@ -77,6 +65,19 @@ VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID( VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, + uint64_t* grallocConsumerUsage, + uint64_t* grallocProducerUsage, +); +---- +The +format+ and +imageUsage+ parameters are taken from the +VkSwapchainCreateInfoKHR+ structure. The driver should fill +*grallocConsumerUsage+ and +*grallocProducerUsage+ with the gralloc usage flags it requires for that format and usage. These will be combined with the usage flags requested by the swapchain consumer when allocating buffers. + +An older version of this function is deprecated but still supported for backwards compatibility; it will be used if +vkGetSwapchainGrallocUsage2ANDROID+ is not supported: +[source,c] +---- +VkResult VKAPI vkGetSwapchainGrallocUsageANDROID( + VkDevice device, + VkFormat format, + VkImageUsageFlags imageUsage, int* grallocUsage ); ---- @@ -95,7 +96,11 @@ typedef struct { // Gralloc format and usage requested when the buffer was allocated. int format; - int usage; + int usage; // deprecated + struct { + uint64_t consumer; + uint64_t producer; + } usage2; } VkNativeBufferANDROID; ---- @@ -200,3 +205,5 @@ If +image+ was created with +VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID+, then * Added VkSwapchainImageUsageFlagBitsANDROID * Added vkGetSwapchainGrallocUsage2ANDROID * Added VkSwapchainImageCreateInfoANDROID +. *2017-02-09* + * Extended vkGetSwapchainGrallocUsage2ANDROID and VkNativeBufferANDROID to use gralloc1-style usage bitfields.
\ No newline at end of file diff --git a/vulkan/doc/implementors_guide/implementors_guide.html b/vulkan/doc/implementors_guide/implementors_guide.html index 4e74a7854d..9fecce5efa 100644 --- a/vulkan/doc/implementors_guide/implementors_guide.html +++ b/vulkan/doc/implementors_guide/implementors_guide.html @@ -730,7 +730,7 @@ asciidoc.install(2); /*]]>*/ </script> </head> -<body class="article"> +<body class="book"> <div id="header"> <h1>Vulkan on Android Implementor’s Guide</h1> <span id="revnumber">version 5</span> @@ -793,20 +793,7 @@ Injected layers, like framerate, social network, or game launcher overlays, whic <h2 id="_window_system_integration">2. Window System Integration</h2> <div class="sectionbody"> <div class="paragraph"><p>The <span class="monospaced">vk_wsi_swapchin</span> and <span class="monospaced">vk_wsi_device_swapchain</span> extensions are primarily be implemented by the platform and live in <span class="monospaced">libvulkan.so</span>. The <span class="monospaced">VkSwapchain</span> object and all interaction with <span class="monospaced">ANativeWindow</span> will be handled by the platform and not exposed to drivers. The WSI implementation will rely on a few private interfaces to the driver for this implementation. These will be loaded through the driver’s <span class="monospaced">vkGetDeviceProcAddr</span> functions, after passing through any enabled layers.</p></div> -<div class="paragraph"><p>Implementations may need swapchain buffers to be allocated with implementation-defined private gralloc usage flags. When creating a swapchain, the platform will ask the driver to translate the requested format and image usage flags into gralloc usage flags by calling</p></div> -<div class="listingblock"> -<div class="content"><!-- Generator: GNU source-highlight 3.1.6 -by Lorenzo Bettini -http://www.lorenzobettini.it -http://www.gnu.org/software/src-highlite --> -<pre><tt>VkResult <span style="color: #008080">VKAPI</span> <span style="font-weight: bold"><span style="color: #000000">vkGetSwapchainGrallocUsageANDROID</span></span><span style="color: #990000">(</span> - <span style="color: #008080">VkDevice</span> device<span style="color: #990000">,</span> - <span style="color: #008080">VkFormat</span> format<span style="color: #990000">,</span> - <span style="color: #008080">VkImageUsageFlags</span> imageUsage<span style="color: #990000">,</span> - <span style="color: #009900">int</span><span style="color: #990000">*</span> grallocUsage -<span style="color: #990000">);</span></tt></pre></div></div> -<div class="paragraph"><p>The <span class="monospaced">format</span> and <span class="monospaced">imageUsage</span> parameters are taken from the <span class="monospaced">VkSwapchainCreateInfoKHR</span> structure. The driver should fill <span class="monospaced">*grallocUsage</span> with the gralloc usage flags it requires for that format and usage. These will be combined with the usage flags requested by the swapchain consumer when allocating buffers.</p></div> -<div class="paragraph"><p>Implementations may further need swapchain buffers to be allocated with implementation-defined private gralloc usage flags that depend not only on <span class="monospaced">format</span> and <span class="monospaced">imageUsage</span>, but also on the intended usage of the swapchain. The additional usage bits are defined as</p></div> +<div class="paragraph"><p>Implementations may need swapchain buffers to be allocated with implementation-defined private gralloc usage flags that depend not only on <span class="monospaced">format</span> and <span class="monospaced">imageUsage</span>, but also on the intended usage of the swapchain. The swapchain usage bits are defined as</p></div> <div class="listingblock"> <div class="content"><!-- Generator: GNU source-highlight 3.1.6 by Lorenzo Bettini @@ -817,7 +804,7 @@ http://www.gnu.org/software/src-highlite --> VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM <span style="color: #990000">=</span> <span style="color: #993399">0x7FFFFFFF</span> <span style="color: #FF0000">}</span> VkSwapchainImageUsageFlagBitsANDROID<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">typedef</span></span> <span style="color: #008080">VkFlags</span> VkSwapchainImageUsageFlagsANDROID<span style="color: #990000">;</span></tt></pre></div></div> -<div class="paragraph"><p>If the driver provides the <span class="monospaced">vkGetSwapchainGrallocUsage2ANDROID</span> function, the platform will use it in preference to <span class="monospaced">vkGetSwapchainGrallocUsageANDROID</span> when translating a requested format, image usage flags, and swapchain image usage flags into gralloc usage flags. <span class="monospaced">vkGetSwapchainGrallocUsage2ANDROID</span> behaves in the same way as <span class="monospaced">vkGetSwapchainGrallocUsageANDROID</span>, and is declared as</p></div> +<div class="paragraph"><p>Implementations may need swapchain buffers to be allocated with implementation-defined private gralloc usage flags. When creating a swapchain, the platform will ask the driver to translate the requested format and image usage flags into gralloc usage flags by calling</p></div> <div class="listingblock"> <div class="content"><!-- Generator: GNU source-highlight 3.1.6 by Lorenzo Bettini @@ -828,6 +815,20 @@ http://www.gnu.org/software/src-highlite --> <span style="color: #008080">VkFormat</span> format<span style="color: #990000">,</span> <span style="color: #008080">VkImageUsageFlags</span> imageUsage<span style="color: #990000">,</span> <span style="color: #008080">VkSwapchainImageUsageFlagsANDROID</span> swapchainImageUsage<span style="color: #990000">,</span> + uint64_t<span style="color: #990000">*</span> grallocConsumerUsage<span style="color: #990000">,</span> + uint64_t<span style="color: #990000">*</span> grallocProducerUsage<span style="color: #990000">,</span> +<span style="color: #990000">);</span></tt></pre></div></div> +<div class="paragraph"><p>The <span class="monospaced">format</span> and <span class="monospaced">imageUsage</span> parameters are taken from the <span class="monospaced">VkSwapchainCreateInfoKHR</span> structure. The driver should fill <span class="monospaced">*grallocConsumerUsage</span> and <span class="monospaced">*grallocProducerUsage</span> with the gralloc usage flags it requires for that format and usage. These will be combined with the usage flags requested by the swapchain consumer when allocating buffers.</p></div> +<div class="paragraph"><p>An older version of this function is deprecated but still supported for backwards compatibility; it will be used if <span class="monospaced">vkGetSwapchainGrallocUsage2ANDROID</span> is not supported:</p></div> +<div class="listingblock"> +<div class="content"><!-- Generator: GNU source-highlight 3.1.6 +by Lorenzo Bettini +http://www.lorenzobettini.it +http://www.gnu.org/software/src-highlite --> +<pre><tt>VkResult <span style="color: #008080">VKAPI</span> <span style="font-weight: bold"><span style="color: #000000">vkGetSwapchainGrallocUsageANDROID</span></span><span style="color: #990000">(</span> + <span style="color: #008080">VkDevice</span> device<span style="color: #990000">,</span> + <span style="color: #008080">VkFormat</span> format<span style="color: #990000">,</span> + <span style="color: #008080">VkImageUsageFlags</span> imageUsage<span style="color: #990000">,</span> <span style="color: #009900">int</span><span style="color: #990000">*</span> grallocUsage <span style="color: #990000">);</span></tt></pre></div></div> <div class="paragraph"><p><span class="monospaced">VkNativeBufferANDROID</span> is a <span class="monospaced">vkCreateImage</span> extension structure for creating an image backed by a gralloc buffer. This structure is provided to <span class="monospaced">vkCreateImage</span> in the <span class="monospaced">VkImageCreateInfo</span> structure chain. Calls to <span class="monospaced">vkCreateImage</span> with this structure will happen during the first call to <span class="monospaced">vkGetSwapChainInfoWSI(.. VK_SWAP_CHAIN_INFO_TYPE_IMAGES_WSI ..)</span>. The WSI implementation will allocate the number of native buffers requested for the swapchain, then create a <span class="monospaced">VkImage</span> for each one.</p></div> @@ -846,7 +847,11 @@ http://www.gnu.org/software/src-highlite --> <span style="font-style: italic"><span style="color: #9A1900">// Gralloc format and usage requested when the buffer was allocated.</span></span> <span style="color: #009900">int</span> format<span style="color: #990000">;</span> - <span style="color: #009900">int</span> usage<span style="color: #990000">;</span> + <span style="color: #009900">int</span> usage<span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// deprecated</span></span> + <span style="font-weight: bold"><span style="color: #0000FF">struct</span></span> <span style="color: #FF0000">{</span> + <span style="color: #008080">uint64_t</span> consumer<span style="color: #990000">;</span> + <span style="color: #008080">uint64_t</span> producer<span style="color: #990000">;</span> + <span style="color: #FF0000">}</span> usage2<span style="color: #990000">;</span> <span style="color: #FF0000">}</span> VkNativeBufferANDROID<span style="color: #990000">;</span></tt></pre></div></div> <div class="paragraph"><p>When creating a gralloc-backed image, the <span class="monospaced">VkImageCreateInfo</span> will have:</p></div> <div class="listingblock"> @@ -1044,6 +1049,18 @@ Added VkSwapchainImageCreateInfoANDROID </li> </ul></div> </li> +<li> +<p> +<strong>2017-02-09</strong> +</p> +<div class="ulist"><ul> +<li> +<p> +Extended vkGetSwapchainGrallocUsage2ANDROID and VkNativeBufferANDROID to use gralloc1-style usage bitfields. +</p> +</li> +</ul></div> +</li> </ol></div> </div> </div> @@ -1052,7 +1069,7 @@ Added VkSwapchainImageCreateInfoANDROID <div id="footer"> <div id="footer-text"> Version 5<br> -Last updated 2017-01-12 14:25:30 NZDT +Last updated 2017-02-09 22:40:30 PST </div> </div> </body> diff --git a/vulkan/include/vulkan/vk_android_native_buffer.h b/vulkan/include/vulkan/vk_android_native_buffer.h index db23e79ef4..d7c5a079e0 100644 --- a/vulkan/include/vulkan/vk_android_native_buffer.h +++ b/vulkan/include/vulkan/vk_android_native_buffer.h @@ -27,6 +27,16 @@ extern "C" { #define VK_ANDROID_native_buffer 1 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER 11 +/* NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 6 + * + * This version of the extension transitions from gralloc0 to gralloc1 usage + * flags (int -> 2x uint64_t). The WSI implementation will temporarily continue + * to fill out deprecated fields in VkNativeBufferANDROID, and will call the + * deprecated vkGetSwapchainGrallocUsageANDROID if the new + * vkGetSwapchainGrallocUsage2ANDROID is not supported. This transitionary + * backwards-compatibility support is temporary, and will likely be removed in + * (along with all gralloc0 support) in a future release. + */ #define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 6 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" @@ -50,7 +60,12 @@ typedef struct { // Gralloc format and usage requested when the buffer was allocated. int format; - int usage; + int usage; // DEPRECATED in SPEC_VERSION 6 + // -- Added in SPEC_VERSION 6 -- + struct { + uint64_t consumer; + uint64_t producer; + } usage2; } VkNativeBufferANDROID; typedef struct { @@ -60,24 +75,30 @@ typedef struct { VkSwapchainImageUsageFlagsANDROID usage; } VkSwapchainImageCreateInfoANDROID; +// -- DEPRECATED in SPEC_VERSION 6 -- typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage); -typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage2ANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, int* grallocUsage); +// -- ADDED in SPEC_VERSION 6 -- +typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage2ANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, uint64_t* grallocConsumerUsage, uint64_t* grallocProducerUsage); typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence); typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd); #ifndef VK_NO_PROTOTYPES + +// -- DEPRECATED in SPEC_VERSION 6 -- VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID( VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage ); +// -- ADDED in SPEC_VERSION 6 -- VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID( VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, - int* grallocUsage + uint64_t* grallocConsumerUsage, + uint64_t* grallocProducerUsage ); VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID( VkDevice device, @@ -93,17 +114,6 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID( VkImage image, int* pNativeFenceFd ); -// -- DEPRECATED -- -VKAPI_ATTR VkResult VKAPI_CALL vkImportNativeFenceANDROID( - VkDevice device, - VkSemaphore semaphore, - int nativeFenceFd -); -VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalNativeFenceANDROID( - VkQueue queue, - int* pNativeFenceFd -); -// ---------------- #endif #ifdef __cplusplus diff --git a/vulkan/libvulkan/code-generator.tmpl b/vulkan/libvulkan/code-generator.tmpl index 501877c8b1..e3c44d28c6 100644 --- a/vulkan/libvulkan/code-generator.tmpl +++ b/vulkan/libvulkan/code-generator.tmpl @@ -413,13 +413,14 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc, {{AssertType $ "Function"}} {{$ext := GetAnnotation $ "extension"}} - {{$required := (Macro "IsRequiredFunction" $)}} {{if $ext}} - INIT_PROC_EXT({{Macro "BaseName" $ext}}, {{$required}}, § + INIT_PROC_EXT({{Macro "BaseName" $ext}}, § {{else}} - INIT_PROC({{$required}}, § + INIT_PROC(§ {{end}} + {{if GetAnnotation $ "optional"}}false{{else}}true{{end}}, § + {{if (Macro "IsInstanceDispatched" $)}} instance, § {{else}} @@ -432,25 +433,6 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc, {{/* ------------------------------------------------------------------------------ - Emits true if a function /must/ be resolved. The only time this is not - the case is for extension-added functions added in a later revision of the - extension, and where we have to cope with drivers written against an older - revision. ------------------------------------------------------------------------------- -*/}} -{{define "IsRequiredFunction"}} - {{AssertType $ "Function"}} - - {{if eq $.Name "vkGetSwapchainGrallocUsage2ANDROID"}} - false - {{else}} - true - {{end}} -{{end}} - - -{{/* ------------------------------------------------------------------------------- Emits true if a function is exported and instance-dispatched. ------------------------------------------------------------------------------ */}} @@ -981,6 +963,8 @@ VK_KHR_shared_presentable_image {{else if eq $.Name "vkCreateImage"}}true {{else if eq $.Name "vkDestroyImage"}}true + {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true + {{end}} {{$ext := GetAnnotation $ "extension"}} diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 991c3edef4..32f777dc87 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -899,7 +899,29 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, return VK_ERROR_INCOMPATIBLE_DRIVER; } + + // sanity check ANDROID_native_buffer implementation, whose set of + // entrypoints varies according to the spec version. + if ((wrapper.GetHalExtensions()[ProcHook::ANDROID_native_buffer]) && + !data->driver.GetSwapchainGrallocUsageANDROID && + !data->driver.GetSwapchainGrallocUsage2ANDROID) { + ALOGE("Driver's implementation of ANDROID_native_buffer is broken;" + " must expose at least one of " + "vkGetSwapchainGrallocUsageANDROID or " + "vkGetSwapchainGrallocUsage2ANDROID"); + + data->driver.DestroyDevice(dev, pAllocator); + FreeDeviceData(data, data_allocator); + + return VK_ERROR_INCOMPATIBLE_DRIVER; + } + + VkPhysicalDeviceProperties properties; + instance_data.driver.GetPhysicalDeviceProperties(physicalDevice, + &properties); + data->driver_device = dev; + data->driver_version = properties.driverVersion; *pDevice = dev; diff --git a/vulkan/libvulkan/driver.h b/vulkan/libvulkan/driver.h index e05843997c..5383f59b58 100644 --- a/vulkan/libvulkan/driver.h +++ b/vulkan/libvulkan/driver.h @@ -102,6 +102,7 @@ struct DeviceData { VkDevice driver_device; DeviceDriverTable driver; + uint32_t driver_version; }; bool Debuggable(); diff --git a/vulkan/libvulkan/driver_gen.cpp b/vulkan/libvulkan/driver_gen.cpp index 689a2284f9..951ea6e571 100644 --- a/vulkan/libvulkan/driver_gen.cpp +++ b/vulkan/libvulkan/driver_gen.cpp @@ -387,6 +387,7 @@ bool InitDriverTable(VkInstance instance, INIT_PROC(true, instance, DestroyInstance); INIT_PROC(true, instance, EnumeratePhysicalDevices); INIT_PROC(true, instance, GetInstanceProcAddr); + INIT_PROC(true, instance, GetPhysicalDeviceProperties); INIT_PROC(true, instance, CreateDevice); INIT_PROC(true, instance, EnumerateDeviceExtensionProperties); INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT); @@ -410,7 +411,7 @@ bool InitDriverTable(VkDevice dev, INIT_PROC(true, dev, CreateImage); INIT_PROC(true, dev, DestroyImage); INIT_PROC(true, dev, AllocateCommandBuffers); - INIT_PROC_EXT(ANDROID_native_buffer, true, dev, GetSwapchainGrallocUsageANDROID); + INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID); diff --git a/vulkan/libvulkan/driver_gen.h b/vulkan/libvulkan/driver_gen.h index 9f3b7054a1..95c70f8fce 100644 --- a/vulkan/libvulkan/driver_gen.h +++ b/vulkan/libvulkan/driver_gen.h @@ -60,6 +60,7 @@ struct InstanceDriverTable { PFN_vkDestroyInstance DestroyInstance; PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices; PFN_vkGetInstanceProcAddr GetInstanceProcAddr; + PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties; PFN_vkCreateDevice CreateDevice; PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties; PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT; diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index f4ee375c81..c11d20f6e7 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -812,13 +812,35 @@ VkResult CreateSwapchainKHR(VkDevice device, int gralloc_usage = 0; if (dispatch.GetSwapchainGrallocUsage2ANDROID) { - result = dispatch.GetSwapchainGrallocUsage2ANDROID( - device, create_info->imageFormat, create_info->imageUsage, - swapchain_image_usage, &gralloc_usage); + uint64_t consumer_usage, producer_usage; + if (GetData(device).driver_version == 256587285) { + // HACK workaround for loader/driver mismatch during transition to + // vkGetSwapchainGrallocUsage2ANDROID. + typedef VkResult(VKAPI_PTR * + PFN_vkGetSwapchainGrallocUsage2ANDROID_HACK)( + VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, + uint64_t * grallocConsumerUsage, + uint64_t * grallocProducerUsage); + auto get_swapchain_gralloc_usage = + reinterpret_cast<PFN_vkGetSwapchainGrallocUsage2ANDROID_HACK>( + dispatch.GetSwapchainGrallocUsage2ANDROID); + result = get_swapchain_gralloc_usage( + device, create_info->imageFormat, create_info->imageUsage, + &consumer_usage, &producer_usage); + } else { + result = dispatch.GetSwapchainGrallocUsage2ANDROID( + device, create_info->imageFormat, create_info->imageUsage, + swapchain_image_usage, &consumer_usage, &producer_usage); + } if (result != VK_SUCCESS) { ALOGE("vkGetSwapchainGrallocUsage2ANDROID failed: %d", result); return VK_ERROR_INITIALIZATION_FAILED; } + // TODO: This is the same translation done by Gralloc1On0Adapter. + // Remove it once ANativeWindow has been updated to take gralloc1-style + // usages. + gralloc_usage = + static_cast<int>(consumer_usage) | static_cast<int>(producer_usage); } else if (dispatch.GetSwapchainGrallocUsageANDROID) { result = dispatch.GetSwapchainGrallocUsageANDROID( device, create_info->imageFormat, create_info->imageUsage, @@ -827,8 +849,6 @@ VkResult CreateSwapchainKHR(VkDevice device, ALOGE("vkGetSwapchainGrallocUsageANDROID failed: %d", result); return VK_ERROR_INITIALIZATION_FAILED; } - } else { - gralloc_usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; } err = native_window_set_usage(surface.window.get(), gralloc_usage); if (err != 0) { @@ -918,6 +938,12 @@ VkResult CreateSwapchainKHR(VkDevice device, image_native_buffer.stride = img.buffer->stride; image_native_buffer.format = img.buffer->format; image_native_buffer.usage = img.buffer->usage; + // TODO: Adjust once ANativeWindowBuffer supports gralloc1-style usage. + // For now, this is the same translation Gralloc1On0Adapter does. + image_native_buffer.usage2.consumer = + static_cast<uint64_t>(img.buffer->usage); + image_native_buffer.usage2.producer = + static_cast<uint64_t>(img.buffer->usage); result = dispatch.CreateImage(device, &image_create, nullptr, &img.image); diff --git a/vulkan/nulldrv/null_driver.cpp b/vulkan/nulldrv/null_driver.cpp index 55f7f19d7c..e03ee0a27a 100644 --- a/vulkan/nulldrv/null_driver.cpp +++ b/vulkan/nulldrv/null_driver.cpp @@ -906,9 +906,11 @@ VkResult GetSwapchainGrallocUsage2ANDROID(VkDevice, VkFormat, VkImageUsageFlags, VkSwapchainImageUsageFlagsANDROID, - int* grallocUsage) { + uint64_t* grallocConsumerUsage, + uint64_t* grallocProducerUsage) { // The null driver never reads or writes the gralloc buffer - *grallocUsage = 0; + *grallocConsumerUsage = 0; + *grallocProducerUsage = 0; return VK_SUCCESS; } diff --git a/vulkan/nulldrv/null_driver_gen.h b/vulkan/nulldrv/null_driver_gen.h index cfc14ddffa..d73bf14411 100644 --- a/vulkan/nulldrv/null_driver_gen.h +++ b/vulkan/nulldrv/null_driver_gen.h @@ -165,8 +165,8 @@ VKAPI_ATTR void CmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRender VKAPI_ATTR void CmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents); VKAPI_ATTR void CmdEndRenderPass(VkCommandBuffer commandBuffer); VKAPI_ATTR void CmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers); -VKAPI_ATTR VkResult GetSwapchainGrallocUsageANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage); -VKAPI_ATTR VkResult GetSwapchainGrallocUsage2ANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, int* grallocUsage); +VKAPI_ATTR VkResult GetSwapchainGrallocUsageANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int32_t* grallocUsage); +VKAPI_ATTR VkResult GetSwapchainGrallocUsage2ANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, uint64_t* grallocConsumerUsage, uint64_t* grallocProducerUsage); VKAPI_ATTR VkResult AcquireImageANDROID(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence); VKAPI_ATTR VkResult QueueSignalReleaseImageANDROID(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd); VKAPI_ATTR VkResult CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback); |