24#include "nicegraf-util.h"
49#define NGF_RETURN_IF_ERROR(expr) \
51 const ngf_error tmp = (expr); \
52 if (tmp != NGF_ERROR_OK) return tmp; \
60template<
class T,
class ObjectManagementFuncs>
class ngf_handle {
72 *
this = std::move(other);
77 destroy_if_necessary();
84 destroy_if_necessary();
85 handle_ = other.handle_;
86 other.handle_ =
nullptr;
90 typedef typename ObjectManagementFuncs::InitType init_type;
94 destroy_if_necessary();
95 const ngf_error err = ObjectManagementFuncs::create(&info, &handle_);
127 operator const T()
const {
135 destroy_if_necessary();
136 handle_ = new_handle;
140 void destroy_if_necessary() {
142 ObjectManagementFuncs::destroy(handle_);
150#define NGF_DEFINE_WRAPPER_MANAGEMENT_FUNCS(name) \
151 struct ngf_##name##_ManagementFuncs { \
152 using InitType = ngf_##name##_info; \
153 static ngf_error create(const InitType* info, ngf_##name* r) { \
154 return ngf_create_##name(info, r); \
156 static void destroy(ngf_##name handle) { ngf_destroy_##name(handle); } \
159#define NGF_DEFINE_WRAPPER_TYPE(name) \
160 using name = ngf_handle<ngf_##name, ngf_##name##_ManagementFuncs>;
165NGF_DEFINE_WRAPPER_MANAGEMENT_FUNCS(
image);
168NGF_DEFINE_WRAPPER_MANAGEMENT_FUNCS(
buffer);
288 uint32_t clear_stencil) {
309 *
this = std::move(other);
314 other.enc_.pvt_data_donotuse.d0 = 0u;
315 other.enc_.pvt_data_donotuse.d1 = 0u;
357 *
this = std::move(other);
362 other.enc_.pvt_data_donotuse.d0 = 0u;
363 other.enc_.pvt_data_donotuse.d1 = 0u;
416 *
this = std::move(other);
421 other.enc_.pvt_data_donotuse.d0 = 0u;
422 other.enc_.pvt_data_donotuse.d1 = 0u;
472 op.
type = NGF_DESCRIPTOR_STORAGE_IMAGE;
528 op.
info.texel_buffer_view = buf_view;
609 *
this = std::move(other);
616 ngf_error initialize(
const uint32_t frames) {
618 const size_t aligned_size = ngf_util_align_size(
sizeof(T), alignment);
620 aligned_size * frames,
621 NGF_BUFFER_STORAGE_HOST_WRITEABLE,
622 NGF_BUFFER_USAGE_UNIFORM_BUFFER}));
624 aligned_per_frame_size_ = aligned_size;
628 void write(
const T& data) {
629 current_offset_ = (frame_)*aligned_per_frame_size_;
631 memcpy(mapped_buf, (
void*)&data,
sizeof(T));
634 frame_ = (frame_ + 1u) % nframes_;
640 size_t additional_offset = 0,
641 size_t range = 0)
const {
647 op.
info.buffer.
offset = current_offset_ + additional_offset;
648 op.
info.buffer.
range = (range == 0) ? aligned_per_frame_size_ : range;
655 size_t current_offset_ = 0;
656 size_t aligned_per_frame_size_ = 0;
657 uint32_t nframes_ = 0;
Definition nicegraf-wrappers.h:386
compute_encoder(ngf_cmd_buffer cmd_buf)
Definition nicegraf-wrappers.h:404
~compute_encoder()
Definition nicegraf-wrappers.h:411
compute_encoder(ngf_cmd_buffer cmd_buf, const ngf_compute_pass_info &pass_info)
Definition nicegraf-wrappers.h:394
Definition nicegraf-wrappers.h:60
T release()
Definition nicegraf-wrappers.h:115
ngf_handle(T raw)
Definition nicegraf-wrappers.h:63
~ngf_handle()
Definition nicegraf-wrappers.h:76
void reset(T new_handle)
Definition nicegraf-wrappers.h:134
ngf_handle & operator=(ngf_handle &&other) noexcept
Definition nicegraf-wrappers.h:83
const T get() const
Definition nicegraf-wrappers.h:106
ngf_handle()
Definition nicegraf-wrappers.h:67
ngf_error initialize(const typename ObjectManagementFuncs::InitType &info)
Definition nicegraf-wrappers.h:93
T get()
Definition nicegraf-wrappers.h:101
Definition nicegraf-wrappers.h:248
render_encoder(ngf_cmd_buffer cmd_buf, const ngf_render_pass_info &pass_info)
Definition nicegraf-wrappers.h:257
~render_encoder()
Definition nicegraf-wrappers.h:304
render_encoder(ngf_cmd_buffer cmd_buf, ngf_render_target rt, float clear_color_r, float clear_color_g, float clear_color_b, float clear_color_a, float clear_depth, uint32_t clear_stencil)
Definition nicegraf-wrappers.h:280
Definition nicegraf-wrappers.h:338
~xfer_encoder()
Definition nicegraf-wrappers.h:352
xfer_encoder(ngf_cmd_buffer cmd_buf, const ngf_xfer_pass_info &pass_info)
Definition nicegraf-wrappers.h:345
void cmd_bind_resources(ngf_render_encoder enc, const Args &&... args)
Definition nicegraf-wrappers.h:577
#define NGF_RETURN_IF_ERROR(expr)
Definition nicegraf-wrappers.h:49
ngf_handle< ngf_sampler, ngf_sampler_ManagementFuncs > sampler
Definition nicegraf-wrappers.h:206
ngf_handle< ngf_image, ngf_image_ManagementFuncs > image
Definition nicegraf-wrappers.h:199
void * ngf_buffer_map_range(ngf_buffer buf, size_t offset, size_t size)
void ngf_buffer_unmap(ngf_buffer buf)
ngf_error
Definition nicegraf.h:293
ngf_error ngf_cmd_end_xfer_pass(ngf_xfer_encoder enc)
ngf_error ngf_cmd_end_render_pass(ngf_render_encoder enc)
ngf_error ngf_cmd_begin_compute_pass(ngf_cmd_buffer buf, const ngf_compute_pass_info *pass_info, ngf_compute_encoder *enc)
void ngf_cmd_bind_compute_resources(ngf_compute_encoder enc, const ngf_resource_bind_op *bind_operations, uint32_t nbind_operations)
const ngf_device_capabilities * ngf_get_device_capabilities(void)
ngf_error ngf_cmd_begin_render_pass(ngf_cmd_buffer buf, const ngf_render_pass_info *pass_info, ngf_render_encoder *enc)
ngf_error ngf_cmd_begin_render_pass_simple(ngf_cmd_buffer buf, ngf_render_target rt, float clear_color_r, float clear_color_g, float clear_color_b, float clear_color_a, float clear_depth, uint32_t clear_stencil, ngf_render_encoder *enc)
ngf_error ngf_cmd_begin_xfer_pass(ngf_cmd_buffer buf, const ngf_xfer_pass_info *pass_info, ngf_xfer_encoder *enc)
void ngf_cmd_bind_resources(ngf_render_encoder enc, const ngf_resource_bind_op *bind_operations, uint32_t nbind_operations)
ngf_error ngf_cmd_end_compute_pass(ngf_compute_encoder enc)
void ngf_buffer_flush_range(ngf_buffer buf, size_t offset, size_t size)
@ NGF_ERROR_OK
Definition nicegraf.h:296
@ NGF_DESCRIPTOR_IMAGE_AND_SAMPLER
Definition nicegraf.h:1441
@ NGF_DESCRIPTOR_TEXEL_BUFFER
Definition nicegraf.h:1449
@ NGF_DESCRIPTOR_UNIFORM_BUFFER
Definition nicegraf.h:1420
@ NGF_DESCRIPTOR_IMAGE
Definition nicegraf.h:1427
@ NGF_DESCRIPTOR_STORAGE_BUFFER
Definition nicegraf.h:1456
@ NGF_DESCRIPTOR_SAMPLER
Definition nicegraf.h:1434
Definition nicegraf-wrappers.h:449
static ngf_resource_bind_op texture_and_sampler(const ngf_image image, const ngf_sampler sampler)
Definition nicegraf-wrappers.h:553
static ngf_resource_bind_op texel_buffer(const ngf_texel_buffer_view buf_view)
Definition nicegraf-wrappers.h:523
static ngf_resource_bind_op uniform_buffer(const ngf_buffer buf, size_t offset, size_t range)
Definition nicegraf-wrappers.h:504
static ngf_resource_bind_op storage_image(const ngf_image image)
Definition nicegraf-wrappers.h:470
static ngf_resource_bind_op sampler(const ngf_sampler sampler)
Definition nicegraf-wrappers.h:537
static ngf_resource_bind_op texture(const ngf_image image)
Definition nicegraf-wrappers.h:455
static ngf_resource_bind_op storage_buffer(const ngf_buffer buf, size_t offset, size_t range)
Definition nicegraf-wrappers.h:486
Definition nicegraf-wrappers.h:445
size_t offset
Definition nicegraf.h:2065
size_t range
Definition nicegraf.h:2066
ngf_buffer buffer
Definition nicegraf.h:2064
Definition nicegraf.h:2010
Definition nicegraf.h:1848
Definition nicegraf.h:1907
size_t uniform_buffer_offset_alignment
Definition nicegraf.h:2317
ngf_sampler sampler
Definition nicegraf.h:2077
ngf_image image
Definition nicegraf.h:2076
Definition nicegraf.h:1827
Definition nicegraf.h:1857
Definition nicegraf.h:2095
uint32_t target_binding
Definition nicegraf.h:2097
union ngf_resource_bind_op::@1 info
uint32_t target_set
Definition nicegraf.h:2096
ngf_descriptor_type type
Definition nicegraf.h:2098
Definition nicegraf.h:1838
Definition nicegraf.h:1897