45 attachment.tex =
nullptr;
47 attachment.layer = -1;
54 if (attachment.tex !=
nullptr) {
55 reinterpret_cast<Texture *
>(attachment.tex)->detach_from(
this);
59#ifndef GPU_NO_USE_PY_REFERENCES
74 if (new_attachment.
mip == -1) {
80 "GPUFramebuffer: Error: Trying to attach texture to type %d but maximum slot is %d.\n",
86 if (new_attachment.
tex) {
87 if (new_attachment.
layer > 0) {
101 if (attachment.
tex == new_attachment.
tex && attachment.
layer == new_attachment.
layer &&
102 attachment.
mip == new_attachment.
mip)
108 if (attachment.
tex) {
109 reinterpret_cast<Texture *
>(attachment.
tex)->detach_from(
this);
113 if (new_attachment.
tex) {
114 reinterpret_cast<Texture *
>(new_attachment.
tex)->attach_to(
this, type);
120 attachment = new_attachment;
161 const GPULoadStore &depth_action = load_store_actions[0];
199 if (
tex !=
nullptr) {
208 void (*
callback)(
void *user_data,
int level),
217 for (
int mip_lvl = 1; mip_lvl <= max_lvl; mip_lvl++) {
221 if (
tex !=
nullptr) {
227 tex->mip_range_set(mip_lvl - 1, mip_max);
229 attachment.mip = mip_lvl;
241 if (
tex !=
nullptr) {
252 if (attachment.tex !=
nullptr) {
254 reinterpret_cast<Texture *
>(attachment.tex)->mip_range_set(0, max_lvl);
287 return unwrap(gpu_fb)->name_get();
294 const bool enable_srgb =
true;
296 unwrap(gpu_fb)->set_use_explicit_loadstore(
false);
297 unwrap(gpu_fb)->bind(enable_srgb);
304 const bool enable_srgb =
true;
306 unwrap(gpu_fb)->set_use_explicit_loadstore(
true);
307 unwrap(gpu_fb)->bind(enable_srgb);
311 fb->load_store_config_array(load_store_actions, actions_len);
318 unwrap(gpu_fb)->subpass_transition(
324 const bool enable_srgb =
false;
325 unwrap(gpu_fb)->bind(enable_srgb);
366 return unwrap(gpu_fb)->check(err_out);
375 unwrap(gpu_fb)->attachment_set(type, attachment);
385 GPUFrameBuffer *
fb, GPUTexture *
tex,
int slot,
int layer,
int mip)
392 GPUFrameBuffer *
fb, GPUTexture *
tex,
int slot,
int face,
int mip)
412 if (depth_attachment.
mip == -1) {
415 else if (depth_attachment.
tex ==
nullptr) {
424 fb->attachment_set(type, depth_attachment);
429 fb->attachment_set(type, attachment);
436 unwrap(gpu_fb)->default_size_set(width, height);
443 int viewport_rect[4] = {
x,
y, width, height};
444 unwrap(gpu_fb)->viewport_set(viewport_rect);
450 unwrap(gpu_fb)->viewport_multi_set(viewport_rects);
455 unwrap(gpu_fb)->viewport_get(r_viewport);
460 unwrap(gpu_fb)->viewport_reset();
467 const float clear_col[4],
472 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
473 "state via GPU_framebuffer_bind_ex is invalid.");
474 unwrap(gpu_fb)->clear(
buffers, clear_col, clear_depth, clear_stencil);
488 const float clear_col[4],
505 const float clear_col[4],
516 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
517 "state via GPU_framebuffer_bind_ex is invalid.");
518 unwrap(gpu_fb)->clear_multi(clear_cols);
524 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
525 "state via GPU_framebuffer_bind_ex is invalid.");
526 float clear_col[4] = {
red,
green, blue, alpha};
533 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
534 "state via GPU_framebuffer_bind_ex is invalid.");
535 float clear_col[4] = {0};
542 int rect[4] = {
x,
y,
w, h};
556 int rect[4] = {
x,
y,
w, h};
563 int rect[4] = {
x,
y,
w, h};
570 GPUFrameBuffer *gpufb_write,
581 GPUTexture *read_tex, *write_tex;
587 read_tex = fb_read->
color_tex(read_slot);
588 write_tex = fb_write->
color_tex(write_slot);
602 fb_read->
blit_to(blit_buffers, read_slot, fb_write, write_slot, 0, 0);
610 void (*
callback)(
void *user_data,
int level),
613 unwrap(gpu_fb)->recursive_downsample(max_lvl,
callback, user_data);
616#ifndef GPU_NO_USE_PY_REFERENCES
619 return unwrap(gpu_fb)->py_ref;
625 unwrap(gpu_fb)->py_ref = py_ref;
637#define FRAMEBUFFER_STACK_DEPTH 16
663#undef FRAMEBUFFER_STACK_DEPTH
674#define MAX_CTX_FB_LEN 3
695 if (framebuffer.fb ==
nullptr) {
696 framebuffer.ctx = ctx;
699 GPU_ATTACHMENT_TEXTURE(ofs->depth),
700 GPU_ATTACHMENT_TEXTURE(ofs->color),
704 if (framebuffer.ctx == ctx) {
705 return framebuffer.fb;
716 "Warning: GPUOffscreen used in more than 3 GPUContext. "
717 "This may create performance drop.\n");
721 framebuffer.fb =
nullptr;
738 height =
max_ii(1, height);
754 const char error[] =
"GPUTexture: Texture allocation failed.";
759 fprintf(stderr,
"%s",
error);
779 if (framebuffer.fb) {
804 GPUFrameBuffer *
fb =
nullptr;
867 GPUFrameBuffer **r_fb,
868 GPUTexture **r_color,
869 GPUTexture **r_depth)
872 *r_color = ofs->
color;
873 *r_depth = ofs->
depth;
#define BLI_assert_msg(a, msg)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
#define STRNCPY(dst, src)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
bool GPU_mip_render_workaround()
@ GPU_LOADACTION_DONT_CARE
@ GPU_STOREACTION_DONT_CARE
void GPU_framebuffer_multi_viewports_set(GPUFrameBuffer *gpu_fb, const int viewport_rects[GPU_MAX_VIEWPORTS][4])
bool GPU_framebuffer_check_valid(GPUFrameBuffer *framebuffer, char err_out[256])
void GPU_offscreen_draw_to_screen(GPUOffScreen *offscreen, int x, int y)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, eGPUTextureFormat format, eGPUTextureUsage usage, char err_out[256])
GPUFrameBuffer * GPU_framebuffer_create(const char *name)
const char * GPU_framebuffer_get_name(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_push(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_default_size(GPUFrameBuffer *framebuffer, int width, int height)
void GPU_framebuffer_config_array(GPUFrameBuffer *framebuffer, const GPUAttachment *config, int config_len)
GPUFrameBuffer * GPU_framebuffer_active_get()
int GPU_offscreen_width(const GPUOffScreen *offscreen)
void GPU_framebuffer_viewport_get(GPUFrameBuffer *framebuffer, int r_viewport[4])
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
void GPU_offscreen_viewport_data_get(GPUOffScreen *offscreen, GPUFrameBuffer **r_fb, GPUTexture **r_color, GPUTexture **r_depth)
void GPU_framebuffer_texture_detach(GPUFrameBuffer *framebuffer, GPUTexture *texture)
void GPU_framebuffer_clear_color_depth_stencil(GPUFrameBuffer *fb, const float clear_col[4], float clear_depth, uint clear_stencil)
void GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int face, int mip)
void GPU_framebuffer_restore()
void GPU_framebuffer_clear_stencil(GPUFrameBuffer *fb, uint clear_stencil)
bool GPU_framebuffer_bound(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_clear_depth_stencil(GPUFrameBuffer *fb, float clear_depth, uint clear_stencil)
void GPU_framebuffer_py_reference_set(GPUFrameBuffer *framebuffer, void **py_ref)
void ** GPU_framebuffer_py_reference_get(GPUFrameBuffer *framebuffer)
void GPU_frontbuffer_read_color(int x, int y, int width, int height, int channels, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_read_depth(GPUFrameBuffer *framebuffer, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
#define GPU_ATTACHMENT_NONE
void GPU_framebuffer_viewport_reset(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_clear_color_depth(GPUFrameBuffer *fb, const float clear_col[4], float clear_depth)
uint GPU_framebuffer_stack_level_get()
#define GPU_ATTACHMENT_TEXTURE_MIP(_texture, _mip)
void GPU_framebuffer_texture_layer_attach(GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int layer, int mip)
int GPU_offscreen_height(const GPUOffScreen *offscreen)
void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *framebuffer, int max_level, void(*per_level_callback)(void *user_data, int level), void *user_data)
void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_clear(GPUFrameBuffer *framebuffer, eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, unsigned int clear_stencil)
GPUTexture * GPU_offscreen_color_texture(const GPUOffScreen *offscreen)
void GPU_clear_color(float red, float green, float blue, float alpha)
void GPU_framebuffer_multi_clear(GPUFrameBuffer *framebuffer, const float(*clear_colors)[4])
void GPU_offscreen_read_color_region(GPUOffScreen *offscreen, eGPUDataFormat data_format, int x, int y, int w, int h, void *r_data)
void GPU_offscreen_free(GPUOffScreen *offscreen)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_subpass_transition_array(GPUFrameBuffer *framebuffer, const GPUAttachmentState *attachment_states, uint attachment_len)
void GPU_backbuffer_bind(eGPUBackBuffer back_buffer_type)
eGPUTextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen)
#define NULL_ATTACHMENT_COLOR
void GPU_clear_depth(float depth)
void GPU_framebuffer_read_color(GPUFrameBuffer *framebuffer, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_clear_color(GPUFrameBuffer *fb, const float clear_col[4])
void GPU_framebuffer_viewport_set(GPUFrameBuffer *framebuffer, int x, int y, int width, int height)
#define GPU_framebuffer_ensure_config(_fb,...)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
GPUFrameBuffer * GPU_framebuffer_pop()
#define GPU_MAX_VIEWPORTS
#define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_texture, _layer, _mip)
void GPU_framebuffer_clear_depth(GPUFrameBuffer *fb, float clear_depth)
void GPU_framebuffer_free(GPUFrameBuffer *framebuffer)
GPUFrameBuffer * GPU_framebuffer_back_get()
void GPU_framebuffer_texture_attach(GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int mip)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
#define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_texture, _face, _mip)
void GPU_framebuffer_blit(GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer *fb_write, int write_slot, eGPUFrameBufferBits blit_buffers)
void GPU_framebuffer_bind_loadstore(GPUFrameBuffer *framebuffer, const GPULoadStore *load_store_actions, uint load_store_actions_len)
int GPU_texture_height(const GPUTexture *texture)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
int GPU_texture_width(const GPUTexture *texture)
bool GPU_texture_is_cube(const GPUTexture *texture)
bool GPU_texture_is_array(const GPUTexture *texture)
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
bool GPU_texture_has_stencil_format(const GPUTexture *texture)
bool GPU_texture_has_depth_format(const GPUTexture *texture)
eGPUTextureFormat GPU_texture_format(const GPUTexture *texture)
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its red
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its green
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr int64_t size() const
void attachment_remove(GPUAttachmentType type)
virtual void subpass_transition_impl(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)=0
GPUTexture * depth_tex() const
virtual void attachment_set_loadstore_op(GPUAttachmentType type, GPULoadStore ls)=0
uint get_bits_per_pixel()
virtual void read(eGPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data)=0
virtual void bind(bool enabled_srgb)=0
char name_[DEBUG_NAME_LEN]
void subpass_transition(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)
GPUTexture * color_tex(int slot) const
FrameBuffer(const char *name)
virtual void clear(eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil)=0
GPUAttachment attachments_[GPU_FB_MAX_ATTACHMENT]
void load_store_config_array(const GPULoadStore *load_store_actions, uint actions_len)
virtual void blit_to(eGPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y)=0
void recursive_downsample(int max_lvl, void(*callback)(void *user_data, int level), void *user_data)
void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment)
static GPUBackend * get()
DEGForeachIDComponentCallback callback
#define FRAMEBUFFER_STACK_DEPTH
static struct @626 FrameBufferStack
GPUFrameBuffer * framebuffers[FRAMEBUFFER_STACK_DEPTH]
static void gpu_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, GPUAttachment attachment, int slot)
static GPUFrameBuffer * gpu_offscreen_fb_get(GPUOffScreen *ofs)
@ GPU_FB_DEPTH_STENCIL_ATTACHMENT
@ GPU_FB_COLOR_ATTACHMENT0
@ GPU_FB_DEPTH_ATTACHMENT
#define GPU_FB_MAX_COLOR_ATTACHMENT
BLI_INLINE float fb(float length, float L)
void MEM_freeN(void *vmemh)
ccl_device_inline float2 floor(const float2 a)
static void error(const char *str)
static Context * unwrap(GPUContext *ctx)
static GPUContext * wrap(Context *ctx)
size_t to_bytesize(GPUIndexBufType type)
int to_component_len(eGPUTextureFormat format)
struct GPUOffScreen::@627 framebuffers[MAX_CTX_FB_LEN]