DRW: TextureFromPool: Change API to use acquire / release
This removes the quirk of having to call the sync function for each new render loop. # Conflicts: # source/blender/draw/engines/eevee_next/eevee_view.cc
This commit is contained in:
@@ -582,7 +582,7 @@ void Film::display()
|
||||
BLI_assert(inst_.is_viewport());
|
||||
|
||||
/* Acquire dummy render buffers for correct binding. They will not be used. */
|
||||
inst_.render_buffers.acquire(int2(1), (void *)this);
|
||||
inst_.render_buffers.acquire(int2(1));
|
||||
|
||||
DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
|
||||
GPU_framebuffer_bind(dfbl->default_fb);
|
||||
|
||||
@@ -97,7 +97,6 @@ void Instance::begin_sync()
|
||||
|
||||
gpencil_engine_enabled = false;
|
||||
|
||||
render_buffers.sync();
|
||||
pipelines.sync();
|
||||
main_view.sync();
|
||||
world.sync();
|
||||
|
||||
@@ -24,25 +24,7 @@
|
||||
|
||||
namespace blender::eevee {
|
||||
|
||||
void RenderBuffers::sync()
|
||||
{
|
||||
depth_tx.sync();
|
||||
combined_tx.sync();
|
||||
|
||||
normal_tx.sync();
|
||||
vector_tx.sync();
|
||||
diffuse_light_tx.sync();
|
||||
diffuse_color_tx.sync();
|
||||
specular_light_tx.sync();
|
||||
specular_color_tx.sync();
|
||||
volume_light_tx.sync();
|
||||
emission_tx.sync();
|
||||
environment_tx.sync();
|
||||
shadow_tx.sync();
|
||||
ambient_occlusion_tx.sync();
|
||||
}
|
||||
|
||||
void RenderBuffers::acquire(int2 extent, void *owner)
|
||||
void RenderBuffers::acquire(int2 extent)
|
||||
{
|
||||
auto pass_extent = [&](eViewLayerEEVEEPassType pass_bit) -> int2 {
|
||||
/* Use dummy texture for disabled passes. Allows correct bindings. */
|
||||
@@ -53,25 +35,25 @@ void RenderBuffers::acquire(int2 extent, void *owner)
|
||||
eGPUTextureFormat float_format = GPU_R16F;
|
||||
|
||||
/* Depth and combined are always needed. */
|
||||
depth_tx.acquire(extent, GPU_DEPTH24_STENCIL8, owner);
|
||||
combined_tx.acquire(extent, color_format, owner);
|
||||
depth_tx.acquire(extent, GPU_DEPTH24_STENCIL8);
|
||||
combined_tx.acquire(extent, color_format);
|
||||
|
||||
bool do_vector_render_pass = inst_.film.enabled_passes_get() & EEVEE_RENDER_PASS_VECTOR;
|
||||
/* Only RG16F when only doing only reprojection or motion blur. */
|
||||
eGPUTextureFormat vector_format = do_vector_render_pass ? GPU_RGBA16F : GPU_RG16F;
|
||||
/* TODO(fclem): Make vector pass allocation optional if no TAA or motion blur is needed. */
|
||||
vector_tx.acquire(extent, vector_format, owner);
|
||||
vector_tx.acquire(extent, vector_format);
|
||||
|
||||
normal_tx.acquire(pass_extent(EEVEE_RENDER_PASS_NORMAL), color_format, owner);
|
||||
diffuse_light_tx.acquire(pass_extent(EEVEE_RENDER_PASS_DIFFUSE_LIGHT), color_format, owner);
|
||||
diffuse_color_tx.acquire(pass_extent(EEVEE_RENDER_PASS_DIFFUSE_COLOR), color_format, owner);
|
||||
specular_light_tx.acquire(pass_extent(EEVEE_RENDER_PASS_SPECULAR_LIGHT), color_format, owner);
|
||||
specular_color_tx.acquire(pass_extent(EEVEE_RENDER_PASS_SPECULAR_COLOR), color_format, owner);
|
||||
volume_light_tx.acquire(pass_extent(EEVEE_RENDER_PASS_VOLUME_LIGHT), color_format, owner);
|
||||
emission_tx.acquire(pass_extent(EEVEE_RENDER_PASS_EMIT), color_format, owner);
|
||||
environment_tx.acquire(pass_extent(EEVEE_RENDER_PASS_ENVIRONMENT), color_format, owner);
|
||||
shadow_tx.acquire(pass_extent(EEVEE_RENDER_PASS_SHADOW), float_format, owner);
|
||||
ambient_occlusion_tx.acquire(pass_extent(EEVEE_RENDER_PASS_AO), float_format, owner);
|
||||
normal_tx.acquire(pass_extent(EEVEE_RENDER_PASS_NORMAL), color_format);
|
||||
diffuse_light_tx.acquire(pass_extent(EEVEE_RENDER_PASS_DIFFUSE_LIGHT), color_format);
|
||||
diffuse_color_tx.acquire(pass_extent(EEVEE_RENDER_PASS_DIFFUSE_COLOR), color_format);
|
||||
specular_light_tx.acquire(pass_extent(EEVEE_RENDER_PASS_SPECULAR_LIGHT), color_format);
|
||||
specular_color_tx.acquire(pass_extent(EEVEE_RENDER_PASS_SPECULAR_COLOR), color_format);
|
||||
volume_light_tx.acquire(pass_extent(EEVEE_RENDER_PASS_VOLUME_LIGHT), color_format);
|
||||
emission_tx.acquire(pass_extent(EEVEE_RENDER_PASS_EMIT), color_format);
|
||||
environment_tx.acquire(pass_extent(EEVEE_RENDER_PASS_ENVIRONMENT), color_format);
|
||||
shadow_tx.acquire(pass_extent(EEVEE_RENDER_PASS_SHADOW), float_format);
|
||||
ambient_occlusion_tx.acquire(pass_extent(EEVEE_RENDER_PASS_AO), float_format);
|
||||
|
||||
const AOVsInfoData &aovs = inst_.film.aovs_info;
|
||||
aov_color_tx.ensure_2d_array(
|
||||
|
||||
@@ -48,9 +48,8 @@ class RenderBuffers {
|
||||
public:
|
||||
RenderBuffers(Instance &inst) : inst_(inst){};
|
||||
|
||||
void sync();
|
||||
/* Acquires (also ensures) the render buffer before rendering to them. */
|
||||
void acquire(int2 extent, void *owner);
|
||||
void acquire(int2 extent);
|
||||
void release();
|
||||
};
|
||||
|
||||
|
||||
@@ -85,8 +85,6 @@ void ShadingView::sync()
|
||||
// inst_.hiz_back.view_sync(extent_);
|
||||
// inst_.hiz_front.view_sync(extent_);
|
||||
// inst_.gbuffer.view_sync(extent_);
|
||||
|
||||
postfx_tx_.sync();
|
||||
}
|
||||
|
||||
void ShadingView::render()
|
||||
@@ -96,12 +94,8 @@ void ShadingView::render()
|
||||
}
|
||||
|
||||
/* Query temp textures and create frame-buffers. */
|
||||
/* HACK: View name should be unique and static.
|
||||
* With this, we can reuse the same texture across views. */
|
||||
DrawEngineType *owner = (DrawEngineType *)name_;
|
||||
|
||||
RenderBuffers &rbufs = inst_.render_buffers;
|
||||
rbufs.acquire(extent_, owner);
|
||||
rbufs.acquire(extent_);
|
||||
combined_fb_.ensure(GPU_ATTACHMENT_TEXTURE(rbufs.depth_tx),
|
||||
GPU_ATTACHMENT_TEXTURE(rbufs.combined_tx));
|
||||
prepass_fb_.ensure(GPU_ATTACHMENT_TEXTURE(rbufs.depth_tx),
|
||||
@@ -154,9 +148,7 @@ GPUTexture *ShadingView::render_post(GPUTexture *input_tx)
|
||||
if (!dof_.postfx_enabled() && !mb_.enabled()) {
|
||||
return input_tx;
|
||||
}
|
||||
/* HACK: View name should be unique and static.
|
||||
* With this, we can reuse the same texture across views. */
|
||||
postfx_tx_.acquire(extent_, GPU_RGBA16F, (void *)name_);
|
||||
postfx_tx_.acquire(extent_, GPU_RGBA16F);
|
||||
|
||||
GPUTexture *velocity_tx = velocity_.view_vectors_get();
|
||||
GPUTexture *output_tx = postfx_tx_;
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "draw_manager.h"
|
||||
#include "draw_texture_pool.h"
|
||||
|
||||
#include "BLI_math_vec_types.hh"
|
||||
@@ -772,50 +773,26 @@ class Texture : NonCopyable {
|
||||
};
|
||||
|
||||
class TextureFromPool : public Texture, NonMovable {
|
||||
private:
|
||||
GPUTexture *tx_tmp_saved_ = nullptr;
|
||||
|
||||
public:
|
||||
TextureFromPool(const char *name = "gpu::Texture") : Texture(name){};
|
||||
|
||||
/* Always use `release()` after rendering and `sync()` in sync phase. */
|
||||
void acquire(int2 extent, eGPUTextureFormat format, void *owner_)
|
||||
/* Always use `release()` after rendering. */
|
||||
void acquire(int2 extent, eGPUTextureFormat format)
|
||||
{
|
||||
BLI_assert(this->tx_ == nullptr);
|
||||
if (this->tx_ != nullptr) {
|
||||
return;
|
||||
}
|
||||
if (tx_tmp_saved_ != nullptr) {
|
||||
if (GPU_texture_width(tx_tmp_saved_) != extent.x ||
|
||||
GPU_texture_height(tx_tmp_saved_) != extent.y ||
|
||||
GPU_texture_format(tx_tmp_saved_) != format) {
|
||||
this->tx_tmp_saved_ = nullptr;
|
||||
}
|
||||
else {
|
||||
this->tx_ = tx_tmp_saved_;
|
||||
return;
|
||||
}
|
||||
}
|
||||
DrawEngineType *owner = (DrawEngineType *)owner_;
|
||||
this->tx_ = DRW_texture_pool_query_2d(UNPACK2(extent), format, owner);
|
||||
|
||||
this->tx_ = DRW_texture_pool_texture_acquire(
|
||||
DST.vmempool->texture_pool, UNPACK2(extent), format);
|
||||
}
|
||||
|
||||
void release(void)
|
||||
{
|
||||
/* Allows multiple release. */
|
||||
if (this->tx_ != nullptr) {
|
||||
tx_tmp_saved_ = this->tx_;
|
||||
this->tx_ = nullptr;
|
||||
if (this->tx_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears any reference. Workaround for pool texture not being able to release on demand.
|
||||
* Needs to be called at during the sync phase.
|
||||
*/
|
||||
void sync(void)
|
||||
{
|
||||
tx_tmp_saved_ = nullptr;
|
||||
DRW_texture_pool_texture_release(DST.vmempool->texture_pool, this->tx_);
|
||||
this->tx_ = nullptr;
|
||||
}
|
||||
|
||||
/** Remove methods that are forbidden with this type of textures. */
|
||||
|
||||
@@ -26,6 +26,7 @@ void DRW_texture_pool_free(DRWTexturePool *pool);
|
||||
/**
|
||||
* Try to find a texture corresponding to params into the texture pool.
|
||||
* If no texture was found, create one and add it to the pool.
|
||||
* DEPRECATED: Use DRW_texture_pool_texture_acquire instead and do it just before rendering.
|
||||
*/
|
||||
GPUTexture *DRW_texture_pool_query(
|
||||
DRWTexturePool *pool, int width, int height, eGPUTextureFormat format, void *user);
|
||||
|
||||
Reference in New Issue
Block a user