Metal: GLSL Compatibility - Hosting default uniform values.

There are a number of shaders, most notably grid_frag.glsl, which rely on default assignments to uniform values within shaders. This is not currently supported by the shader uniform push model implemented for the Metal backend, wherein uniform updates are pushed as a singular block of data. Any default assignment would become over-written.

As such, adding assignments of these default values in the high-level, to ensure the correct value is written for all APIs. This likely impacts Vulkan push-constants as well.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem

Maniphest Tasks: T96261

Differential Revision: https://developer.blender.org/D14555
This commit is contained in:
Jason Fielder 2022-04-27 13:00:36 +02:00 committed by Clément Foucault
parent cdd4354c81
commit db622b5a0b
Notes: blender-bot 2023-02-13 23:16:02 +01:00
Referenced by commit 74a44e816c, Fix error holding stack memory in a uniform
Referenced by issue #96261, Metal Viewport
8 changed files with 20 additions and 7 deletions

View File

@ -233,6 +233,7 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata,
DRW_shgroup_uniform_texture_ex(grp, "studioLight", sl->equirect_radiance_gputexture, state);
/* Do not fade-out when doing probe rendering, only when drawing the background. */
DRW_shgroup_uniform_float_copy(grp, "backgroundAlpha", 1.0f);
DRW_shgroup_uniform_float_copy(grp, "studioLightBlur", 0.0f);
}
else {
float background_alpha = g_data->background_alpha * shading->studiolight_background;
@ -240,6 +241,7 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata,
DRW_shgroup_uniform_float_copy(grp, "backgroundAlpha", background_alpha);
DRW_shgroup_uniform_float_copy(grp, "studioLightBlur", studiolight_blur);
DRW_shgroup_uniform_texture(grp, "probeCubes", txl->lookdev_cube_tx);
DRW_shgroup_uniform_float_copy(grp, "studioLightIntensity", 1.0f);
}
/* Common UBOs are setup latter. */

View File

@ -113,6 +113,9 @@ void EEVEE_material_bind_resources(DRWShadingGroup *shgrp,
DRW_shgroup_uniform_texture_ref(shgrp, "probePlanars", &vedata->txl->planar_pool);
DRW_shgroup_uniform_int_copy(shgrp, "outputSsrId", ssr_id ? *ssr_id : 0);
}
else {
DRW_shgroup_uniform_int_copy(shgrp, "outputSsrId", 1);
}
if (use_refract) {
DRW_shgroup_uniform_float_copy(
shgrp, "refractionDepth", (refract_depth) ? *refract_depth : 0.0);

View File

@ -6,8 +6,8 @@
#ifndef VOLUMETRICS
uniform int outputSsrId = 1;
uniform int outputSssId = 1;
uniform int outputSsrId; /*Default = 1;*/
uniform int outputSssId; /*Default = 1;*/
#endif

View File

@ -8,8 +8,8 @@ uniform sampler2D studioLight;
uniform float backgroundAlpha;
uniform mat3 StudioLightMatrix;
uniform float studioLightIntensity = 1.0;
uniform float studioLightBlur = 0.0;
uniform float studioLightIntensity; /* Default 1.0; */
uniform float studioLightBlur; /* Default 0.0; */
out vec4 FragColor;

View File

@ -179,10 +179,9 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
/* Verts */
state |= DRW_STATE_WRITE_DEPTH;
DRW_PASS_CREATE(psl->edit_mesh_verts_ps[i], state | pd->clipping_state);
int vert_mask[4] = {0xFF, 0xFF, 0xFF, 0xFF};
if (select_vert) {
int vert_mask[4] = {0xFF, 0xFF, 0xFF, 0xFF};
sh = OVERLAY_shader_edit_mesh_vert();
grp = pd->edit_mesh_verts_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_verts_ps[i]);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
@ -201,6 +200,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
DRW_shgroup_uniform_ivec4_copy(grp, "dataMask", vert_mask);
DRW_shgroup_state_enable(grp, DRW_STATE_WRITE_DEPTH);
}
else {

View File

@ -226,6 +226,9 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata)
GPUShader *sh;
struct GPUBatch *geom = DRW_cache_grid_get();
const float line_zero = 0;
const float grid_steps_default[8] = {0.001, 0.01, 0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0};
if (pd->space_type == SPACE_IMAGE) {
float mat[4][4];
@ -254,6 +257,7 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_vec3(grp, "gridSize", shd->grid_size, 1);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
DRW_shgroup_uniform_float(grp, "gridSteps", grid_steps_default, 8);
if (shd->zneg_flag & SHOW_AXIS_Z) {
DRW_shgroup_call(grp, geom, NULL);
}
@ -264,6 +268,7 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_vec3(grp, "planeAxes", shd->grid_axes, 1);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
DRW_shgroup_uniform_float_copy(grp, "lineKernel", line_zero);
DRW_shgroup_uniform_float(grp, "gridSteps", shd->grid_steps, ARRAY_SIZE(shd->grid_steps));
if (shd->grid_flag) {
DRW_shgroup_call(grp, geom, NULL);
@ -274,6 +279,8 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_vec3(grp, "planeAxes", shd->zplane_axes, 1);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
DRW_shgroup_uniform_float_copy(grp, "lineKernel", line_zero);
DRW_shgroup_uniform_float(grp, "gridSteps", grid_steps_default, 8);
if (shd->zpos_flag & SHOW_AXIS_Z) {
DRW_shgroup_call(grp, geom, NULL);
}

View File

@ -132,6 +132,7 @@ void OVERLAY_outline_cache_init(OVERLAY_Data *vedata)
pd->outlines_gpencil_grp = grp = DRW_shgroup_create(sh_gpencil, psl->outlines_prepass_ps);
DRW_shgroup_uniform_bool_copy(grp, "isTransform", (G.moving & G_TRANSFORM_OBJ) != 0);
DRW_shgroup_uniform_float_copy(grp, "strokeIndexOffset", 0.0);
}
/* outlines_prepass_ps is still needed for selection of probes. */

View File

@ -18,7 +18,7 @@ uniform int gridFlag;
uniform float zoomFactor;
#define STEPS_LEN 8 /* Match: #SI_GRID_STEPS_LEN */
uniform float gridSteps[STEPS_LEN] = float[](0.001, 0.01, 0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0);
uniform float gridSteps[STEPS_LEN];
#define AXIS_X (1 << 0)
#define AXIS_Y (1 << 1)