Skip to content

Commit

Permalink
Merge pull request #50644 from BastiaanOlij/mobile_compute_to_fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jul 25, 2021
2 parents 6b11d8c + 1f69582 commit 2a8a59e
Show file tree
Hide file tree
Showing 12 changed files with 843 additions and 38 deletions.
238 changes: 232 additions & 6 deletions servers/rendering/renderer_rd/effects_rd.cpp

Large diffs are not rendered by default.

90 changes: 89 additions & 1 deletion servers/rendering/renderer_rd/effects_rd.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "core/math/camera_matrix.h"
#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
#include "servers/rendering/renderer_rd/shaders/blur_raster.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/bokeh_dof.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/copy.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/copy_to_fb.glsl.gen.h"
Expand All @@ -41,6 +42,7 @@
#include "servers/rendering/renderer_rd/shaders/cubemap_filter.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/cubemap_roughness.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/luminance_reduce.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/luminance_reduce_raster.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/resolve.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/roughness_limiter.glsl.gen.h"
#include "servers/rendering/renderer_rd/shaders/screen_space_reflection.glsl.gen.h"
Expand All @@ -60,6 +62,63 @@
#include "servers/rendering_server.h"

class EffectsRD {
enum BlurRasterMode {
BLUR_MODE_GAUSSIAN_BLUR,
BLUR_MODE_GAUSSIAN_GLOW,
BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,

BLUR_MODE_DOF_LOW,
BLUR_MODE_DOF_MEDIUM,
BLUR_MODE_DOF_HIGH,

BLUR_MODE_MAX
};

enum {
BLUR_FLAG_HORIZONTAL = (1 << 0),
BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),
BLUR_FLAG_GLOW_FIRST_PASS = (1 << 2),
BLUR_FLAG_DOF_FAR = (1 << 3),
BLUR_FLAG_DOF_NEAR = (1 << 4),
};

struct BlurRasterPushConstant {
float pixel_size[2];
uint32_t flags;
uint32_t pad;

//glow
float glow_strength;
float glow_bloom;
float glow_hdr_threshold;
float glow_hdr_scale;

float glow_exposure;
float glow_white;
float glow_luminance_cap;
float glow_auto_exposure_grey;

//dof
float dof_far_begin;
float dof_far_end;
float dof_near_begin;
float dof_near_end;

float dof_radius;
float dof_pad[3];

float dof_dir[2];
float camera_z_far;
float camera_z_near;
};

struct BlurRaster {
BlurRasterPushConstant push_constant;
BlurRasterShaderRD shader;
RID shader_version;
PipelineCacheRD pipelines[BLUR_MODE_MAX];
} blur_raster;

enum CopyMode {
COPY_MODE_GAUSSIAN_COPY,
COPY_MODE_GAUSSIAN_COPY_8BIT,
Expand Down Expand Up @@ -239,6 +298,29 @@ class EffectsRD {
RID pipelines[LUMINANCE_REDUCE_MAX];
} luminance_reduce;

enum LuminanceReduceRasterMode {
LUMINANCE_REDUCE_FRAGMENT_FIRST,
LUMINANCE_REDUCE_FRAGMENT,
LUMINANCE_REDUCE_FRAGMENT_FINAL,
LUMINANCE_REDUCE_FRAGMENT_MAX
};

struct LuminanceReduceRasterPushConstant {
int32_t source_size[2];
int32_t dest_size[2];
float exposure_adjust;
float min_luminance;
float max_luminance;
float pad[1];
};

struct LuminanceReduceFragment {
LuminanceReduceRasterPushConstant push_constant;
LuminanceReduceRasterShaderRD shader;
RID shader_version;
PipelineCacheRD pipelines[LUMINANCE_REDUCE_FRAGMENT_MAX];
} luminance_reduce_raster;

struct CopyToDPPushConstant {
float z_far;
float z_near;
Expand Down Expand Up @@ -656,6 +738,8 @@ class EffectsRD {
RID _get_compute_uniform_set_from_texture_pair(RID p_texture, RID p_texture2, bool p_use_mipmaps = false);
RID _get_compute_uniform_set_from_image_pair(RID p_texture, RID p_texture2);

bool prefer_raster_effects;

public:
void copy_to_fb_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false, bool p_force_luminance = false, bool p_alpha_to_zero = false, bool p_srgb = false, RID p_secondary = RID());
void copy_to_rect(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y = false, bool p_force_luminance = false, bool p_all_source = false, bool p_8_bit_dst = false, bool p_alpha_to_one = false);
Expand All @@ -666,12 +750,16 @@ class EffectsRD {
void gaussian_blur(RID p_source_rd_texture, RID p_texture, RID p_back_texture, const Rect2i &p_region, bool p_8bit_dst = false);
void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);
void gaussian_glow(RID p_source_rd_texture, RID p_back_texture, const Size2i &p_size, float p_strength = 1.0, bool p_high_quality = false, bool p_first_pass = false, float p_luminance_cap = 16.0, float p_exposure = 1.0, float p_bloom = 0.0, float p_hdr_bleed_treshold = 1.0, float p_hdr_bleed_scale = 1.0, RID p_auto_exposure = RID(), float p_auto_exposure_grey = 1.0);
void gaussian_glow_raster(RID p_source_rd_texture, RID p_framebuffer_half, RID p_rd_texture_half, RID p_dest_framebuffer, const Vector2 &p_pixel_size, float p_strength = 1.0, bool p_high_quality = false, bool p_first_pass = false, float p_luminance_cap = 16.0, float p_exposure = 1.0, float p_bloom = 0.0, float p_hdr_bleed_treshold = 1.0, float p_hdr_bleed_scale = 1.0, RID p_auto_exposure = RID(), float p_auto_exposure_grey = 1.0);

void cubemap_roughness(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);
void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
void copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dest_texture, const Rect2 &p_rect, float p_z_near, float p_z_far, bool p_dp_flip);
void luminance_reduction(RID p_source_texture, const Size2i p_source_size, const Vector<RID> p_reduce, RID p_prev_luminance, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set = false);
void luminance_reduction_raster(RID p_source_texture, const Size2i p_source_size, const Vector<RID> p_reduce, Vector<RID> p_fb, RID p_prev_luminance, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set = false);

void bokeh_dof(RID p_base_texture, RID p_depth_texture, const Size2i &p_base_texture_size, RID p_secondary_texture, RID p_bokeh_texture1, RID p_bokeh_texture2, bool p_dof_far, float p_dof_far_begin, float p_dof_far_size, bool p_dof_near, float p_dof_near_begin, float p_dof_near_size, float p_bokeh_size, RS::DOFBokehShape p_bokeh_shape, RS::DOFBlurQuality p_quality, bool p_use_jitter, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
void blur_dof_raster(RID p_base_texture, RID p_depth_texture, const Size2i &p_base_texture_size, RID p_base_fb, RID p_secondary_texture, RID p_secondary_fb, bool p_dof_far, float p_dof_far_begin, float p_dof_far_size, bool p_dof_near, float p_dof_near_begin, float p_dof_near_size, float p_dof_blur_amount, RS::DOFBlurQuality p_quality, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);

struct TonemapSettings {
bool use_glow = false;
Expand Down Expand Up @@ -751,7 +839,7 @@ class EffectsRD {

void sort_buffer(RID p_uniform_set, int p_size);

EffectsRD();
EffectsRD(bool p_prefer_raster_effects);
~EffectsRD();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ void RenderForwardMobile::RenderBufferDataForwardMobile::configure(RID p_color_b
RD::DataFormat color_format = RenderForwardMobile::singleton->_render_buffers_get_color_format();

if (p_msaa == RS::VIEWPORT_MSAA_DISABLED) {
if (color_format == RD::DATA_FORMAT_A2B10G10R10_UNORM_PACK32) {
// @TODO add a second color buffer for alpha as this format is RGB only
}

Vector<RID> fb;
fb.push_back(p_color_buffer);
fb.push_back(depth);
Expand Down Expand Up @@ -165,15 +161,12 @@ bool RenderForwardMobile::free(RID p_rid) {

RD::DataFormat RenderForwardMobile::_render_buffers_get_color_format() {
// Using 32bit buffers enables AFBC on mobile devices which should have a definate performance improvement (MALI G710 and newer support this on 64bit RTs)
// NO ALPHA and unsigned float.
// @TODO No alpha is an issue, recommendation here is to add a second RT for alpha
return RD::DATA_FORMAT_A2B10G10R10_UNORM_PACK32;
}

bool RenderForwardMobile::_render_buffers_can_be_storage() {
// Using 32bit buffers enables AFBC on mobile devices which should have a definate performance improvement (MALI G710 and newer support this on 64bit RTs)
// NO ALPHA and unsigned float.
// @TODO No alpha is an issue, recommendation here is to add a second RT for alpha
// Doesn't support storage
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions servers/rendering/renderer_rd/renderer_compositor_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ RendererCompositorRD::RendererCompositorRD() {
// default to our high end renderer
scene = memnew(RendererSceneRenderImplementation::RenderForwardClustered(storage));
}

// now we're ready to create our effects,
storage->init_effects(!scene->_render_buffers_can_be_storage());
}

RendererCompositorRD::~RendererCompositorRD() {
Expand Down
Loading

0 comments on commit 2a8a59e

Please sign in to comment.