<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Sep 26, 2018 at 8:29 AM Tapani Pälli <<a href="mailto:tapani.palli@intel.com">tapani.palli@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 9/26/18 10:46 AM, Jason Ekstrand wrote:<br>
> On Mon, Aug 27, 2018 at 2:22 AM Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a> <br>
> <mailto:<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>>> wrote:<br>
> <br>
>     On Sun, Aug 26, 2018 at 11:54 PM Tapani Pälli<br>
>     <<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a> <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>>> wrote:<br>
> <br>
> <br>
> <br>
>         On 08/24/2018 05:04 PM, Jason Ekstrand wrote:<br>
>          > On Fri, Aug 24, 2018 at 12:08 AM Tapani Pälli<br>
>         <<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a> <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>><br>
>          > <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a><br>
>         <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>>>> wrote:<br>
>          ><br>
>          ><br>
>          ><br>
>          >     On 08/22/2018 05:18 PM, Jason Ekstrand wrote:<br>
>          >      > On Tue, Aug 21, 2018 at 3:27 AM Tapani Pälli<br>
>          >     <<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a> <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>><br>
>         <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a> <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>>><br>
>          >      > <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a><br>
>         <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>> <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a><br>
>         <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>>>>><br>
>          >     wrote:<br>
>          >      ><br>
>          >      >     When adding YUV support, we need to figure out<br>
>          >     implementation-defined<br>
>          >      >     external format identifier.<br>
>          >      ><br>
>          >      >     Signed-off-by: Tapani Pälli<br>
>         <<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a> <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>><br>
>          >     <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a><br>
>         <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>>><br>
>          >      >     <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a><br>
>         <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>> <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a><br>
>         <mailto:<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>>>>><br>
>          >      >     ---<br>
>          >      >       src/intel/vulkan/anv_android.c | 99<br>
>          >      >     ++++++++++++++++++++++++++++++++++++++++++<br>
>          >      >       1 file changed, 99 insertions(+)<br>
>          >      ><br>
>          >      >     diff --git a/src/intel/vulkan/anv_android.c<br>
>          >      >     b/src/intel/vulkan/anv_android.c<br>
>          >      >     index 46c41d57861..7d0eb588e2b 100644<br>
>          >      >     --- a/src/intel/vulkan/anv_android.c<br>
>          >      >     +++ b/src/intel/vulkan/anv_android.c<br>
>          >      >     @@ -29,6 +29,8 @@<br>
>          >      >       #include <sync/sync.h><br>
>          >      ><br>
>          >      >       #include "anv_private.h"<br>
>          >      >     +#include "vk_format_info.h"<br>
>          >      >     +#include "vk_util.h"<br>
>          >      ><br>
>          >      >       static int anv_hal_open(const struct<br>
>         hw_module_t* mod,<br>
>          >     const char*<br>
>          >      >     id, struct hw_device_t** dev);<br>
>          >      >       static int anv_hal_close(struct hw_device_t *dev);<br>
>          >      >     @@ -96,6 +98,103 @@ anv_hal_close(struct<br>
>         hw_device_t *dev)<br>
>          >      >          return -1;<br>
>          >      >       }<br>
>          >      ><br>
>          >      >     +static VkResult<br>
>          >      >     +get_ahw_buffer_format_properties(<br>
>          >      >     +   VkDevice device_h,<br>
>          >      >     +   const struct AHardwareBuffer *buffer,<br>
>          >      >     +   VkAndroidHardwareBufferFormatPropertiesANDROID<br>
>         *pProperties)<br>
>          >      >     +{<br>
>          >      >     +   ANV_FROM_HANDLE(anv_device, device, device_h);<br>
>          >      >     +<br>
>          >      >     +   /* Get a description of buffer contents . */<br>
>          >      >     +   AHardwareBuffer_Desc desc;<br>
>          >      >     +   AHardwareBuffer_describe(buffer, &desc);<br>
>          >      >     +<br>
>          >      >     +   /* Verify description. */<br>
>          >      >     +   uint64_t gpu_usage =<br>
>          >      >     +      AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |<br>
>          >      >     +      AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT |<br>
>          >      >     +      AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER;<br>
>          >      >     +<br>
>          >      >     +   /* "Buffer must be a valid Android hardware<br>
>         buffer object<br>
>          >     with<br>
>          >      >     at least<br>
>          >      >     +    * one of the AHARDWAREBUFFER_USAGE_GPU_*<br>
>         usage flags."<br>
>          >      >     +    */<br>
>          >      >     +   if (!(desc.usage & (gpu_usage)))<br>
>          >      >     +      return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;<br>
>          >      >     +<br>
>          >      >     +   /* Fill properties fields based on description. */<br>
>          >      >     +   VkAndroidHardwareBufferFormatPropertiesANDROID<br>
>         *p =<br>
>          >     pProperties;<br>
>          >      >     +<br>
>          >      >     +   p->pNext = NULL;<br>
>          >      ><br>
>          >      ><br>
>          >      > You shouldn't be overwriting pNext.  That's used by<br>
>         the client to<br>
>          >     let<br>
>          >      > them chain in multiple structs to fill out in case<br>
>         Google ever<br>
>          >     extends<br>
>          >      > this extension.  Also, while we're here, it'd be good<br>
>         to throw in an<br>
>          >      > assert that p->sType is the right thing.<br>
>          ><br>
>          >     Yes of course, will remove.<br>
>          ><br>
>          >      >     +   p->format = vk_format_from_android(desc.format);<br>
>          >      >     +   p->externalFormat = 1; /* XXX */<br>
>          >      >     +<br>
>          >      >     +   const struct anv_format *anv_format =<br>
>          >     anv_get_format(p->format);<br>
>          >      >     +   struct anv_physical_device *physical_device =<br>
>          >      >     +      &device->instance->physicalDevice;<br>
>          >      >     +   const struct gen_device_info *devinfo =<br>
>          >     &physical_device->info;<br>
>          >      ><br>
>          >      ><br>
>          >      > If all you need is devinfo, that's avilable in the<br>
>         device; you don't<br>
>          >      > need to get the physical device for it.  Should be<br>
>         device->info.<br>
>          ><br>
>          >     OK<br>
>          ><br>
>          >      >     +<br>
>          >      >     +   p->formatFeatures =<br>
>          >      >     +      anv_get_image_format_features(devinfo,<br>
>         p->format,<br>
>          >      >     +                                    anv_format,<br>
>          >      >     VK_IMAGE_TILING_OPTIMAL);<br>
>          >      >     +<br>
>          >      >     +   /* "The formatFeatures member *must* include<br>
>          >      >     +    *  VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT and at<br>
>         least one of<br>
>          >      >     +    * <br>
>         VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT or<br>
>          >      >     +    *  VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT"<br>
>          >      >     +    */<br>
>          >      >     +   p->formatFeatures |=<br>
>          >      >     +      VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT;<br>
>          >      ><br>
>          >      ><br>
>          >      > Uh... Why not just throw in SAMPLED_BIT?  For that<br>
>         matter, all of<br>
>          >     the<br>
>          >      > formats you have in your conversion helpers support<br>
>         sampling.  Maybe<br>
>          >      > just replace that with an assert for now.<br>
>          ><br>
>          >     Yeah, VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT is there. Well<br>
>         thing is that<br>
>          >     dEQP checks explicitly that either<br>
>          >     VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT or<br>
>          >     VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT exists<br>
>         (independent of<br>
>          >     surface format). TBH I'm not sure what to do about that.<br>
>          ><br>
>          ><br>
>          > That's annoying...  Is that in a Khronos CTS test or a Google<br>
>         test?<br>
>          > Either way, we should try to get it corrected.  If you don't<br>
>         know how to<br>
>          > do that, I can send some e-mails.<br>
> <br>
>         But per the Vulkan spec quote above it's not a bug, it says that<br>
>         "formatFeatures member must include sampled bit and at least one of<br>
>         MIDPOINT_CHROMA_SAMPLES or COSITED_CHROMA_SAMPLES. So .. I guess I<br>
>         should limit the supported formats to only those that have<br>
>         anv_format->can_ycbcr() set?<br>
> <br>
> <br>
>       I'll grant that it's consistent with the spec but it also seems<br>
>     like the spec has a bug.  I'll file a spec bug.<br>
> <br>
> <br>
> I had a chat with Jesse Hall at the F2F in Budapest last week and he <br>
> explained why this is needed.  The requirement exists so that clients <br>
> can always take the external path even if the format is not <br>
> VK_FORMAT_UNSUPPORTED.  In order to support this, we need to allow color <br>
> conversion samplers even for non-YUV formats.  It should be fairly easy <br>
> to just no-op the format conversion when it's a non-YUV external <br>
> format.  I don't know if there are tests which exercise the format <br>
> conversion path on, say R8G8B8A8_UNORM, but we need to make sure it works.<br>
> <br>
<br>
OK, will try to test this through. It seems currently I'm getting a <br>
crash in anv_nir_lower_ycbcr_textures() when using sampler created with <br>
VkSamplerYcbcrConversion together with regular RGB texture, I think <br>
something is going wrong with component swizzle mapping done there. I'll <br>
need to verify I'm doing things ok though, I haven't used <br>
VkSamplerYcbcrConversion previously.<br></blockquote><div><br></div><div>Yeah, we just need to detect the case where we have an external format that's RGBA and no-op it either in lower_ycbcr_conversion or don't create the conversion object in CreateSampler.</div><div><br></div><div>--Jason<br></div></div></div>