<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Fri, Aug 24, 2018 at 12:08 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 08/22/2018 05:18 PM, Jason Ekstrand wrote:<br>
> On Tue, Aug 21, 2018 at 3:27 AM Tapani Pälli <<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>
> When adding YUV support, we need to figure out implementation-defined<br>
> external format identifier.<br>
> <br>
> Signed-off-by: Tapani Pälli <<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 hw_module_t* mod, 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 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 *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 buffer object with<br>
> at least<br>
> + * one of the AHARDWAREBUFFER_USAGE_GPU_* 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 *p = pProperties;<br>
> +<br>
> + p->pNext = NULL;<br>
> <br>
> <br>
> You shouldn't be overwriting pNext. That's used by the client to let <br>
> them chain in multiple structs to fill out in case Google ever extends <br>
> this extension. Also, while we're here, it'd be good 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 = anv_get_format(p->format);<br>
> + struct anv_physical_device *physical_device =<br>
> + &device->instance->physicalDevice;<br>
> + const struct gen_device_info *devinfo = &physical_device->info;<br>
> <br>
> <br>
> If all you need is devinfo, that's avilable in the device; you don't <br>
> need to get the physical device for it. Should be device->info.<br>
<br>
OK<br>
<br>
> +<br>
> + p->formatFeatures =<br>
> + anv_get_image_format_features(devinfo, 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 least one of<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 matter, all of the <br>
> formats you have in your conversion helpers support sampling. Maybe <br>
> just replace that with an assert for now.<br>
<br>
Yeah, VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT is there. Well 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 (independent of <br>
surface format). TBH I'm not sure what to do about that.<br></blockquote><div><br></div><div>That's annoying... Is that in a Khronos CTS test or a Google test? Either way, we should try to get it corrected. If you don't know how to do that, I can send some e-mails.</div><div><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> +<br>
> + p->samplerYcbcrConversionComponents.r =<br>
> VK_COMPONENT_SWIZZLE_IDENTITY;<br>
> + p->samplerYcbcrConversionComponents.g =<br>
> VK_COMPONENT_SWIZZLE_IDENTITY;<br>
> + p->samplerYcbcrConversionComponents.b =<br>
> VK_COMPONENT_SWIZZLE_IDENTITY;<br>
> + p->samplerYcbcrConversionComponents.a =<br>
> VK_COMPONENT_SWIZZLE_IDENTITY;<br>
> +<br>
> + p->suggestedYcbcrModel =<br>
> VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;<br>
> + p->suggestedYcbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;<br>
> + p->suggestedXChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;<br>
> + p->suggestedYChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;<br>
> +<br>
> + return VK_SUCCESS;<br>
> +}<br>
> +<br>
> +VkResult<br>
> +anv_GetAndroidHardwareBufferPropertiesANDROID(<br>
> + VkDevice device_h,<br>
> + const struct AHardwareBuffer *buffer,<br>
> + VkAndroidHardwareBufferPropertiesANDROID *pProperties)<br>
> +{<br>
> + ANV_FROM_HANDLE(anv_device, dev, device_h);<br>
> + struct anv_physical_device *pdevice =<br>
> &dev->instance->physicalDevice;<br>
> +<br>
> + VkAndroidHardwareBufferFormatPropertiesANDROID *format_prop =<br>
> + vk_find_struct(pProperties->pNext,<br>
> + <br>
> ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID);<br>
> +<br>
> + /* Fill format properties of an Android hardware buffer. */<br>
> + if (format_prop)<br>
> + get_ahw_buffer_format_properties(device_h, buffer, format_prop);<br>
> +<br>
> + /* Get a description of buffer contents . */<br>
> + AHardwareBuffer_Desc desc;<br>
> + AHardwareBuffer_describe(buffer, &desc);<br>
> <br>
> <br>
> I don't see you using this anywyere. get_ahw_bufer_format_properties <br>
> calls it itself. An artefact of rebsing perhaps? Should probably drop <br>
> it if it's not needed.<br>
<br>
Yes this was only used for debugging, will remove.<br>
<br>
> +<br>
> + const native_handle_t *handle =<br>
> + AHardwareBuffer_getNativeHandle(buffer);<br>
> + int dma_buf = (handle && handle->numFds) ? handle->data[0] : -1;<br>
> + if (dma_buf < 0)<br>
> + return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;<br>
> +<br>
> + /* All memory types. */<br>
> + uint32_t memory_types = (1ull << pdevice->memory.type_count) - 1;<br>
> +<br>
> + pProperties->allocationSize = lseek(dma_buf, 0, SEEK_END);<br>
> + pProperties->memoryTypeBits = memory_types;<br>
> +<br>
> + return VK_SUCCESS;<br>
> +}<br>
> +<br>
> VkResult<br>
> anv_image_from_gralloc(VkDevice device_h,<br>
> const VkImageCreateInfo *base_info,<br>
> -- <br>
> 2.14.4<br>
> <br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a>><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> <br>
</blockquote></div></div>