vkr: split out vkr_image.c

No functional change.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Chia-I Wu 3 years ago
parent c471485538
commit c15d09acd1
  1. 1
      src/meson.build
  2. 271
      src/venus/vkr_image.c
  3. 12
      src/venus/vkr_image.h
  4. 236
      src/venus/vkr_renderer.c

@ -90,6 +90,7 @@ venus_sources = [
'venus/vkr_descriptor_set.h',
'venus/vkr_device.h',
'venus/vkr_device_memory.h',
'venus/vkr_image.c',
'venus/vkr_image.h',
'venus/vkr_pipeline.c',
'venus/vkr_pipeline.h',

@ -0,0 +1,271 @@
/*
* Copyright 2020 Google LLC
* SPDX-License-Identifier: MIT
*/
#include "vkr_image.h"
#include "venus-protocol/vn_protocol_renderer_image.h"
#include "venus-protocol/vn_protocol_renderer_image_view.h"
#include "venus-protocol/vn_protocol_renderer_sampler.h"
#include "venus-protocol/vn_protocol_renderer_sampler_ycbcr_conversion.h"
#include "vkr_context.h"
#include "vkr_device.h"
static void
vkr_dispatch_vkCreateImage(struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateImage *args)
{
struct vkr_context *ctx = dispatch->data;
struct vkr_device *dev = (struct vkr_device *)args->device;
if (!dev || dev->base.type != VK_OBJECT_TYPE_DEVICE) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
#ifdef FORCE_ENABLE_DMABUF
/* Do not chain VkExternalMemoryImageCreateInfo with optimal tiling, so that
* guest Venus can pass memory requirement cts with dedicated allocation.
*/
VkExternalMemoryImageCreateInfo local_external_info;
if (args->pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL &&
dev->physical_device->EXT_external_memory_dma_buf) {
VkExternalMemoryImageCreateInfo *external_info = vkr_find_pnext(
args->pCreateInfo->pNext, VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO);
if (external_info) {
external_info->handleTypes |= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
} else {
local_external_info = (const VkExternalMemoryImageCreateInfo){
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
.pNext = args->pCreateInfo->pNext,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
};
((VkImageCreateInfo *)args->pCreateInfo)->pNext = &local_external_info;
}
}
#endif
CREATE_OBJECT(img, image, IMAGE, vkCreateImage, pImage);
util_hash_table_set_u64(ctx->object_table, img->base.id, img);
}
static void
vkr_dispatch_vkDestroyImage(struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroyImage *args)
{
struct vkr_context *ctx = dispatch->data;
DESTROY_OBJECT(img, image, IMAGE, vkDestroyImage, image);
util_hash_table_remove_u64(ctx->object_table, img->base.id);
}
static void
vkr_dispatch_vkGetImageMemoryRequirements(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageMemoryRequirements *args)
{
vn_replace_vkGetImageMemoryRequirements_args_handle(args);
vkGetImageMemoryRequirements(args->device, args->image, args->pMemoryRequirements);
}
static void
vkr_dispatch_vkGetImageMemoryRequirements2(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageMemoryRequirements2 *args)
{
vn_replace_vkGetImageMemoryRequirements2_args_handle(args);
vkGetImageMemoryRequirements2(args->device, args->pInfo, args->pMemoryRequirements);
}
static void
vkr_dispatch_vkGetImageSparseMemoryRequirements(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageSparseMemoryRequirements *args)
{
vn_replace_vkGetImageSparseMemoryRequirements_args_handle(args);
vkGetImageSparseMemoryRequirements(args->device, args->image,
args->pSparseMemoryRequirementCount,
args->pSparseMemoryRequirements);
}
static void
vkr_dispatch_vkGetImageSparseMemoryRequirements2(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageSparseMemoryRequirements2 *args)
{
vn_replace_vkGetImageSparseMemoryRequirements2_args_handle(args);
vkGetImageSparseMemoryRequirements2(args->device, args->pInfo,
args->pSparseMemoryRequirementCount,
args->pSparseMemoryRequirements);
}
static void
vkr_dispatch_vkBindImageMemory(UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkBindImageMemory *args)
{
vn_replace_vkBindImageMemory_args_handle(args);
args->ret =
vkBindImageMemory(args->device, args->image, args->memory, args->memoryOffset);
}
static void
vkr_dispatch_vkBindImageMemory2(UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkBindImageMemory2 *args)
{
vn_replace_vkBindImageMemory2_args_handle(args);
args->ret = vkBindImageMemory2(args->device, args->bindInfoCount, args->pBindInfos);
}
static void
vkr_dispatch_vkGetImageSubresourceLayout(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageSubresourceLayout *args)
{
vn_replace_vkGetImageSubresourceLayout_args_handle(args);
vkGetImageSubresourceLayout(args->device, args->image, args->pSubresource,
args->pLayout);
}
static void
vkr_dispatch_vkGetImageDrmFormatModifierPropertiesEXT(
struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageDrmFormatModifierPropertiesEXT *args)
{
struct vkr_context *ctx = dispatch->data;
struct vkr_device *dev = (struct vkr_device *)args->device;
if (!dev || dev->base.type != VK_OBJECT_TYPE_DEVICE) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
vn_replace_vkGetImageDrmFormatModifierPropertiesEXT_args_handle(args);
args->ret = dev->get_image_drm_format_modifier_properties(args->device, args->image,
args->pProperties);
}
static void
vkr_dispatch_vkCreateImageView(struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateImageView *args)
{
struct vkr_context *ctx = dispatch->data;
CREATE_OBJECT(view, image_view, IMAGE_VIEW, vkCreateImageView, pView);
util_hash_table_set_u64(ctx->object_table, view->base.id, view);
}
static void
vkr_dispatch_vkDestroyImageView(struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroyImageView *args)
{
struct vkr_context *ctx = dispatch->data;
DESTROY_OBJECT(view, image_view, IMAGE_VIEW, vkDestroyImageView, imageView);
util_hash_table_remove_u64(ctx->object_table, view->base.id);
}
static void
vkr_dispatch_vkCreateSampler(struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateSampler *args)
{
struct vkr_context *ctx = dispatch->data;
CREATE_OBJECT(sampler, sampler, SAMPLER, vkCreateSampler, pSampler);
util_hash_table_set_u64(ctx->object_table, sampler->base.id, sampler);
}
static void
vkr_dispatch_vkDestroySampler(struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroySampler *args)
{
struct vkr_context *ctx = dispatch->data;
DESTROY_OBJECT(sampler, sampler, SAMPLER, vkDestroySampler, sampler);
util_hash_table_remove_u64(ctx->object_table, sampler->base.id);
}
static void
vkr_dispatch_vkCreateSamplerYcbcrConversion(
struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateSamplerYcbcrConversion *args)
{
struct vkr_context *ctx = dispatch->data;
CREATE_OBJECT(conv, sampler_ycbcr_conversion, SAMPLER_YCBCR_CONVERSION,
vkCreateSamplerYcbcrConversion, pYcbcrConversion);
util_hash_table_set_u64(ctx->object_table, conv->base.id, conv);
}
static void
vkr_dispatch_vkDestroySamplerYcbcrConversion(
struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroySamplerYcbcrConversion *args)
{
struct vkr_context *ctx = dispatch->data;
DESTROY_OBJECT(conv, sampler_ycbcr_conversion, SAMPLER_YCBCR_CONVERSION,
vkDestroySamplerYcbcrConversion, ycbcrConversion);
util_hash_table_remove_u64(ctx->object_table, conv->base.id);
}
void
vkr_context_init_image_dispatch(struct vkr_context *ctx)
{
struct vn_dispatch_context *dispatch = &ctx->dispatch;
dispatch->dispatch_vkCreateImage = vkr_dispatch_vkCreateImage;
dispatch->dispatch_vkDestroyImage = vkr_dispatch_vkDestroyImage;
dispatch->dispatch_vkGetImageMemoryRequirements =
vkr_dispatch_vkGetImageMemoryRequirements;
dispatch->dispatch_vkGetImageMemoryRequirements2 =
vkr_dispatch_vkGetImageMemoryRequirements2;
dispatch->dispatch_vkGetImageSparseMemoryRequirements =
vkr_dispatch_vkGetImageSparseMemoryRequirements;
dispatch->dispatch_vkGetImageSparseMemoryRequirements2 =
vkr_dispatch_vkGetImageSparseMemoryRequirements2;
dispatch->dispatch_vkBindImageMemory = vkr_dispatch_vkBindImageMemory;
dispatch->dispatch_vkBindImageMemory2 = vkr_dispatch_vkBindImageMemory2;
dispatch->dispatch_vkGetImageSubresourceLayout =
vkr_dispatch_vkGetImageSubresourceLayout;
dispatch->dispatch_vkGetImageDrmFormatModifierPropertiesEXT =
vkr_dispatch_vkGetImageDrmFormatModifierPropertiesEXT;
}
void
vkr_context_init_image_view_dispatch(struct vkr_context *ctx)
{
struct vn_dispatch_context *dispatch = &ctx->dispatch;
dispatch->dispatch_vkCreateImageView = vkr_dispatch_vkCreateImageView;
dispatch->dispatch_vkDestroyImageView = vkr_dispatch_vkDestroyImageView;
}
void
vkr_context_init_sampler_dispatch(struct vkr_context *ctx)
{
struct vn_dispatch_context *dispatch = &ctx->dispatch;
dispatch->dispatch_vkCreateSampler = vkr_dispatch_vkCreateSampler;
dispatch->dispatch_vkDestroySampler = vkr_dispatch_vkDestroySampler;
}
void
vkr_context_init_sampler_ycbcr_conversion_dispatch(struct vkr_context *ctx)
{
struct vn_dispatch_context *dispatch = &ctx->dispatch;
dispatch->dispatch_vkCreateSamplerYcbcrConversion =
vkr_dispatch_vkCreateSamplerYcbcrConversion;
dispatch->dispatch_vkDestroySamplerYcbcrConversion =
vkr_dispatch_vkDestroySamplerYcbcrConversion;
}

@ -24,4 +24,16 @@ struct vkr_sampler_ycbcr_conversion {
struct vkr_object base;
};
void
vkr_context_init_image_dispatch(struct vkr_context *ctx);
void
vkr_context_init_image_view_dispatch(struct vkr_context *ctx);
void
vkr_context_init_sampler_dispatch(struct vkr_context *ctx);
void
vkr_context_init_sampler_ycbcr_conversion_dispatch(struct vkr_context *ctx);
#endif /* VKR_IMAGE_H */

@ -1997,73 +1997,6 @@ vkr_dispatch_vkGetDeviceMemoryOpaqueCaptureAddress(
args->ret = dev->GetDeviceMemoryOpaqueCaptureAddress(args->device, args->pInfo);
}
static void
vkr_dispatch_vkGetImageMemoryRequirements(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageMemoryRequirements *args)
{
vn_replace_vkGetImageMemoryRequirements_args_handle(args);
vkGetImageMemoryRequirements(args->device, args->image, args->pMemoryRequirements);
}
static void
vkr_dispatch_vkGetImageMemoryRequirements2(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageMemoryRequirements2 *args)
{
vn_replace_vkGetImageMemoryRequirements2_args_handle(args);
vkGetImageMemoryRequirements2(args->device, args->pInfo, args->pMemoryRequirements);
}
static void
vkr_dispatch_vkGetImageSparseMemoryRequirements(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageSparseMemoryRequirements *args)
{
vn_replace_vkGetImageSparseMemoryRequirements_args_handle(args);
vkGetImageSparseMemoryRequirements(args->device, args->image,
args->pSparseMemoryRequirementCount,
args->pSparseMemoryRequirements);
}
static void
vkr_dispatch_vkGetImageSparseMemoryRequirements2(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageSparseMemoryRequirements2 *args)
{
vn_replace_vkGetImageSparseMemoryRequirements2_args_handle(args);
vkGetImageSparseMemoryRequirements2(args->device, args->pInfo,
args->pSparseMemoryRequirementCount,
args->pSparseMemoryRequirements);
}
static void
vkr_dispatch_vkBindImageMemory(UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkBindImageMemory *args)
{
vn_replace_vkBindImageMemory_args_handle(args);
args->ret =
vkBindImageMemory(args->device, args->image, args->memory, args->memoryOffset);
}
static void
vkr_dispatch_vkBindImageMemory2(UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkBindImageMemory2 *args)
{
vn_replace_vkBindImageMemory2_args_handle(args);
args->ret = vkBindImageMemory2(args->device, args->bindInfoCount, args->pBindInfos);
}
static void
vkr_dispatch_vkGetImageSubresourceLayout(
UNUSED struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageSubresourceLayout *args)
{
vn_replace_vkGetImageSubresourceLayout_args_handle(args);
vkGetImageSubresourceLayout(args->device, args->image, args->pSubresource,
args->pLayout);
}
static void
vkr_dispatch_vkCreateFence(struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateFence *args)
@ -2197,126 +2130,6 @@ vkr_dispatch_vkSignalSemaphore(struct vn_dispatch_context *dispatch,
args->ret = dev->SignalSemaphore(args->device, args->pSignalInfo);
}
static void
vkr_dispatch_vkCreateImage(struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateImage *args)
{
struct vkr_context *ctx = dispatch->data;
struct vkr_device *dev = (struct vkr_device *)args->device;
if (!dev || dev->base.type != VK_OBJECT_TYPE_DEVICE) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
#ifdef FORCE_ENABLE_DMABUF
/* Do not chain VkExternalMemoryImageCreateInfo with optimal tiling, so that
* guest Venus can pass memory requirement cts with dedicated allocation.
*/
VkExternalMemoryImageCreateInfo local_external_info;
if (args->pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL &&
dev->physical_device->EXT_external_memory_dma_buf) {
VkExternalMemoryImageCreateInfo *external_info = vkr_find_pnext(
args->pCreateInfo->pNext, VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO);
if (external_info) {
external_info->handleTypes |= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
} else {
local_external_info = (const VkExternalMemoryImageCreateInfo){
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
.pNext = args->pCreateInfo->pNext,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
};
((VkImageCreateInfo *)args->pCreateInfo)->pNext = &local_external_info;
}
}
#endif
CREATE_OBJECT(img, image, IMAGE, vkCreateImage, pImage);
util_hash_table_set_u64(ctx->object_table, img->base.id, img);
}
static void
vkr_dispatch_vkDestroyImage(struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroyImage *args)
{
struct vkr_context *ctx = dispatch->data;
DESTROY_OBJECT(img, image, IMAGE, vkDestroyImage, image);
util_hash_table_remove_u64(ctx->object_table, img->base.id);
}
static void
vkr_dispatch_vkCreateImageView(struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateImageView *args)
{
struct vkr_context *ctx = dispatch->data;
CREATE_OBJECT(view, image_view, IMAGE_VIEW, vkCreateImageView, pView);
util_hash_table_set_u64(ctx->object_table, view->base.id, view);
}
static void
vkr_dispatch_vkDestroyImageView(struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroyImageView *args)
{
struct vkr_context *ctx = dispatch->data;
DESTROY_OBJECT(view, image_view, IMAGE_VIEW, vkDestroyImageView, imageView);
util_hash_table_remove_u64(ctx->object_table, view->base.id);
}
static void
vkr_dispatch_vkCreateSampler(struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateSampler *args)
{
struct vkr_context *ctx = dispatch->data;
CREATE_OBJECT(sampler, sampler, SAMPLER, vkCreateSampler, pSampler);
util_hash_table_set_u64(ctx->object_table, sampler->base.id, sampler);
}
static void
vkr_dispatch_vkDestroySampler(struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroySampler *args)
{
struct vkr_context *ctx = dispatch->data;
DESTROY_OBJECT(sampler, sampler, SAMPLER, vkDestroySampler, sampler);
util_hash_table_remove_u64(ctx->object_table, sampler->base.id);
}
static void
vkr_dispatch_vkCreateSamplerYcbcrConversion(
struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateSamplerYcbcrConversion *args)
{
struct vkr_context *ctx = dispatch->data;
CREATE_OBJECT(conv, sampler_ycbcr_conversion, SAMPLER_YCBCR_CONVERSION,
vkCreateSamplerYcbcrConversion, pYcbcrConversion);
util_hash_table_set_u64(ctx->object_table, conv->base.id, conv);
}
static void
vkr_dispatch_vkDestroySamplerYcbcrConversion(
struct vn_dispatch_context *dispatch,
struct vn_command_vkDestroySamplerYcbcrConversion *args)
{
struct vkr_context *ctx = dispatch->data;
DESTROY_OBJECT(conv, sampler_ycbcr_conversion, SAMPLER_YCBCR_CONVERSION,
vkDestroySamplerYcbcrConversion, ycbcrConversion);
util_hash_table_remove_u64(ctx->object_table, conv->base.id);
}
static void
vkr_dispatch_vkCreateEvent(struct vn_dispatch_context *dispatch,
struct vn_command_vkCreateEvent *args)
@ -2363,23 +2176,6 @@ vkr_dispatch_vkResetEvent(UNUSED struct vn_dispatch_context *dispatch,
args->ret = vkResetEvent(args->device, args->event);
}
static void
vkr_dispatch_vkGetImageDrmFormatModifierPropertiesEXT(
struct vn_dispatch_context *dispatch,
struct vn_command_vkGetImageDrmFormatModifierPropertiesEXT *args)
{
struct vkr_context *ctx = dispatch->data;
struct vkr_device *dev = (struct vkr_device *)args->device;
if (!dev || dev->base.type != VK_OBJECT_TYPE_DEVICE) {
vkr_cs_decoder_set_fatal(&ctx->decoder);
return;
}
vn_replace_vkGetImageDrmFormatModifierPropertiesEXT_args_handle(args);
args->ret = dev->get_image_drm_format_modifier_properties(args->device, args->image,
args->pProperties);
}
static void
vkr_dispatch_vkGetMemoryResourcePropertiesMESA(
struct vn_dispatch_context *dispatch,
@ -2583,31 +2379,10 @@ vkr_context_init_dispatch(struct vkr_context *ctx)
vkr_context_init_buffer_dispatch(ctx);
vkr_context_init_buffer_view_dispatch(ctx);
dispatch->dispatch_vkCreateImage = vkr_dispatch_vkCreateImage;
dispatch->dispatch_vkDestroyImage = vkr_dispatch_vkDestroyImage;
dispatch->dispatch_vkGetImageMemoryRequirements =
vkr_dispatch_vkGetImageMemoryRequirements;
dispatch->dispatch_vkGetImageMemoryRequirements2 =
vkr_dispatch_vkGetImageMemoryRequirements2;
dispatch->dispatch_vkGetImageSparseMemoryRequirements =
vkr_dispatch_vkGetImageSparseMemoryRequirements;
dispatch->dispatch_vkGetImageSparseMemoryRequirements2 =
vkr_dispatch_vkGetImageSparseMemoryRequirements2;
dispatch->dispatch_vkBindImageMemory = vkr_dispatch_vkBindImageMemory;
dispatch->dispatch_vkBindImageMemory2 = vkr_dispatch_vkBindImageMemory2;
dispatch->dispatch_vkGetImageSubresourceLayout =
vkr_dispatch_vkGetImageSubresourceLayout;
dispatch->dispatch_vkCreateImageView = vkr_dispatch_vkCreateImageView;
dispatch->dispatch_vkDestroyImageView = vkr_dispatch_vkDestroyImageView;
dispatch->dispatch_vkCreateSampler = vkr_dispatch_vkCreateSampler;
dispatch->dispatch_vkDestroySampler = vkr_dispatch_vkDestroySampler;
dispatch->dispatch_vkCreateSamplerYcbcrConversion =
vkr_dispatch_vkCreateSamplerYcbcrConversion;
dispatch->dispatch_vkDestroySamplerYcbcrConversion =
vkr_dispatch_vkDestroySamplerYcbcrConversion;
vkr_context_init_image_dispatch(ctx);
vkr_context_init_image_view_dispatch(ctx);
vkr_context_init_sampler_dispatch(ctx);
vkr_context_init_sampler_ycbcr_conversion_dispatch(ctx);
vkr_context_init_descriptor_set_layout_dispatch(ctx);
vkr_context_init_descriptor_pool_dispatch(ctx);
@ -2633,9 +2408,6 @@ vkr_context_init_dispatch(struct vkr_context *ctx)
vkr_context_init_command_pool_dispatch(ctx);
vkr_context_init_command_buffer_dispatch(ctx);
dispatch->dispatch_vkGetImageDrmFormatModifierPropertiesEXT =
vkr_dispatch_vkGetImageDrmFormatModifierPropertiesEXT;
dispatch->dispatch_vkGetMemoryResourcePropertiesMESA =
vkr_dispatch_vkGetMemoryResourcePropertiesMESA;

Loading…
Cancel
Save