rtengine/src/renderer/vk/resources.h
Kevin Trogant 3bc192b281 dump state
this will be the basis of the framegraph rewrite, because the current
state is fucked
2024-03-25 17:55:03 +01:00

81 lines
1.7 KiB
C

#ifndef RT_VK_RESOURCES_H
#define RT_VK_RESOURCES_H
/* Buffers and images */
#include "gpu.h"
#include "runtime/threading.h"
typedef enum {
RT_BUFFER_STATE_INVALID,
RT_BUFFER_STATE_NOT_USED,
RT_BUFFER_STATE_IN_USE,
RT_BUFFER_STATE_IN_TRANSFER,
} rt_buffer_state;
typedef struct {
VkBuffer buffer;
VmaAllocation allocation;
size_t size;
rt_buffer_usage usage;
rt_buffer_type type;
rt_buffer_state state;
rt_rwlock lock;
bool mappable;
bool coherent;
rt_gpu_queue owner;
} rt_buffer;
rt_buffer *rtGetBuffer(rt_buffer_handle handle);
/* Helper functions for accessing buffers */
RT_INLINE rt_gpu_queue rtGetBufferOwner(rt_buffer_handle handle) {
rt_buffer *buffer = rtGetBuffer(handle);
rt_gpu_queue owner = RT_VK_UNOWNED;
if (buffer) {
rtLockRead(&buffer->lock);
owner = buffer->owner;
rtUnlockRead(&buffer->lock);
}
return owner;
}
RT_INLINE void rtSetBufferOwner(rt_buffer_handle handle, rt_gpu_queue owner) {
rt_buffer *buffer = rtGetBuffer(handle);
if (buffer) {
rtLockWrite(&buffer->lock);
buffer->owner = owner;
rtUnlockWrite(&buffer->lock);
}
}
RT_INLINE rt_buffer_state rtGetBufferState(rt_buffer_handle handle) {
rt_buffer *buffer = rtGetBuffer(handle);
rt_buffer_state state = RT_BUFFER_STATE_INVALID;
if (buffer) {
rtLockRead(&buffer->lock);
state = buffer->state;
rtUnlockRead(&buffer->lock);
}
return state;
}
RT_INLINE void rtSetBufferState(rt_buffer_handle handle, rt_buffer_state state) {
rt_buffer *buffer = rtGetBuffer(handle);
if (buffer) {
rtLockWrite(&buffer->lock);
buffer->state = state;
rtUnlockWrite(&buffer->lock);
}
}
#endif