2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2020 Blender Foundation. */
|
2020-08-21 12:30:55 +02:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "BLI_sys_types.h"
|
|
|
|
|
|
2020-12-16 16:19:04 +11:00
|
|
|
struct GPUUniformBuf;
|
|
|
|
|
|
2020-08-21 12:30:55 +02:00
|
|
|
namespace blender {
|
|
|
|
|
namespace gpu {
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
# define DEBUG_NAME_LEN 64
|
2020-08-29 01:33:55 +02:00
|
|
|
#else
|
|
|
|
|
# define DEBUG_NAME_LEN 8
|
2020-08-21 12:30:55 +02:00
|
|
|
#endif
|
|
|
|
|
|
2020-08-21 14:14:56 +02:00
|
|
|
/**
|
|
|
|
|
* Implementation of Uniform Buffers.
|
|
|
|
|
* Base class which is then specialized for each implementation (GL, VK, ...).
|
2021-01-04 12:00:18 +11:00
|
|
|
*/
|
2020-08-21 12:30:55 +02:00
|
|
|
class UniformBuf {
|
|
|
|
|
protected:
|
|
|
|
|
/** Data size in bytes. */
|
|
|
|
|
size_t size_in_bytes_;
|
|
|
|
|
/** Continuous memory block to copy to GPU. This data is owned by the UniformBuf. */
|
2022-07-15 10:36:24 +02:00
|
|
|
void *data_ = nullptr;
|
2020-08-21 12:30:55 +02:00
|
|
|
/** Debugging name */
|
|
|
|
|
char name_[DEBUG_NAME_LEN];
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
UniformBuf(size_t size, const char *name);
|
|
|
|
|
virtual ~UniformBuf();
|
|
|
|
|
|
|
|
|
|
virtual void update(const void *data) = 0;
|
2022-11-15 20:15:04 +01:00
|
|
|
virtual void clear_to_zero() = 0;
|
2020-08-21 12:30:55 +02:00
|
|
|
virtual void bind(int slot) = 0;
|
2022-11-15 14:41:28 +01:00
|
|
|
virtual void bind_as_ssbo(int slot) = 0;
|
2022-01-05 21:44:03 -05:00
|
|
|
virtual void unbind() = 0;
|
2020-08-21 12:30:55 +02:00
|
|
|
|
|
|
|
|
/** Used to defer data upload at drawing time.
|
|
|
|
|
* This is useful if the thread has no context bound.
|
|
|
|
|
* This transfers ownership to this UniformBuf. */
|
|
|
|
|
void attach_data(void *data)
|
|
|
|
|
{
|
|
|
|
|
data_ = data;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Syntactic sugar. */
|
2020-09-08 03:34:47 +02:00
|
|
|
static inline GPUUniformBuf *wrap(UniformBuf *vert)
|
|
|
|
|
{
|
|
|
|
|
return reinterpret_cast<GPUUniformBuf *>(vert);
|
|
|
|
|
}
|
|
|
|
|
static inline UniformBuf *unwrap(GPUUniformBuf *vert)
|
|
|
|
|
{
|
|
|
|
|
return reinterpret_cast<UniformBuf *>(vert);
|
|
|
|
|
}
|
|
|
|
|
static inline const UniformBuf *unwrap(const GPUUniformBuf *vert)
|
|
|
|
|
{
|
|
|
|
|
return reinterpret_cast<const UniformBuf *>(vert);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-21 12:30:55 +02:00
|
|
|
#undef DEBUG_NAME_LEN
|
|
|
|
|
|
|
|
|
|
} // namespace gpu
|
|
|
|
|
} // namespace blender
|