[Piglit] [v3 08/11] ext_memory_object: Support for importing vulkan memory

Andres Rodriguez andresx7 at gmail.com
Thu Dec 21 16:33:54 UTC 2017



On 2017-12-21 07:02 AM, Topi Pohjolainen wrote:
> v2:
>      - s/get_fd/vk_get_memory_fd/ (Andres)
>      - check for glImportMemoryFdEXT() failure (Andres)
> 
> Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
> ---
>   tests/spec/ext_memory_object/common.c    | 72 ++++++++++++++++++++++++++++++++
>   tests/spec/ext_memory_object/common.h    |  8 ++++
>   tests/spec/ext_memory_object/vk_common.c | 12 ++++++
>   tests/spec/ext_memory_object/vk_common.h |  3 ++
>   4 files changed, 95 insertions(+)
> 
> diff --git a/tests/spec/ext_memory_object/common.c b/tests/spec/ext_memory_object/common.c
> index c274f14df..2a7c0ba31 100644
> --- a/tests/spec/ext_memory_object/common.c
> +++ b/tests/spec/ext_memory_object/common.c
> @@ -69,3 +69,75 @@ parse_tex_layout(const char **args, unsigned num_args,
>   	layout->layout.first_layer = read_unsigned(args[10], usage_prefix);
>   	layout->layout.num_layers = read_unsigned(args[11], usage_prefix);
>   }
> +
> +bool
> +create_mem_obj_for_vk_dev_mem(VkDevice dev, VkDeviceMemory mem,
> +			      uint64_t size, GLuint *mem_obj)
> +{
> +	PFN_vkGetMemoryFdKHR vk_get_memory_fd =
> +                vk_get_proc_addr_for_mem_fd(dev);
> +	const VkMemoryGetFdInfoKHR info = {
> +		.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
> +		.memory = mem,
> +		.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
> +	};
> +	int fd;
> +
> +	assert(vk_get_memory_fd);
> +	if (vk_get_memory_fd(dev, &info, &fd) != VK_SUCCESS)
> +		return false;
> +
> +	glCreateMemoryObjectsEXT(1, mem_obj);
> +
> +	glImportMemoryFdEXT(*mem_obj, size, GL_HANDLE_TYPE_OPAQUE_FD_EXT, fd);
> +
> +	return glGetError() == GL_NO_ERROR;

Might be able to use piglit_check_gl_error(GL_NO_ERROR) here.

With that changed, patch is
Reviewed-by: Andres Rodriguez <andresx7 at gmail.com>

> +}
> +
> +void
> +create_tex_from_vk_dev_mem(const struct tex_layout *layout,
> +			   GLuint mem_obj, unsigned offset, GLuint *tex)
> +{
> +	assert(layout->layout.num_samples == 1);
> +
> +	glGenTextures(1, tex);
> +	glBindTexture(layout->target, *tex);
> +
> +	switch (layout->target) {
> +	case GL_TEXTURE_1D:
> +		assert(layout->layout.z == 1);
> +		assert(layout->layout.h == 1);
> +		glTexStorageMem1DEXT(
> +			layout->target, layout->layout.num_levels,
> +			layout->format, layout->layout.w, mem_obj, offset);
> +		break;
> +	case GL_TEXTURE_1D_ARRAY:
> +		assert(layout->layout.z == 1);
> +		assert(layout->layout.h == 1);
> +		glTexStorageMem2DEXT(
> +			layout->target, layout->layout.num_levels,
> +			layout->format, layout->layout.w,
> +			layout->layout.num_layers, mem_obj, offset);
> +	case GL_TEXTURE_2D:
> +		assert(layout->layout.z == 1);
> +		glTexStorageMem2DEXT(
> +			layout->target, layout->layout.num_levels,
> +			layout->format, layout->layout.w, layout->layout.h,
> +			mem_obj, offset);
> +		break;
> +	case GL_TEXTURE_2D_ARRAY:
> +		assert(layout->layout.z == 1);
> +		glTexStorageMem3DEXT(
> +			layout->target, layout->layout.num_levels,
> +			layout->format, layout->layout.w, layout->layout.h,
> +			layout->layout.num_layers, mem_obj, offset);
> +	case GL_TEXTURE_3D:
> +		glTexStorageMem3DEXT(
> +			layout->target, layout->layout.num_levels,
> +			layout->format, layout->layout.w, layout->layout.h,
> +			layout->layout.z, mem_obj, offset);
> +		break;
> +	default:
> +		assert(!"Invalid target");
> +	}
> +}
> diff --git a/tests/spec/ext_memory_object/common.h b/tests/spec/ext_memory_object/common.h
> index 69ebb3f4a..240c305e8 100644
> --- a/tests/spec/ext_memory_object/common.h
> +++ b/tests/spec/ext_memory_object/common.h
> @@ -36,4 +36,12 @@ void
>   parse_tex_layout(const char **args, unsigned num_args,
>   		 const char *usage_prefix, struct tex_layout *layout);
>   
> +bool
> +create_mem_obj_for_vk_dev_mem(VkDevice dev, VkDeviceMemory mem,
> +			      uint64_t size, GLuint *mem_obj);
> +
> +void
> +create_tex_from_vk_dev_mem(const struct tex_layout *layout,
> +			   GLuint mem_obj, unsigned offset, GLuint *tex);
> +
>   #endif
> diff --git a/tests/spec/ext_memory_object/vk_common.c b/tests/spec/ext_memory_object/vk_common.c
> index eaecdf8cd..6e6458ce4 100644
> --- a/tests/spec/ext_memory_object/vk_common.c
> +++ b/tests/spec/ext_memory_object/vk_common.c
> @@ -583,3 +583,15 @@ vk_get_proc_addr_for_image_mem_req(VkDevice dev)
>   
>           return get_mem_req;
>   }
> +
> +PFN_vkGetMemoryFdKHR
> +vk_get_proc_addr_for_mem_fd(VkDevice dev)
> +{
> +	static PFN_vkGetMemoryFdKHR get_fd = NULL;
> +
> +	if (get_fd == NULL)
> +		get_fd = (PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(
> +						dev, "vkGetMemoryFdKHR");
> +
> +	return get_fd;
> +}
> diff --git a/tests/spec/ext_memory_object/vk_common.h b/tests/spec/ext_memory_object/vk_common.h
> index b092b142f..db4bbf20f 100644
> --- a/tests/spec/ext_memory_object/vk_common.h
> +++ b/tests/spec/ext_memory_object/vk_common.h
> @@ -150,4 +150,7 @@ vk_create_fence(VkDevice dev);
>   PFN_vkGetImageMemoryRequirements2KHR
>   vk_get_proc_addr_for_image_mem_req(VkDevice dev);
>   
> +PFN_vkGetMemoryFdKHR
> +vk_get_proc_addr_for_mem_fd(VkDevice dev);
> +
>   #endif
> 


More information about the Piglit mailing list