mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
vulkan: create validation function for dmabuf properties
Validation of properties is moved from the import and allocation functions into a separate function. This allows later separation of modifier informations from the base struct.
This commit is contained in:
parent
08216be3b1
commit
02779fe28b
3 changed files with 18 additions and 15 deletions
|
|
@ -495,6 +495,8 @@ int spa_vulkan_compute_use_buffers(struct vulkan_compute_state *s, struct vulkan
|
|||
: VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
.spa_buf = buffers[i],
|
||||
};
|
||||
struct vulkan_modifier_info *modifierInfo = vulkan_modifierInfo_find(&s->base, format, dsp_info->modifier);
|
||||
CHECK(vulkan_validate_dmabuf_properties(modifierInfo, &dmabufInfo.spa_buf->n_datas, &dmabufInfo.size));
|
||||
ret = vulkan_create_dmabuf(&s->base, &dmabufInfo, &p->buffers[i]);
|
||||
} else {
|
||||
spa_log_error(s->log, "Unsupported buffer type mask %d", buffers[i]->datas[0].type);
|
||||
|
|
@ -513,6 +515,8 @@ int spa_vulkan_compute_use_buffers(struct vulkan_compute_state *s, struct vulkan
|
|||
: VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
.spa_buf = buffers[i],
|
||||
};
|
||||
struct vulkan_modifier_info *modifierInfo = vulkan_modifierInfo_find(&s->base, format, dsp_info->modifier);
|
||||
CHECK(vulkan_validate_dmabuf_properties(modifierInfo, &dmabufInfo.spa_buf->n_datas, &dmabufInfo.size));
|
||||
ret = vulkan_import_dmabuf(&s->base, &dmabufInfo, &p->buffers[i]);
|
||||
break;
|
||||
case SPA_DATA_MemPtr:;
|
||||
|
|
|
|||
|
|
@ -579,6 +579,19 @@ static int allocate_dmabuf(struct vulkan_base *s, VkFormat format, uint32_t modi
|
|||
return 0;
|
||||
}
|
||||
|
||||
int vulkan_validate_dmabuf_properties(const struct vulkan_modifier_info *modInfo, uint32_t *planeCount, struct spa_rectangle *dim)
|
||||
{
|
||||
if (planeCount) {
|
||||
if (*planeCount != modInfo->props.drmFormatModifierPlaneCount)
|
||||
return -1;
|
||||
}
|
||||
if (dim) {
|
||||
if (dim->width > modInfo->max_extent.width || dim->height > modInfo->max_extent.height)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vulkan_fixate_modifier(struct vulkan_base *s, struct dmabuf_fixation_info *info, uint64_t *modifier)
|
||||
{
|
||||
VULKAN_INSTANCE_FUNCTION(vkGetImageDrmFormatModifierPropertiesEXT);
|
||||
|
|
@ -617,11 +630,6 @@ int vulkan_create_dmabuf(struct vulkan_base *s, struct external_buffer_info *inf
|
|||
int fd = -1;
|
||||
VK_CHECK_RESULT(vkGetMemoryFdKHR(s->device, &getFdInfo, &fd));
|
||||
|
||||
const struct vulkan_modifier_info *modInfo = vulkan_modifierInfo_find(s, info->format, info->modifier);
|
||||
|
||||
if (info->spa_buf->n_datas != modInfo->props.drmFormatModifierPlaneCount)
|
||||
return -1;
|
||||
|
||||
VkMemoryRequirements memoryRequirements = {0};
|
||||
vkGetImageMemoryRequirements(s->device,
|
||||
vk_buf->image, &memoryRequirements);
|
||||
|
|
@ -671,18 +679,8 @@ int vulkan_import_dmabuf(struct vulkan_base *s, struct external_buffer_info *inf
|
|||
if (info->spa_buf->n_datas == 0 || info->spa_buf->n_datas > DMABUF_MAX_PLANES)
|
||||
return -1;
|
||||
|
||||
struct vulkan_modifier_info *modProps = vulkan_modifierInfo_find(s, info->format, info->modifier);
|
||||
if (!modProps)
|
||||
return -1;
|
||||
|
||||
uint32_t planeCount = info->spa_buf->n_datas;
|
||||
|
||||
if (planeCount != modProps->props.drmFormatModifierPlaneCount)
|
||||
return -1;
|
||||
|
||||
if (info->size.width > modProps->max_extent.width || info->size.height > modProps->max_extent.height)
|
||||
return -1;
|
||||
|
||||
VkSubresourceLayout planeLayouts[DMABUF_MAX_PLANES] = {0};
|
||||
for (uint32_t i = 0; i < planeCount; i++) {
|
||||
planeLayouts[i].offset = info->spa_buf->datas[i].chunk->offset;
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ int vulkan_read_pixels(struct vulkan_base *s, struct vulkan_read_pixels_info *in
|
|||
int vulkan_sync_foreign_dmabuf(struct vulkan_base *s, struct vulkan_buffer *vk_buf);
|
||||
bool vulkan_sync_export_dmabuf(struct vulkan_base *s, struct vulkan_buffer *vk_buf, int sync_file_fd);
|
||||
|
||||
int vulkan_validate_dmabuf_properties(const struct vulkan_modifier_info *modInfo, uint32_t *planeCount, struct spa_rectangle *dim);
|
||||
int vulkan_fixate_modifier(struct vulkan_base *s, struct dmabuf_fixation_info *info, uint64_t *modifier);
|
||||
int vulkan_create_dmabuf(struct vulkan_base *s, struct external_buffer_info *info, struct vulkan_buffer *vk_buf);
|
||||
int vulkan_import_dmabuf(struct vulkan_base *s, struct external_buffer_info *info, struct vulkan_buffer *vk_buf);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue