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;
|
2018-08-31 15:50:20 +01:00
|
|
|
|
2021-03-12 22:42:28 +00:00
|
|
|
#define ZINK_RESOURCE_USAGE_STREAMOUT (1 << 10) //much greater than ZINK_DESCRIPTOR_TYPES
|
|
|
|
|
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"
|
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>
|
|
|
|
|
2020-10-28 17:19:53 +00:00
|
|
|
enum zink_resource_access {
|
|
|
|
ZINK_RESOURCE_ACCESS_READ = 1,
|
|
|
|
ZINK_RESOURCE_ACCESS_WRITE = 32,
|
|
|
|
ZINK_RESOURCE_ACCESS_RW = ZINK_RESOURCE_ACCESS_READ | ZINK_RESOURCE_ACCESS_WRITE,
|
|
|
|
};
|
2020-06-15 20:51:05 +01:00
|
|
|
|
2020-10-13 14:42:07 +01:00
|
|
|
struct mem_key {
|
|
|
|
VkMemoryRequirements reqs;
|
|
|
|
VkMemoryPropertyFlags flags;
|
|
|
|
};
|
|
|
|
|
2020-10-27 15:38:16 +00:00
|
|
|
struct zink_resource_object {
|
|
|
|
struct pipe_reference reference;
|
|
|
|
union {
|
|
|
|
VkBuffer buffer;
|
|
|
|
VkImage image;
|
|
|
|
};
|
|
|
|
VkDeviceMemory mem;
|
|
|
|
uint32_t mem_hash;
|
|
|
|
struct mem_key mkey;
|
|
|
|
VkDeviceSize offset, size;
|
|
|
|
|
2020-10-27 15:59:33 +00:00
|
|
|
unsigned persistent_maps; //if nonzero, requires vkFlushMappedMemoryRanges during batch use
|
2020-10-27 16:07:36 +00:00
|
|
|
struct zink_descriptor_refs desc_set_refs;
|
|
|
|
|
2020-11-05 17:39:50 +00:00
|
|
|
struct zink_batch_usage reads;
|
|
|
|
struct zink_batch_usage writes;
|
2020-11-03 19:28:17 +00:00
|
|
|
unsigned map_count;
|
|
|
|
void *map;
|
2020-10-27 15:59:33 +00:00
|
|
|
bool is_buffer;
|
2020-10-27 15:38:16 +00:00
|
|
|
bool host_visible;
|
|
|
|
};
|
|
|
|
|
2018-08-31 15:50:20 +01:00
|
|
|
struct zink_resource {
|
|
|
|
struct pipe_resource base;
|
|
|
|
|
2020-06-01 15:53:19 +01:00
|
|
|
enum pipe_format internal_format:16;
|
|
|
|
|
2020-08-17 21:09:26 +01:00
|
|
|
VkPipelineStageFlagBits access_stage;
|
2020-09-07 15:34:24 +01:00
|
|
|
VkAccessFlags access;
|
2020-10-27 15:38:16 +00:00
|
|
|
|
|
|
|
struct zink_resource_object *obj;
|
2018-08-31 15:50:20 +01:00
|
|
|
union {
|
2020-10-27 15:38:16 +00:00
|
|
|
struct util_range valid_buffer_range;
|
2018-08-31 15:50:20 +01:00
|
|
|
struct {
|
|
|
|
VkFormat format;
|
|
|
|
VkImageLayout layout;
|
|
|
|
VkImageAspectFlags aspect;
|
2020-12-12 02:41:39 +00:00
|
|
|
bool optimal_tiling;
|
2018-08-31 15:50:20 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sw_displaytarget *dt;
|
|
|
|
unsigned dt_stride;
|
2020-10-27 16:44:58 +00:00
|
|
|
|
|
|
|
uint32_t bind_history; // enum zink_descriptor_type bitmask
|
|
|
|
uint32_t bind_stages;
|
2018-08-31 15:50:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct zink_transfer {
|
|
|
|
struct pipe_transfer base;
|
|
|
|
struct pipe_resource *staging_res;
|
2020-12-10 21:00:46 +00:00
|
|
|
unsigned offset;
|
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);
|
|
|
|
|
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-28 17:21:34 +00:00
|
|
|
bool
|
2020-11-25 22:05:58 +00:00
|
|
|
zink_resource_has_usage(struct zink_resource *res, enum zink_resource_access usage);
|
2020-10-28 17:21:34 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
zink_resource_has_usage_for_id(struct zink_resource *res, uint32_t id);
|
2020-10-02 18:40:40 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
zink_resource_desc_set_add(struct zink_resource *res, struct zink_descriptor_set *zds, unsigned idx);
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-31 15:50:20 +01:00
|
|
|
#endif
|