mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 21:35:59 +00:00
fix(display): read linear client frames at their row pitch when the driver has no explicit modifier layouts (#2927)
* fix(display): read linear client frames at their row pitch when the driver has no explicit modifier layouts * fix(display): keep row-pitch copied client frames eligible for layer presentation * fix(display): order the readback layout change after the staging copy * fix(display): skip the modifier import query when the driver lacks VK_EXT_image_drm_format_modifier * test(display): the compositor's source-extracting tests follow the linear dma-buf helpers vkp_image_destroy now frees through destroy_image_objects, render_impl stages linear dma-bufs and the external-image release asks foreign_image; the two tests that compile these functions out of vk_present.c extract or stub them, with the image's new buffer fields in their fakes. --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
6f45b5347d
commit
3c0d25d83b
7 files changed
+488
-21
No files matched your search
@@ -0,0 +1,55 @@
|
||||
#ifndef VK_LINEAR_DMABUF_H
|
||||
#define VK_LINEAR_DMABUF_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static inline int vkp_linear_dmabuf_through_buffer(int drm_modifiers, uint64_t modifier, int blit_dst) {
|
||||
return !drm_modifiers && modifier == 0 && !blit_dst;
|
||||
}
|
||||
|
||||
static inline int vkp_linear_dmabuf_foreign_image(int dmabuf, int staged) {
|
||||
return dmabuf && !staged;
|
||||
}
|
||||
|
||||
static inline VkPipelineStageFlags vkp_linear_dmabuf_readback_stage(int in_general) {
|
||||
return in_general ? VK_PIPELINE_STAGE_TRANSFER_BIT : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||
}
|
||||
|
||||
static inline VkAccessFlags vkp_linear_dmabuf_readback_access(int in_general) {
|
||||
return in_general ? VK_ACCESS_TRANSFER_WRITE_BIT : 0;
|
||||
}
|
||||
|
||||
static inline uint32_t vkp_linear_dmabuf_texel_bytes(VkFormat fmt) {
|
||||
return fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? 8u : 4u;
|
||||
}
|
||||
|
||||
static inline VkDeviceSize vkp_linear_dmabuf_copy(VkFormat fmt, int w, int h, uint32_t stride, uint32_t offset,
|
||||
VkBufferImageCopy *copy) {
|
||||
const uint32_t texel = vkp_linear_dmabuf_texel_bytes(fmt);
|
||||
if (!copy || w <= 0 || h <= 0 || stride % texel || offset % texel || stride / texel < (uint32_t)w) return 0;
|
||||
*copy = (VkBufferImageCopy){
|
||||
.bufferOffset = offset,
|
||||
.bufferRowLength = stride / texel,
|
||||
.bufferImageHeight = (uint32_t)h,
|
||||
.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.imageExtent = {(uint32_t)w, (uint32_t)h, 1},
|
||||
};
|
||||
return (VkDeviceSize)offset + (VkDeviceSize)stride * (VkDeviceSize)(h - 1) + (VkDeviceSize)w * texel;
|
||||
}
|
||||
|
||||
static inline VkBufferMemoryBarrier vkp_linear_dmabuf_ownership(VkBuffer buffer, uint32_t queue_family,
|
||||
int acquire) {
|
||||
return (VkBufferMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
||||
.srcAccessMask = acquire ? 0 : VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.dstAccessMask = acquire ? VK_ACCESS_TRANSFER_READ_BIT : 0,
|
||||
.srcQueueFamilyIndex = acquire ? VK_QUEUE_FAMILY_FOREIGN_EXT : queue_family,
|
||||
.dstQueueFamilyIndex = acquire ? queue_family : VK_QUEUE_FAMILY_FOREIGN_EXT,
|
||||
.buffer = buffer,
|
||||
.offset = 0,
|
||||
.size = VK_WHOLE_SIZE,
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -23,6 +23,8 @@
|
||||
X(EndCommandBuffer) X(ResetFences) X(QueueSubmit) X(QueuePresentKHR) X(WaitForFences) \
|
||||
X(QueueWaitIdle) X(GetMemoryFdPropertiesKHR) X(GetAndroidHardwareBufferPropertiesANDROID) \
|
||||
X(GetImageSubresourceLayout) X(MapMemory) X(UnmapMemory) X(CmdClearColorImage) \
|
||||
X(CreateBuffer) X(DestroyBuffer) X(GetBufferMemoryRequirements) X(BindBufferMemory) \
|
||||
X(CmdCopyBufferToImage) \
|
||||
\
|
||||
X(CreateShaderModule) X(DestroyShaderModule) X(CreatePipelineLayout) X(DestroyPipelineLayout) \
|
||||
X(CreateGraphicsPipelines) X(DestroyPipeline) X(CreateRenderPass) X(DestroyRenderPass) \
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "vk_present.h"
|
||||
#include "vk_loader.h"
|
||||
#include "vk_external_image_sync.h"
|
||||
#include "vk_linear_dmabuf.h"
|
||||
#include "sc_layer.h"
|
||||
#include "effects_chain.h"
|
||||
#include "cardboard.h"
|
||||
@@ -42,10 +43,15 @@ struct vkp_image {
|
||||
VkFormat fmt;
|
||||
int sampled;
|
||||
AHardwareBuffer *android_buffer;
|
||||
int staged;
|
||||
VkBuffer linear_buf;
|
||||
VkDeviceMemory linear_mem;
|
||||
VkBufferImageCopy linear_copy;
|
||||
};
|
||||
|
||||
static ANativeWindow *g_window;
|
||||
static int g_ahb_import;
|
||||
static int g_drm_modifiers;
|
||||
static char *g_driver_path, *g_library_name, *g_native_lib_dir;
|
||||
static int g_allow_driver_fallback;
|
||||
static int g_dev_state;
|
||||
@@ -628,6 +634,7 @@ static int dev_init(void) {
|
||||
if (has_ext(exts, ne, import_exts[i])) dev_exts[n_dev_exts++] = import_exts[i];
|
||||
else LOGE("present: driver MISSING %s (dmabuf import will fail)", import_exts[i]);
|
||||
}
|
||||
g_drm_modifiers = has_ext(exts, ne, "VK_EXT_image_drm_format_modifier");
|
||||
int want_hdr_md = 0;
|
||||
if (droiddeck_color_requested()) {
|
||||
want_hdr_md = has_ext(exts, ne, VK_EXT_HDR_METADATA_EXTENSION_NAME);
|
||||
@@ -1088,6 +1095,10 @@ struct vkp_image *vkp_image_from_dmabuf(int fd, uint32_t drm_format, uint64_t mo
|
||||
return vkp_image_import_dmabuf(fd, drm_format, modifier, w, h, stride, offset, 0);
|
||||
}
|
||||
|
||||
static int foreign_image(const struct vkp_image *img) {
|
||||
return vkp_linear_dmabuf_foreign_image(img->dmabuf, img->staged);
|
||||
}
|
||||
|
||||
/* Return client sources to FOREIGN after their final read. The consuming paths
|
||||
* wait for our fence before Wayland can release an ordinary dma-buf or an
|
||||
* android_wlegl AHardwareBuffer. Producer-fence synchronization is separate from
|
||||
@@ -1095,7 +1106,7 @@ struct vkp_image *vkp_image_from_dmabuf(int fd, uint32_t drm_format, uint64_t mo
|
||||
static void release_external_client_image(VkCommandBuffer cmd, struct vkp_image *img) {
|
||||
struct vkp_external_client_barrier_pair pair;
|
||||
if (!img || !vkp_external_client_barrier_pair(
|
||||
img->image, g_qfam, img->dmabuf, img->blit_dst, &pair))
|
||||
img->image, g_qfam, foreign_image(img), img->blit_dst, &pair))
|
||||
return;
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, NULL, 0, NULL, 1, &pair.release);
|
||||
@@ -1109,6 +1120,37 @@ static void release_external_client_draws(VkCommandBuffer cmd, const struct vkp_
|
||||
}
|
||||
}
|
||||
|
||||
static void stage_linear_dmabuf(VkCommandBuffer cmd, const struct vkp_image *img) {
|
||||
if (!img || !img->linear_buf) return;
|
||||
const VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
VkBufferMemoryBarrier acquire = vkp_linear_dmabuf_ownership(img->linear_buf, g_qfam, 1);
|
||||
VkImageMemoryBarrier write = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = img->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0,
|
||||
0, NULL, 1, &acquire, 1, &write);
|
||||
g_vk.CmdCopyBufferToImage(cmd, img->linear_buf, img->image, VK_IMAGE_LAYOUT_GENERAL, 1, &img->linear_copy);
|
||||
VkBufferMemoryBarrier release = vkp_linear_dmabuf_ownership(img->linear_buf, g_qfam, 0);
|
||||
VkImageMemoryBarrier read = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = img->image, .subresourceRange = range, .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
|
||||
0, NULL, 1, &release, 1, &read);
|
||||
}
|
||||
|
||||
static void stage_linear_dmabufs(VkCommandBuffer cmd, const struct vkp_draw *draws, int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
int seen = 0;
|
||||
for (int j = 0; j < i; j++) if (draws[j].img == draws[i].img) { seen = 1; break; }
|
||||
if (!seen) stage_linear_dmabuf(cmd, draws[i].img);
|
||||
}
|
||||
}
|
||||
|
||||
int vkp_image_is_dmabuf(const struct vkp_image *img) {
|
||||
return img && vkp_is_external_client_image(img->dmabuf, img->blit_dst);
|
||||
}
|
||||
@@ -1181,6 +1223,102 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int optimal_sampled(VkFormat fmt) {
|
||||
if (!g_vk.GetPhysicalDeviceFormatProperties2) return 0;
|
||||
VkFormatProperties2 fp = {.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
|
||||
g_vk.GetPhysicalDeviceFormatProperties2(g_pd, fmt, &fp);
|
||||
const VkFormatFeatureFlags need = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
|
||||
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
return (fp.formatProperties.optimalTilingFeatures & need) == need;
|
||||
}
|
||||
|
||||
static void destroy_image_objects(struct vkp_image *img) {
|
||||
if (img->image) g_vk.DestroyImage(g_dev, img->image, NULL);
|
||||
if (img->mem) g_vk.FreeMemory(g_dev, img->mem, NULL);
|
||||
if (img->linear_buf) g_vk.DestroyBuffer(g_dev, img->linear_buf, NULL);
|
||||
if (img->linear_mem) g_vk.FreeMemory(g_dev, img->linear_mem, NULL);
|
||||
img->image = VK_NULL_HANDLE; img->mem = VK_NULL_HANDLE;
|
||||
img->linear_buf = VK_NULL_HANDLE; img->linear_mem = VK_NULL_HANDLE;
|
||||
img->staged = 0; img->in_general = 0;
|
||||
}
|
||||
|
||||
static int import_linear_dmabuf(struct vkp_image *img, int fd, const VkBufferImageCopy *copy, VkDeviceSize need) {
|
||||
int dupfd = dup(fd);
|
||||
if (dupfd < 0) return -1;
|
||||
VkDeviceSize size = need;
|
||||
off_t end = lseek(dupfd, 0, SEEK_END);
|
||||
if (end > 0 && (VkDeviceSize)end >= need) size = (VkDeviceSize)end;
|
||||
lseek(dupfd, 0, SEEK_SET);
|
||||
if (end > 0 && (VkDeviceSize)end < need) {
|
||||
LOGE("dmabuf: the linear %dx%d buffer holds %lld bytes, its row pitch needs %llu", img->w, img->h,
|
||||
(long long)end, (unsigned long long)need);
|
||||
close(dupfd);
|
||||
return -1;
|
||||
}
|
||||
VkExternalMemoryBufferCreateInfo ext = {
|
||||
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
|
||||
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT};
|
||||
VkBufferCreateInfo bci = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .pNext = &ext, .size = size,
|
||||
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
|
||||
VkResult r = g_vk.CreateBuffer(g_dev, &bci, NULL, &img->linear_buf);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
uint32_t allowed = 0xffffffff;
|
||||
if (g_vk.GetMemoryFdPropertiesKHR) {
|
||||
VkMemoryFdPropertiesKHR fp = {.sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR};
|
||||
if (g_vk.GetMemoryFdPropertiesKHR(g_dev, VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
|
||||
dupfd, &fp) == VK_SUCCESS)
|
||||
allowed = fp.memoryTypeBits;
|
||||
}
|
||||
VkMemoryRequirements breq;
|
||||
g_vk.GetBufferMemoryRequirements(g_dev, img->linear_buf, &breq);
|
||||
int bidx = memory_type(breq.memoryTypeBits & allowed, 0);
|
||||
r = VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
if (bidx < 0) goto fail;
|
||||
VkImportMemoryFdInfoKHR imp = {.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
|
||||
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, .fd = dupfd};
|
||||
VkMemoryDedicatedAllocateInfo ded = {.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
|
||||
.pNext = &imp, .buffer = img->linear_buf};
|
||||
VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .pNext = &ded,
|
||||
.allocationSize = breq.size, .memoryTypeIndex = (uint32_t)bidx};
|
||||
r = g_vk.AllocateMemory(g_dev, &mai, NULL, &img->linear_mem);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
dupfd = -1;
|
||||
r = g_vk.BindBufferMemory(g_dev, img->linear_buf, img->linear_mem, 0);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
|
||||
VkImageCreateInfo ici = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, .format = img->fmt,
|
||||
.extent = {(uint32_t)img->w, (uint32_t)img->h, 1}, .mipLevels = 1, .arrayLayers = 1,
|
||||
.samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL,
|
||||
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
|
||||
(img->sampled ? VK_IMAGE_USAGE_SAMPLED_BIT : 0),
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED};
|
||||
r = g_vk.CreateImage(g_dev, &ici, NULL, &img->image);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
VkMemoryRequirements ireq;
|
||||
g_vk.GetImageMemoryRequirements(g_dev, img->image, &ireq);
|
||||
int iidx = memory_type(ireq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||
if (iidx < 0) iidx = memory_type(ireq.memoryTypeBits, 0);
|
||||
r = VK_ERROR_FORMAT_NOT_SUPPORTED;
|
||||
if (iidx < 0) goto fail;
|
||||
VkMemoryAllocateInfo iai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||
.allocationSize = ireq.size, .memoryTypeIndex = (uint32_t)iidx};
|
||||
r = g_vk.AllocateMemory(g_dev, &iai, NULL, &img->mem);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
r = g_vk.BindImageMemory(g_dev, img->image, img->mem, 0);
|
||||
if (r != VK_SUCCESS) goto fail;
|
||||
img->linear_copy = *copy;
|
||||
img->staged = 1;
|
||||
img->in_general = 1;
|
||||
return 0;
|
||||
fail:
|
||||
LOGE("dmabuf: reading the linear %dx%d buffer at its row pitch failed (%s); importing it as an image",
|
||||
img->w, img->h, vk_result_name(r));
|
||||
if (dupfd >= 0) close(dupfd);
|
||||
destroy_image_objects(img);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, int w, int h,
|
||||
uint32_t stride, uint32_t offset, int as_blit_dst) {
|
||||
if (modifier == MOD_INVALID || w <= 0 || h <= 0) return NULL;
|
||||
@@ -1190,9 +1328,11 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
if (!img) return NULL;
|
||||
img->w = w; img->h = h; img->dmabuf = 1; img->blit_dst = as_blit_dst ? 1 : 0;
|
||||
img->fmt = drm_to_vk(drm_format);
|
||||
const int through_buffer = vkp_linear_dmabuf_through_buffer(g_drm_modifiers, modifier, as_blit_dst);
|
||||
const VkImageUsageFlags sampled_usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||
img->sampled = !as_blit_dst && g_vk.GetPhysicalDeviceImageFormatProperties2 &&
|
||||
modifier_importable(img->fmt, modifier, sampled_usage);
|
||||
const int modifier_sampled = !as_blit_dst && g_drm_modifiers && g_vk.GetPhysicalDeviceImageFormatProperties2 &&
|
||||
modifier_importable(img->fmt, modifier, sampled_usage);
|
||||
img->sampled = through_buffer ? optimal_sampled(img->fmt) : modifier_sampled;
|
||||
/* Each new format/modifier/size a client hands over, once, for the graphics report: a colour
|
||||
* or swizzle mismatch on a non-Adreno driver shows up as the pair it arrived as. */
|
||||
{
|
||||
@@ -1203,10 +1343,11 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
if (seen[i].fmt == drm_format && seen[i].mod == modifier && seen[i].w == w && seen[i].h == h) known = 1;
|
||||
if (!known && nseen < 32) {
|
||||
seen[nseen].fmt = drm_format; seen[nseen].mod = modifier; seen[nseen].w = w; seen[nseen].h = h; nseen++;
|
||||
droiddeck_log("gpu", "dmabuf import: %c%c%c%c %s %dx%d stride %u offset %u -> vk format %d, %s%s",
|
||||
droiddeck_log("gpu", "dmabuf import: %c%c%c%c %s %dx%d stride %u offset %u -> vk format %d, %s%s%s",
|
||||
drm_format & 0xff, (drm_format >> 8) & 0xff, (drm_format >> 16) & 0xff, (drm_format >> 24) & 0xff,
|
||||
vkp_modifier_name(modifier), w, h, stride, offset, (int)img->fmt,
|
||||
img->sampled ? "sampled" : "copied", as_blit_dst ? ", blit target" : "");
|
||||
img->sampled ? "sampled" : "copied", as_blit_dst ? ", blit target" : "",
|
||||
through_buffer ? ", trying a copy at its row pitch (no VK_EXT_image_drm_format_modifier)" : "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1214,6 +1355,12 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
* vkCreateImage, which left the whole window unshown (David Cimo). One packed, 64-byte aligned
|
||||
* row is what a linear buffer that small holds. */
|
||||
if (stride == 0 && modifier == 0) stride = ((uint32_t)w * 4 + 63) & ~63u;
|
||||
if (through_buffer) {
|
||||
VkBufferImageCopy linear_copy;
|
||||
const VkDeviceSize linear_size = vkp_linear_dmabuf_copy(img->fmt, w, h, stride, offset, &linear_copy);
|
||||
if (linear_size && import_linear_dmabuf(img, fd, &linear_copy, linear_size) == 0) return img;
|
||||
img->sampled = modifier_sampled;
|
||||
}
|
||||
VkSubresourceLayout plane = {.offset = offset, .rowPitch = stride};
|
||||
VkImageDrmFormatModifierExplicitCreateInfoEXT modInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT,
|
||||
@@ -1501,8 +1648,7 @@ void vkp_image_destroy(struct vkp_image *img) {
|
||||
if (g_dev) {
|
||||
blendp_forget_image(img->image);
|
||||
if (img->map) g_vk.UnmapMemory(g_dev, img->mem);
|
||||
if (img->image) g_vk.DestroyImage(g_dev, img->image, NULL);
|
||||
if (img->mem) g_vk.FreeMemory(g_dev, img->mem, NULL);
|
||||
destroy_image_objects(img);
|
||||
}
|
||||
if (img->android_buffer) AHardwareBuffer_release(img->android_buffer);
|
||||
free(img);
|
||||
@@ -1600,7 +1746,7 @@ static void effects_source_note(int scene_w, int scene_h, const struct vkp_draw
|
||||
static void record_draw(VkCommandBuffer cmd, const struct vkp_draw *d, const VkImageBlit *blit, VkImage target,
|
||||
VkFormat target_fmt, int target_w, int target_h, VkFilter filter) {
|
||||
const struct vkp_image *im = d->img;
|
||||
const int external_client = vkp_image_is_dmabuf(im);
|
||||
const int external_client = vkp_is_external_client_image(foreign_image(im), im->blit_dst);
|
||||
if (d->blend && im->sampled &&
|
||||
blendp_draw(cmd, im->image, im->fmt, im->w, im->h, !external_client,
|
||||
target, target_fmt, target_w, target_h,
|
||||
@@ -2084,6 +2230,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
g_vk.BeginCommandBuffer(cmd, &bi);
|
||||
blendp_begin_frame();
|
||||
stage_linear_dmabufs(cmd, draws, n);
|
||||
VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
|
||||
VkImageMemoryBarrier *bars = calloc((size_t)n + 1, sizeof(*bars));
|
||||
@@ -2101,7 +2248,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
if (seen || !im) continue;
|
||||
struct vkp_external_client_barrier_pair pair;
|
||||
if (vkp_external_client_barrier_pair(
|
||||
im->image, g_qfam, im->dmabuf, im->blit_dst, &pair)) {
|
||||
im->image, g_qfam, foreign_image(im), im->blit_dst, &pair)) {
|
||||
bars[nb++] = pair.acquire;
|
||||
} else if (!im->blit_dst && !im->in_general) {
|
||||
bars[nb++] = (VkImageMemoryBarrier){
|
||||
@@ -2383,9 +2530,10 @@ int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) {
|
||||
VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
g_vk.BeginCommandBuffer(g_cmd, &bi);
|
||||
stage_linear_dmabuf(g_cmd, src);
|
||||
struct vkp_external_client_barrier_pair src_pair;
|
||||
const int src_external = vkp_external_client_barrier_pair(
|
||||
src->image, g_qfam, src->dmabuf, src->blit_dst, &src_pair);
|
||||
src->image, g_qfam, foreign_image(src), src->blit_dst, &src_pair);
|
||||
VkImageMemoryBarrier acq[2] = {
|
||||
src_external ? src_pair.acquire : (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
@@ -2489,22 +2637,26 @@ int vkp_image_readback(struct vkp_image *src, uint32_t *out, int max_px) {
|
||||
VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
g_vk.BeginCommandBuffer(cmd, &bi);
|
||||
stage_linear_dmabuf(cmd, src);
|
||||
struct vkp_external_client_barrier_pair src_pair;
|
||||
const int src_external = vkp_external_client_barrier_pair(
|
||||
src->image, g_qfam, src->dmabuf, src->blit_dst, &src_pair);
|
||||
src->image, g_qfam, foreign_image(src), src->blit_dst, &src_pair);
|
||||
VkImageMemoryBarrier acq[2] = {
|
||||
src_external ? src_pair.acquire : (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.oldLayout = src->in_general ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = src->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT},
|
||||
.image = src->image, .subresourceRange = range,
|
||||
.srcAccessMask = vkp_linear_dmabuf_readback_access(src->in_general),
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT},
|
||||
{.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = g_rb->image, .subresourceRange = range,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}};
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 0, NULL, 0, NULL, 2, acq);
|
||||
g_vk.CmdPipelineBarrier(cmd, vkp_linear_dmabuf_readback_stage(src->in_general),
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 2, acq);
|
||||
VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.srcOffsets = {{0, 0, 0}, {src->w, src->h, 1}},
|
||||
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
@@ -2602,6 +2754,7 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
g_vk.BeginCommandBuffer(cmd, &bi);
|
||||
blendp_begin_frame();
|
||||
stage_linear_dmabufs(cmd, draws, n);
|
||||
VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
|
||||
VkImageMemoryBarrier *bars = calloc((size_t)n + 1, sizeof(*bars));
|
||||
@@ -2620,7 +2773,7 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
if (seen || !im) continue;
|
||||
struct vkp_external_client_barrier_pair pair;
|
||||
if (vkp_external_client_barrier_pair(
|
||||
im->image, g_qfam, im->dmabuf, im->blit_dst, &pair)) {
|
||||
im->image, g_qfam, foreign_image(im), im->blit_dst, &pair)) {
|
||||
bars[nb++] = pair.acquire;
|
||||
} else if (!im->blit_dst && !im->in_general) {
|
||||
bars[nb++] = (VkImageMemoryBarrier){
|
||||
|
||||
@@ -26,7 +26,7 @@ class EffectsSourceResolutionTest(unittest.TestCase):
|
||||
header = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_present.h').read_text()
|
||||
effects = (REPO / 'app/src/main/cpp/waylandcomp/src/effects_chain.c').read_text()
|
||||
functions = '\n'.join(function(source, signature) for signature in (
|
||||
'static void release_external_client_image(', 'static void release_external_client_draws(',
|
||||
'static int foreign_image(', 'static void release_external_client_image(', 'static void release_external_client_draws(',
|
||||
'static int map_draw(', 'static int draw_to_blit(',
|
||||
'static int draw_to_scene_blit(', 'static int effects_source_draw(',
|
||||
'static void effects_source_note(',
|
||||
@@ -113,7 +113,7 @@ TYPES = r'''
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
typedef int VkImage, VkDeviceMemory, VkFormat, VkCommandBuffer, VkResult, VkFilter;
|
||||
typedef int VkImage, VkDeviceMemory, VkFormat, VkCommandBuffer, VkResult, VkFilter, VkBuffer;
|
||||
typedef int VkImageLayout, VkPipelineStageFlags, VkImageUsageFlags;
|
||||
typedef uint64_t VkDeviceSize;
|
||||
typedef struct { unsigned width, height; } VkExtent2D;
|
||||
@@ -126,6 +126,13 @@ typedef struct {
|
||||
VkImageSubresourceLayers dstSubresource;
|
||||
VkOffset3D dstOffsets[2];
|
||||
} VkImageBlit;
|
||||
typedef struct {
|
||||
VkDeviceSize bufferOffset;
|
||||
unsigned bufferRowLength, bufferImageHeight;
|
||||
VkImageSubresourceLayers imageSubresource;
|
||||
VkOffset3D imageOffset;
|
||||
struct { unsigned width, height, depth; } imageExtent;
|
||||
} VkBufferImageCopy;
|
||||
typedef struct { int sType, flags; } VkCommandBufferBeginInfo;
|
||||
typedef struct {
|
||||
int sType, oldLayout, newLayout, srcQueueFamilyIndex, dstQueueFamilyIndex;
|
||||
@@ -161,6 +168,8 @@ typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
|
||||
|
||||
STUBS = r'''
|
||||
static void stage_linear_dmabufs(VkCommandBuffer cmd, const struct vkp_draw *draws, int count) { (void)cmd; (void)draws; (void)count; }
|
||||
static int vkp_linear_dmabuf_foreign_image(int dmabuf, int staged) { return dmabuf && !staged; }
|
||||
static void quarantine_pending_work(VkResult result, const char *where) { (void)result; (void)where; }
|
||||
static int noop(int handle, ...) { return VK_SUCCESS; }
|
||||
static VkImageMemoryBarrier recorded_barriers[64];
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tools.tests.test_vk_external_image_sync import vulkan_include_args
|
||||
from tools.tests.test_vk_pending_completion import function
|
||||
|
||||
TESTS = Path(__file__).resolve().parent
|
||||
SRC = TESTS.parents[1] / "app/src/main/cpp/waylandcomp/src"
|
||||
|
||||
LAYER_HARNESS = r'''
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "vk_external_image_sync.h"
|
||||
#include "vk_linear_dmabuf.h"
|
||||
|
||||
typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
%(image)s
|
||||
struct vkp_draw {
|
||||
struct vkp_image *img;
|
||||
float sx, sy, sw, sh;
|
||||
int dx, dy, dw, dh;
|
||||
int blend;
|
||||
};
|
||||
struct draw_list { struct vkp_draw *d; int n, cap; };
|
||||
static const uint32_t g_qfam = 2;
|
||||
%(foreign)s
|
||||
%(is_dmabuf)s
|
||||
%(width)s
|
||||
%(height)s
|
||||
%(candidate)s
|
||||
|
||||
static int candidate(struct vkp_image *img) {
|
||||
struct vkp_draw d = {.img = img, .sw = 1560, .sh = 720, .dw = 1560, .dh = 720};
|
||||
struct draw_list dl = {.d = &d, .n = 1, .cap = 1};
|
||||
return layer_candidate(&dl, 1560, 720);
|
||||
}
|
||||
|
||||
static int foreign_pair(struct vkp_image *img) {
|
||||
struct vkp_external_client_barrier_pair pair;
|
||||
return vkp_external_client_barrier_pair(img->image, g_qfam, foreign_image(img), img->blit_dst, &pair);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct vkp_image staged = {.w = 1560, .h = 720, .dmabuf = 1, .staged = 1};
|
||||
assert(candidate(&staged) == 0);
|
||||
assert(!foreign_pair(&staged));
|
||||
|
||||
struct vkp_image client = {.w = 1560, .h = 720, .dmabuf = 1};
|
||||
assert(candidate(&client) == 0);
|
||||
assert(foreign_pair(&client));
|
||||
|
||||
struct vkp_image shm = {.w = 1560, .h = 720};
|
||||
assert(candidate(&shm) == -1);
|
||||
assert(!foreign_pair(&shm));
|
||||
|
||||
struct vkp_image layer = {.w = 1560, .h = 720, .dmabuf = 1, .blit_dst = 1};
|
||||
assert(candidate(&layer) == -1);
|
||||
assert(!foreign_pair(&layer));
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def compile_and_run(test, source, tmp, name):
|
||||
compiler = shutil.which(os.environ.get("CC", "cc"))
|
||||
if not compiler:
|
||||
test.fail("A C compiler is required for the linear dma-buf regression tests")
|
||||
program = Path(tmp) / name
|
||||
command = [
|
||||
compiler,
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-UNDEBUG",
|
||||
"-I",
|
||||
str(SRC),
|
||||
*vulkan_include_args(),
|
||||
str(source),
|
||||
"-o",
|
||||
str(program),
|
||||
]
|
||||
built = subprocess.run(command, capture_output=True, text=True)
|
||||
test.assertEqual(built.returncode, 0, built.stdout + built.stderr)
|
||||
ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30)
|
||||
test.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
|
||||
|
||||
|
||||
class VkLinearDmabufTest(unittest.TestCase):
|
||||
def test_linear_dmabuf_copy(self):
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-vk-linear-") as tmp:
|
||||
compile_and_run(self, TESTS / "vk_linear_dmabuf_test.c", tmp, "vk-linear-dmabuf")
|
||||
|
||||
def test_readback_orders_general_transition_after_staging_copy(self):
|
||||
body = function((SRC / "vk_present.c").read_text(), "vkp_image_readback")
|
||||
stage = body.index("stage_linear_dmabuf(cmd, src);")
|
||||
barrier = body.index("vkp_linear_dmabuf_readback_stage(src->in_general)")
|
||||
self.assertLess(stage, barrier)
|
||||
self.assertIn(".srcAccessMask = vkp_linear_dmabuf_readback_access(src->in_general)", body[stage:barrier])
|
||||
self.assertNotIn("CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT", body)
|
||||
|
||||
def test_modifier_query_needs_drm_modifier_extension(self):
|
||||
body = function((SRC / "vk_present.c").read_text(), "vkp_image_import_dmabuf")
|
||||
query = re.search(r"const int modifier_sampled = (.*?);", body, re.S)
|
||||
self.assertIsNotNone(query, "modifier_sampled not found in vkp_image_import_dmabuf")
|
||||
terms = [t.strip() for t in query.group(1).split("&&")]
|
||||
self.assertIn("g_drm_modifiers", terms)
|
||||
self.assertLess(terms.index("g_drm_modifiers"), terms.index("modifier_importable(img->fmt, modifier, sampled_usage)"))
|
||||
self.assertIn("!as_blit_dst", terms)
|
||||
self.assertIn("g_vk.GetPhysicalDeviceImageFormatProperties2", terms)
|
||||
|
||||
def test_staged_client_image_stays_layer_candidate(self):
|
||||
vk = (SRC / "vk_present.c").read_text()
|
||||
comp = (SRC / "compositor.c").read_text()
|
||||
image = re.search(r"^struct vkp_image \{.*?^\};", vk, re.M | re.S)
|
||||
self.assertIsNotNone(image, "struct vkp_image not found in vk_present.c")
|
||||
harness = LAYER_HARNESS % {
|
||||
"image": image.group(0),
|
||||
"foreign": function(vk, "foreign_image"),
|
||||
"is_dmabuf": function(vk, "vkp_image_is_dmabuf"),
|
||||
"width": function(vk, "vkp_image_width"),
|
||||
"height": function(vk, "vkp_image_height"),
|
||||
"candidate": function(comp, "layer_candidate"),
|
||||
}
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-vk-linear-layer-") as tmp:
|
||||
source = Path(tmp) / "layer_candidate_test.c"
|
||||
source.write_text(harness)
|
||||
compile_and_run(self, source, tmp, "vk-linear-layer")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -56,16 +56,20 @@ static VkResult wait_fn(uintptr_t dev, unsigned n, const VkFence *f, int all, ui
|
||||
static void unmap_fn(uintptr_t dev, uintptr_t mem) { (void)dev; (void)mem; ++unmapped; }
|
||||
static void destroy_fn(uintptr_t dev, uintptr_t img, void *allocator) { (void)dev; (void)img; (void)allocator; ++destroyed; }
|
||||
static void free_fn(uintptr_t dev, uintptr_t mem, void *allocator) { (void)dev; (void)mem; (void)allocator; ++freed_memory; }
|
||||
static unsigned destroyed_buffers;
|
||||
static void destroy_buffer_fn(uintptr_t dev, uintptr_t buf, void *allocator) { (void)dev; (void)buf; (void)allocator; ++destroyed_buffers; }
|
||||
#define VK_NULL_HANDLE 0
|
||||
static struct {
|
||||
VkResult (*WaitForFences)(uintptr_t, unsigned, const VkFence *, int, uint64_t);
|
||||
void (*UnmapMemory)(uintptr_t, uintptr_t);
|
||||
void (*DestroyImage)(uintptr_t, uintptr_t, void *);
|
||||
void (*FreeMemory)(uintptr_t, uintptr_t, void *);
|
||||
} g_vk = {wait_fn, unmap_fn, destroy_fn, free_fn};
|
||||
void (*DestroyBuffer)(uintptr_t, uintptr_t, void *);
|
||||
} g_vk = {wait_fn, unmap_fn, destroy_fn, free_fn, destroy_buffer_fn};
|
||||
typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
static int released_buffers;
|
||||
static void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; ++released_buffers; }
|
||||
struct vkp_image { uintptr_t image, mem; void *map; AHardwareBuffer *android_buffer; };
|
||||
struct vkp_image { uintptr_t image, mem; void *map; AHardwareBuffer *android_buffer; uintptr_t linear_buf, linear_mem; int staged, in_general; };
|
||||
static void blendp_forget_image(uintptr_t image) { (void)image; ++forgotten; }
|
||||
/* PRODUCTION_FUNCTIONS */
|
||||
static struct vkp_image *image(void) {
|
||||
@@ -173,7 +177,7 @@ class VkPendingCompletionTest(unittest.TestCase):
|
||||
self.assertEqual(ran.returncode,0,ran.stdout+ran.stderr)
|
||||
|
||||
def test_unknown_completion_retains_gpu_resources(self):
|
||||
self.compile_and_run(HARNESS, ['quarantine_pending_work', 'timed_wait', 'vkp_image_destroy'])
|
||||
self.compile_and_run(HARNESS, ['quarantine_pending_work', 'timed_wait', 'destroy_image_objects', 'vkp_image_destroy'])
|
||||
|
||||
def test_failed_device_idle_does_not_destroy_swapchain(self):
|
||||
# LOGE's arguments must be evaluated as real production logging does.
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vk_linear_dmabuf.h"
|
||||
|
||||
static void check_padded_rows(void) {
|
||||
VkBufferImageCopy copy;
|
||||
memset(©, 0xa5, sizeof(copy));
|
||||
const VkDeviceSize need = vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6400, 0, ©);
|
||||
assert(copy.bufferRowLength == 1600);
|
||||
assert(copy.bufferRowLength != 1560);
|
||||
assert(copy.bufferOffset == 0);
|
||||
assert(copy.bufferImageHeight == 720);
|
||||
assert(copy.imageSubresource.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
assert(copy.imageSubresource.mipLevel == 0);
|
||||
assert(copy.imageSubresource.baseArrayLayer == 0);
|
||||
assert(copy.imageSubresource.layerCount == 1);
|
||||
assert(copy.imageOffset.x == 0 && copy.imageOffset.y == 0 && copy.imageOffset.z == 0);
|
||||
assert(copy.imageExtent.width == 1560);
|
||||
assert(copy.imageExtent.height == 720);
|
||||
assert(copy.imageExtent.depth == 1);
|
||||
assert(need == (VkDeviceSize)6400 * 719 + 1560 * 4);
|
||||
}
|
||||
|
||||
static void check_offset_and_wide_texels(void) {
|
||||
VkBufferImageCopy copy;
|
||||
const VkDeviceSize need = vkp_linear_dmabuf_copy(VK_FORMAT_R16G16B16A16_SFLOAT, 1920, 1080, 15360, 4096, ©);
|
||||
assert(copy.bufferRowLength == 1920);
|
||||
assert(copy.bufferOffset == 4096);
|
||||
assert(need == 4096 + (VkDeviceSize)15360 * 1079 + 1920 * 8);
|
||||
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_B8G8R8A8_UNORM, 1, 1, 64, 0, ©) == 4);
|
||||
assert(copy.bufferRowLength == 16);
|
||||
}
|
||||
|
||||
static void check_rejected_layouts(void) {
|
||||
VkBufferImageCopy copy;
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6236, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6402, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6400, 2, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R16G16B16A16_SFLOAT, 1560, 720, 6240, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 0, 720, 6400, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 0, 6400, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6400, 0, NULL) == 0);
|
||||
}
|
||||
|
||||
static void check_path_choice(void) {
|
||||
const uint64_t linear = 0;
|
||||
const uint64_t qcom_compressed = 0x0500000000000001ULL;
|
||||
assert(vkp_linear_dmabuf_through_buffer(0, linear, 0));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(1, linear, 0));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(1, qcom_compressed, 0));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(0, qcom_compressed, 0));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(0, linear, 1));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(1, linear, 1));
|
||||
}
|
||||
|
||||
static void check_foreign_image(void) {
|
||||
assert(vkp_linear_dmabuf_foreign_image(1, 0));
|
||||
assert(!vkp_linear_dmabuf_foreign_image(1, 1));
|
||||
assert(!vkp_linear_dmabuf_foreign_image(0, 0));
|
||||
assert(!vkp_linear_dmabuf_foreign_image(0, 1));
|
||||
}
|
||||
|
||||
static void check_readback_order(void) {
|
||||
assert(vkp_linear_dmabuf_readback_stage(1) & VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
assert(vkp_linear_dmabuf_readback_access(1) & VK_ACCESS_TRANSFER_WRITE_BIT);
|
||||
assert(vkp_linear_dmabuf_readback_stage(0) == VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
assert(vkp_linear_dmabuf_readback_access(0) == 0);
|
||||
}
|
||||
|
||||
static void check_ownership(void) {
|
||||
const VkBuffer buffer = (VkBuffer)(uintptr_t)0x4321;
|
||||
const uint32_t queue_family = 3;
|
||||
const VkBufferMemoryBarrier acquire = vkp_linear_dmabuf_ownership(buffer, queue_family, 1);
|
||||
assert(acquire.sType == VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER);
|
||||
assert(acquire.pNext == NULL);
|
||||
assert(acquire.srcQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT);
|
||||
assert(acquire.dstQueueFamilyIndex == queue_family);
|
||||
assert(acquire.srcAccessMask == 0);
|
||||
assert(acquire.dstAccessMask == VK_ACCESS_TRANSFER_READ_BIT);
|
||||
assert(acquire.buffer == buffer);
|
||||
assert(acquire.offset == 0);
|
||||
assert(acquire.size == VK_WHOLE_SIZE);
|
||||
|
||||
const VkBufferMemoryBarrier release = vkp_linear_dmabuf_ownership(buffer, queue_family, 0);
|
||||
assert(release.sType == VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER);
|
||||
assert(release.srcQueueFamilyIndex == queue_family);
|
||||
assert(release.dstQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT);
|
||||
assert(release.srcAccessMask == VK_ACCESS_TRANSFER_READ_BIT);
|
||||
assert(release.dstAccessMask == 0);
|
||||
assert(release.buffer == buffer);
|
||||
assert(release.size == VK_WHOLE_SIZE);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
check_padded_rows();
|
||||
check_offset_and_wide_texels();
|
||||
check_rejected_layouts();
|
||||
check_path_choice();
|
||||
check_foreign_image();
|
||||
check_readback_order();
|
||||
check_ownership();
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user