2018-08-31 15:50:20 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Collabora Ltd.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* on the rights to use, copy, modify, merge, publish, distribute, sub
|
|
|
|
* license, and/or sell copies of the Software, and to permit persons to whom
|
|
|
|
* the Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZINK_RESOURCE_H
|
|
|
|
#define ZINK_RESOURCE_H
|
|
|
|
|
|
|
|
struct pipe_screen;
|
|
|
|
struct sw_displaytarget;
|
2020-06-14 05:01:07 +01:00
|
|
|
struct zink_batch;
|
2020-09-15 23:26:39 +01:00
|
|
|
struct zink_context;
|
2021-05-13 12:33:44 +01:00
|
|
|
struct zink_bo;
|
2021-03-12 22:42:28 +00:00
|
|
|
|
2021-08-31 14:57:30 +01:00
|
|
|
#include "util/hash_table.h"
|
2020-12-25 00:43:10 +00:00
|
|
|
#include "util/simple_mtx.h"
|
2018-08-31 15:50:20 +01:00
|
|
|
#include "util/u_transfer.h"
|
2020-09-03 15:44:11 +01:00
|
|
|
#include "util/u_range.h"
|
2020-10-02 18:40:40 +01:00
|
|
|
#include "util/u_dynarray.h"
|
2021-03-22 15:01:30 +00:00
|
|
|
#include "util/u_threaded_context.h"
|
2018-08-31 15:50:20 +01:00
|
|
|
|
2020-11-05 17:39:50 +00:00
|
|
|
#include "zink_batch.h"
|
2020-10-06 00:51:27 +01:00
|
|
|
#include "zink_descriptors.h"
|
2020-10-04 15:07:29 +01:00
|
|
|
|
2018-08-31 15:50:20 +01:00
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
2021-05-08 00:08:18 +01:00
|
|
|
#define ZINK_MAP_TEMPORARY (PIPE_MAP_DRV_PRV << 0)
|
2021-09-15 20:10:07 +01:00
|
|
|
#define ZINK_BIND_TRANSIENT (1 << 30) //transient fb attachment
|
2021-05-08 00:08:18 +01:00
|
|
|
|
2020-10-13 14:42:07 +01:00
|
|
|
struct mem_key {
|
2021-05-07 21:05:51 +01:00
|
|
|
unsigned seen_count;
|
|
|
|
struct {
|
|
|
|
unsigned heap_index;
|
|
|
|
VkMemoryRequirements reqs;
|
|
|
|
} key;
|
2020-10-13 14:42:07 +01:00
|
|
|
};
|
|
|
|
|
2020-10-27 15:38:16 +00:00
|
|
|
struct zink_resource_object {
|
|
|
|
struct pipe_reference reference;
|
2021-06-11 14:33:43 +01:00
|
|
|
|
2021-09-08 20:25:01 +01:00
|
|
|
VkPipelineStageFlagBits access_stage;
|
|
|
|
VkAccessFlags access;
|
|
|
|
bool unordered_barrier;
|
|
|
|
|
2021-06-11 14:33:43 +01:00
|
|
|
unsigned persistent_maps; //if nonzero, requires vkFlushMappedMemoryRanges during batch use
|
|
|
|
struct zink_descriptor_refs desc_set_refs;
|
|
|
|
|
|
|
|
struct util_dynarray tmp;
|
|
|
|
|
2020-10-27 15:38:16 +00:00
|
|
|
union {
|
|
|
|
VkBuffer buffer;
|
|
|
|
VkImage image;
|
|
|
|
};
|
2020-12-12 06:45:29 +00:00
|
|
|
|
2021-06-11 14:33:43 +01:00
|
|
|
VkSampleLocationsInfoEXT zs_evaluate;
|
|
|
|
bool needs_zs_evaluate;
|
|
|
|
|
2020-12-12 06:45:29 +00:00
|
|
|
bool storage_init; //layout was set for image
|
2021-02-03 20:35:49 +00:00
|
|
|
bool transfer_dst;
|
2021-06-11 14:33:43 +01:00
|
|
|
bool is_buffer;
|
2020-12-12 06:45:29 +00:00
|
|
|
|
2021-05-13 12:33:44 +01:00
|
|
|
struct zink_bo *bo;
|
2021-05-13 19:54:43 +01:00
|
|
|
VkDeviceSize offset, size, alignment;
|
2021-06-30 14:32:19 +01:00
|
|
|
VkImageCreateFlags vkflags;
|
|
|
|
VkImageUsageFlags vkusage;
|
2021-11-11 16:57:49 +00:00
|
|
|
uint64_t modifier;
|
|
|
|
VkImageAspectFlags modifier_aspect;
|
2020-10-27 15:38:16 +00:00
|
|
|
|
|
|
|
bool host_visible;
|
2021-02-25 17:33:11 +00:00
|
|
|
bool coherent;
|
2020-10-27 15:38:16 +00:00
|
|
|
};
|
|
|
|
|
2018-08-31 15:50:20 +01:00
|
|
|
struct zink_resource {
|
2021-03-22 15:01:30 +00:00
|
|
|
struct threaded_resource base;
|
2018-08-31 15:50:20 +01:00
|
|
|
|
2020-06-01 15:53:19 +01:00
|
|
|
enum pipe_format internal_format:16;
|
|
|
|
|
2020-10-27 15:38:16 +00:00
|
|
|
struct zink_resource_object *obj;
|
2021-04-09 15:23:48 +01:00
|
|
|
struct zink_resource_object *scanout_obj; //TODO: remove for wsi
|
2021-04-13 14:14:15 +01:00
|
|
|
bool scanout_obj_init;
|
2018-08-31 15:50:20 +01:00
|
|
|
union {
|
2021-01-15 18:22:10 +00:00
|
|
|
struct {
|
|
|
|
struct util_range valid_buffer_range;
|
2021-05-14 15:44:02 +01:00
|
|
|
uint32_t vbo_bind_mask : PIPE_MAX_ATTRIBS;
|
2021-05-11 15:09:06 +01:00
|
|
|
uint8_t ubo_bind_count[2];
|
2021-10-22 19:35:53 +01:00
|
|
|
uint8_t so_bind_count; //not counted in all_binds
|
2021-09-03 15:31:07 +01:00
|
|
|
bool so_valid;
|
2021-05-11 15:09:06 +01:00
|
|
|
uint32_t ubo_bind_mask[PIPE_SHADER_TYPES];
|
2021-05-11 15:12:39 +01:00
|
|
|
uint32_t ssbo_bind_mask[PIPE_SHADER_TYPES];
|
2021-01-15 18:22:10 +00:00
|
|
|
};
|
2018-08-31 15:50:20 +01:00
|
|
|
struct {
|
2022-01-03 19:34:30 +00:00
|
|
|
VkSparseImageMemoryRequirements sparse;
|
2018-08-31 15:50:20 +01:00
|
|
|
VkFormat format;
|
|
|
|
VkImageLayout layout;
|
|
|
|
VkImageAspectFlags aspect;
|
2020-12-12 02:41:39 +00:00
|
|
|
bool optimal_tiling;
|
2021-10-28 20:17:11 +01:00
|
|
|
bool need_2D_zs;
|
2021-10-22 19:35:53 +01:00
|
|
|
uint8_t fb_binds; //not counted in all_binds
|
2018-08-31 15:50:20 +01:00
|
|
|
};
|
|
|
|
};
|
2021-05-11 15:13:45 +01:00
|
|
|
uint32_t sampler_binds[PIPE_SHADER_TYPES];
|
2021-05-11 15:34:40 +01:00
|
|
|
uint16_t image_bind_count[2]; //gfx, compute
|
2021-01-12 22:53:47 +00:00
|
|
|
uint16_t write_bind_count[2]; //gfx, compute
|
2021-09-14 14:42:31 +01:00
|
|
|
uint16_t bindless[2]; //tex, img
|
2021-09-03 15:15:14 +01:00
|
|
|
union {
|
|
|
|
uint16_t bind_count[2]; //gfx, compute
|
|
|
|
uint32_t all_binds;
|
|
|
|
};
|
2018-08-31 15:50:20 +01:00
|
|
|
|
2021-08-31 14:57:30 +01:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
struct hash_table bufferview_cache;
|
|
|
|
simple_mtx_t bufferview_mtx;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
struct hash_table surface_cache;
|
|
|
|
simple_mtx_t surface_mtx;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-09-10 01:48:38 +01:00
|
|
|
bool dmabuf_acquire;
|
2018-08-31 15:50:20 +01:00
|
|
|
struct sw_displaytarget *dt;
|
|
|
|
unsigned dt_stride;
|
2020-10-27 16:44:58 +00:00
|
|
|
|
2021-04-08 21:24:51 +01:00
|
|
|
uint8_t modifiers_count;
|
|
|
|
uint64_t *modifiers;
|
2018-08-31 15:50:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct zink_transfer {
|
2021-03-22 15:01:30 +00:00
|
|
|
struct threaded_transfer base;
|
2018-08-31 15:50:20 +01:00
|
|
|
struct pipe_resource *staging_res;
|
2020-12-10 21:00:46 +00:00
|
|
|
unsigned offset;
|
2020-12-10 21:25:47 +00:00
|
|
|
unsigned depthPitch;
|
2018-08-31 15:50:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct zink_resource *
|
|
|
|
zink_resource(struct pipe_resource *r)
|
|
|
|
{
|
|
|
|
return (struct zink_resource *)r;
|
|
|
|
}
|
|
|
|
|
2020-10-13 14:42:07 +01:00
|
|
|
bool
|
2018-08-31 15:50:20 +01:00
|
|
|
zink_screen_resource_init(struct pipe_screen *pscreen);
|
|
|
|
|
|
|
|
void
|
|
|
|
zink_context_resource_init(struct pipe_context *pctx);
|
|
|
|
|
2020-06-01 15:53:19 +01:00
|
|
|
void
|
|
|
|
zink_get_depth_stencil_resources(struct pipe_resource *res,
|
|
|
|
struct zink_resource **out_z,
|
|
|
|
struct zink_resource **out_s);
|
2021-05-14 19:56:35 +01:00
|
|
|
VkMappedMemoryRange
|
|
|
|
zink_resource_init_mem_range(struct zink_screen *screen, struct zink_resource_object *obj, VkDeviceSize offset, VkDeviceSize size);
|
2020-06-14 05:01:07 +01:00
|
|
|
void
|
2020-09-15 23:26:39 +01:00
|
|
|
zink_resource_setup_transfer_layouts(struct zink_context *ctx, struct zink_resource *src, struct zink_resource *dst);
|
2020-08-11 23:36:15 +01:00
|
|
|
|
2020-10-27 16:07:36 +00:00
|
|
|
void
|
|
|
|
zink_destroy_resource_object(struct zink_screen *screen, struct zink_resource_object *resource_object);
|
|
|
|
|
|
|
|
void
|
|
|
|
debug_describe_zink_resource_object(char *buf, const struct zink_resource_object *ptr);
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
zink_resource_object_reference(struct zink_screen *screen,
|
|
|
|
struct zink_resource_object **dst,
|
|
|
|
struct zink_resource_object *src)
|
|
|
|
{
|
|
|
|
struct zink_resource_object *old_dst = dst ? *dst : NULL;
|
|
|
|
|
|
|
|
if (pipe_reference_described(old_dst ? &old_dst->reference : NULL, &src->reference,
|
|
|
|
(debug_reference_descriptor)debug_describe_zink_resource_object))
|
|
|
|
zink_destroy_resource_object(screen, old_dst);
|
|
|
|
if (dst) *dst = src;
|
|
|
|
}
|
|
|
|
|
2021-05-13 19:54:43 +01:00
|
|
|
VkBuffer
|
|
|
|
zink_resource_tmp_buffer(struct zink_screen *screen, struct zink_resource *res, unsigned offset_add, unsigned add_binds, unsigned *offset);
|
|
|
|
|
2020-12-12 06:45:29 +00:00
|
|
|
bool
|
|
|
|
zink_resource_object_init_storage(struct zink_context *ctx, struct zink_resource *res);
|
2021-07-07 14:36:45 +01:00
|
|
|
|
2021-09-03 15:15:14 +01:00
|
|
|
static inline bool
|
|
|
|
zink_resource_has_binds(const struct zink_resource *res)
|
|
|
|
{
|
|
|
|
return res->all_binds > 0;
|
|
|
|
}
|
|
|
|
|
2021-07-07 14:36:45 +01:00
|
|
|
#ifndef __cplusplus
|
2021-05-13 12:33:44 +01:00
|
|
|
#include "zink_bo.h"
|
2021-07-07 14:36:45 +01:00
|
|
|
|
|
|
|
static inline bool
|
|
|
|
zink_resource_usage_is_unflushed(const struct zink_resource *res)
|
|
|
|
{
|
2021-05-13 12:33:44 +01:00
|
|
|
return zink_bo_has_unflushed_usage(res->obj->bo);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
zink_resource_usage_is_unflushed_write(const struct zink_resource *res)
|
|
|
|
{
|
2021-05-13 12:33:44 +01:00
|
|
|
return zink_batch_usage_is_unflushed(res->obj->bo->writes);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
zink_resource_usage_matches(const struct zink_resource *res, const struct zink_batch_state *bs)
|
|
|
|
{
|
2021-05-13 12:33:44 +01:00
|
|
|
return zink_bo_usage_matches(res->obj->bo, bs);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
zink_resource_has_usage(const struct zink_resource *res)
|
|
|
|
{
|
2021-05-13 12:33:44 +01:00
|
|
|
return zink_bo_has_usage(res->obj->bo);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
zink_resource_has_unflushed_usage(const struct zink_resource *res)
|
|
|
|
{
|
2021-05-13 12:33:44 +01:00
|
|
|
return zink_bo_has_unflushed_usage(res->obj->bo);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
zink_resource_usage_check_completion(struct zink_screen *screen, struct zink_resource *res, enum zink_resource_access access)
|
|
|
|
{
|
2021-05-13 12:33:44 +01:00
|
|
|
return zink_bo_usage_check_completion(screen, res->obj->bo, access);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
zink_resource_usage_wait(struct zink_context *ctx, struct zink_resource *res, enum zink_resource_access access)
|
|
|
|
{
|
2021-07-30 15:09:23 +01:00
|
|
|
zink_bo_usage_wait(ctx, res->obj->bo, access);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
zink_resource_usage_set(struct zink_resource *res, struct zink_batch_state *bs, bool write)
|
|
|
|
{
|
2021-07-30 15:09:23 +01:00
|
|
|
zink_bo_usage_set(res->obj->bo, bs, write);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
2021-09-08 20:21:52 +01:00
|
|
|
static inline bool
|
2021-07-07 14:36:45 +01:00
|
|
|
zink_resource_object_usage_unset(struct zink_resource_object *obj, struct zink_batch_state *bs)
|
|
|
|
{
|
2021-09-08 20:21:52 +01:00
|
|
|
return zink_bo_usage_unset(obj->bo, bs);
|
2021-07-07 14:36:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2018-08-31 15:50:20 +01:00
|
|
|
#endif
|