#include "util/slab.h"
#include "util/u_debug.h"
#include "util/format/u_format.h"
+#include "util/u_transfer_helper.h"
#include "util/u_inlines.h"
#include "util/u_memory.h"
VkMemoryRequirements reqs;
VkMemoryPropertyFlags flags = 0;
+
+ res->internal_format = templ->format;
if (templ->target == PIPE_BUFFER) {
VkBufferCreateInfo bci = {};
bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
return resource_create(pscreen, templ, whandle, usage);
}
-void
-zink_screen_resource_init(struct pipe_screen *pscreen)
-{
- pscreen->resource_create = zink_resource_create;
- pscreen->resource_destroy = zink_resource_destroy;
-
- if (zink_screen(pscreen)->have_KHR_external_memory_fd) {
- pscreen->resource_get_handle = zink_resource_get_handle;
- pscreen->resource_from_handle = zink_resource_from_handle;
- }
-}
-
static bool
zink_transfer_copy_bufimage(struct zink_context *ctx,
struct zink_resource *res,
zink_batch_reference_resoure(batch, res);
zink_batch_reference_resoure(batch, staging_res);
- unsigned aspects = res->aspect;
+ /* we're using u_transfer_helper_deinterleave, which means we'll be getting PIPE_TRANSFER_* usage
+ * to indicate whether to copy either the depth or stencil aspects
+ */
+ unsigned aspects = 0;
+ assert((trans->base.usage & (PIPE_TRANSFER_DEPTH_ONLY | PIPE_TRANSFER_STENCIL_ONLY)) !=
+ (PIPE_TRANSFER_DEPTH_ONLY | PIPE_TRANSFER_STENCIL_ONLY));
+ if (trans->base.usage & PIPE_TRANSFER_DEPTH_ONLY)
+ aspects = VK_IMAGE_ASPECT_DEPTH_BIT;
+ else if (trans->base.usage & PIPE_TRANSFER_STENCIL_ONLY)
+ aspects = VK_IMAGE_ASPECT_STENCIL_BIT;
+ else {
+ aspects = aspect_from_format(res->base.format);
+ }
while (aspects) {
int aspect = 1 << u_bit_scan(&aspects);
copyRegion.imageSubresource.aspectMask = aspect;
ptr = ((uint8_t *)ptr) + box->x;
} else {
if (res->optimial_tiling || ((res->base.usage != PIPE_USAGE_STAGING))) {
- trans->base.stride = util_format_get_stride(pres->format, box->width);
- trans->base.layer_stride = util_format_get_2d_size(pres->format,
+ enum pipe_format format = pres->format;
+ if (usage & PIPE_TRANSFER_DEPTH_ONLY)
+ format = util_format_get_depth_only(pres->format);
+ else if (usage & PIPE_TRANSFER_STENCIL_ONLY)
+ format = PIPE_FORMAT_S8_UINT;
+ trans->base.stride = util_format_get_stride(format, box->width);
+ trans->base.layer_stride = util_format_get_2d_size(format,
trans->base.stride,
box->height);
struct pipe_resource templ = *pres;
+ templ.format = format;
templ.usage = PIPE_USAGE_STAGING;
templ.target = PIPE_BUFFER;
templ.bind = 0;
slab_free(&ctx->transfer_pool, ptrans);
}
+static struct pipe_resource *
+zink_resource_get_separate_stencil(struct pipe_resource *pres)
+{
+ /* For packed depth-stencil, we treat depth as the primary resource
+ * and store S8 as the "second plane" resource.
+ */
+ if (pres->next && pres->next->format == PIPE_FORMAT_S8_UINT)
+ return pres->next;
+
+ return NULL;
+
+}
+
+void
+zink_get_depth_stencil_resources(struct pipe_resource *res,
+ struct zink_resource **out_z,
+ struct zink_resource **out_s)
+{
+ if (!res) {
+ if (out_z) *out_z = NULL;
+ if (out_s) *out_s = NULL;
+ return;
+ }
+
+ if (res->format != PIPE_FORMAT_S8_UINT) {
+ if (out_z) *out_z = zink_resource(res);
+ if (out_s) *out_s = zink_resource(zink_resource_get_separate_stencil(res));
+ } else {
+ if (out_z) *out_z = NULL;
+ if (out_s) *out_s = zink_resource(res);
+ }
+}
+
+static void
+zink_resource_set_separate_stencil(struct pipe_resource *pres,
+ struct pipe_resource *stencil)
+{
+ assert(util_format_has_depth(util_format_description(pres->format)));
+ pipe_resource_reference(&pres->next, stencil);
+}
+
+static enum pipe_format
+zink_resource_get_internal_format(struct pipe_resource *pres)
+{
+ struct zink_resource *res = zink_resource(pres);
+ return res->internal_format;
+}
+
+static const struct u_transfer_vtbl transfer_vtbl = {
+ .resource_create = zink_resource_create,
+ .resource_destroy = zink_resource_destroy,
+ .transfer_map = zink_transfer_map,
+ .transfer_unmap = zink_transfer_unmap,
+ .transfer_flush_region = u_default_transfer_flush_region,
+ .get_internal_format = zink_resource_get_internal_format,
+ .set_stencil = zink_resource_set_separate_stencil,
+ .get_stencil = zink_resource_get_separate_stencil,
+};
+
+void
+zink_screen_resource_init(struct pipe_screen *pscreen)
+{
+ pscreen->resource_create = zink_resource_create;
+ pscreen->resource_destroy = zink_resource_destroy;
+ pscreen->transfer_helper = u_transfer_helper_create(&transfer_vtbl, true, true, false, false);
+
+ if (zink_screen(pscreen)->have_KHR_external_memory_fd) {
+ pscreen->resource_get_handle = zink_resource_get_handle;
+ pscreen->resource_from_handle = zink_resource_from_handle;
+ }
+}
+
void
zink_context_resource_init(struct pipe_context *pctx)
{
- pctx->transfer_map = zink_transfer_map;
- pctx->transfer_unmap = zink_transfer_unmap;
+ pctx->transfer_map = u_transfer_helper_deinterleave_transfer_map;
+ pctx->transfer_unmap = u_transfer_helper_deinterleave_transfer_unmap;
- pctx->transfer_flush_region = u_default_transfer_flush_region;
+ pctx->transfer_flush_region = u_transfer_helper_transfer_flush_region;
pctx->buffer_subdata = u_default_buffer_subdata;
pctx->texture_subdata = u_default_texture_subdata;
}