Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1abd745 authored by Jesse Hall's avatar Jesse Hall
Browse files

vulkan: Add gralloc1 usage to VK_ANDROID_native_buffer

Replaces the gralloc0-style 'int' usage in
vkGetSwapchainGrallocUsage2ANDROID and VkNativeBufferANDROID with a
gralloc1-style pair of uint64_t usages. A later change will plumb this
to and from ANativeWindow; for now we just collapse and expand from
32-bit usage.

Test: vulkanGears
Change-Id: I4555ba9d6ca1d15ed0791dc0bda01a1443890d02
parent d827791b
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -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 ?
}

+22 −15
Original line number Diff line number Diff line
@@ -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
+35 −18
Original line number Diff line number Diff line
@@ -730,7 +730,7 @@ asciidoc.install(2);
/*]]>*/
</script>
</head>
<body class="article">
<body class="book">
<div id="header">
<h1>Vulkan on Android Implementor&#8217;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&#8217;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>
+24 −14
Original line number Diff line number Diff line
@@ -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
+4 −24
Original line number Diff line number Diff line
@@ -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}}
@@ -430,27 +431,6 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
{{end}}


{{/*
------------------------------------------------------------------------------
  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 if eq $.Name "vkGetSwapchainGrallocUsageANDROID"}}
    false
  {{else}}
    true
  {{end}}
{{end}}


{{/*
------------------------------------------------------------------------------
  Emits true if a function is exported and instance-dispatched.
Loading