GPU: Shader CodeBase use constexpr instead of const

Do this only when applicable.

This allow better compile time checking in Shader C++ compilation.
Moreover, this allows to have `constexpr` in shared code between
C++ and GLSL.

After investigation the `const` keyword in GLSL has the same
semantic than C/C++.

Rel #137333 and #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137497
This commit is contained in:
Clément Foucault
2025-04-15 11:36:53 +02:00
committed by Clément Foucault
parent f71358d281
commit 47d2dffe8c
118 changed files with 476 additions and 452 deletions

View File

@@ -105,7 +105,7 @@ void main()
/* Compute the overlap polynomial parameters for 8-sector ellipse based on the equations in
* section "3 Alternative Weighting Functions" of the polynomial weights paper. More on this
* later in the code. */
const int number_of_sectors = 8;
constexpr int number_of_sectors = 8;
float sector_center_overlap_parameter = 2.0f / radius;
float sector_envelope_angle = ((3.0f / 2.0f) * M_PI) / number_of_sectors;
float cross_sector_overlap_parameter = (sector_center_overlap_parameter +

View File

@@ -19,8 +19,8 @@ void main()
/* The weight kernels of the filter optimized for rotational symmetry described in section
* "3.2.1 Gradient Calculation". */
const float corner_weight = 0.182f;
const float center_weight = 1.0f - 2.0f * corner_weight;
constexpr float corner_weight = 0.182f;
constexpr float center_weight = 1.0f - 2.0f * corner_weight;
float3 x_partial_derivative = texture_load(input_tx, texel + int2(-1, 1)).rgb * -corner_weight +
texture_load(input_tx, texel + int2(-1, 0)).rgb * -center_weight +

View File

@@ -33,8 +33,8 @@ void node_composite_color_correction(float4 color,
const float3 luminance_coefficients,
out float4 result)
{
const float margin = 0.10f;
const float margin_divider = 0.5f / margin;
constexpr float margin = 0.10f;
constexpr float margin_divider = 0.5f / margin;
float level = (color.r + color.g + color.b) / 3.0f;
float level_shadows = 0.0f;
float level_midtones = 0.0f;

View File

@@ -4,7 +4,7 @@
#include "gpu_shader_common_color_utils.glsl"
void color_to_luminance(float4 color, const float3 luminance_coefficients, out float result)
void color_to_luminance(float4 color, float3 luminance_coefficients, out float result)
{
result = get_luminance(color.rgb, luminance_coefficients);
}

View File

@@ -9,7 +9,7 @@
* parameter in the [0, 1] range. */
float3 compute_hue_curve_map_coordinates(float3 parameters)
{
const float sampler_resolution = 257.0f;
constexpr float sampler_resolution = 257.0f;
float sampler_offset = 0.5f / sampler_resolution;
float sampler_scale = 1.0f - (1.0f / sampler_resolution);
return parameters * sampler_scale + sampler_offset;

View File

@@ -124,7 +124,7 @@ float ambient_ambient_occlusion_search_horizon(float3 vI,
}
/* Bias depth a bit to avoid self shadowing issues. */
const float bias = 2.0f * 2.4e-7f;
constexpr float bias = 2.0f * 2.4e-7f;
depth += (inverted != 0.0f) ? -bias : bias;
float3 s = drw_point_screen_to_view(float3(uv, depth));
@@ -193,7 +193,7 @@ float2 ambient_occlusion_clamp_horizons_to_hemisphere(float2 horizons,
const float inverted)
{
/* Add a little bias to fight self shadowing. */
const float max_angle = M_PI_2 - 0.05f;
constexpr float max_angle = M_PI_2 - 0.05f;
if (inverted != 0.0f) {
horizons.x = max(horizons.x, angle_N + max_angle);
@@ -395,7 +395,7 @@ float ambient_occlusion_specular(
float vis_angle = acos_fast(sqrt(1 - visibility));
/* Roughness to cone angle (eq. 26). */
/* A 0.001 min_angle can generate NaNs on Intel GPUs. See D12508. */
const float min_angle = 0.00990998744964599609375f;
constexpr float min_angle = 0.00990998744964599609375f;
float spec_angle = max(min_angle, acos_fast(ambient_occlusion_cone_cosine(roughness)));
/* Angle between cone axes. */
float cone_cone_dist = acos_fast(saturate(dot(visibility_dir, specular_dir)));

View File

@@ -46,7 +46,7 @@ float bxdf_ggx_smith_G1(float NX, float a2)
*
* \return: the sampled direction and the pdf of sampling the direction.
*/
BsdfSample bxdf_ggx_sample_reflection(float3 rand, float3 Vt, float alpha, const bool do_clamp)
BsdfSample bxdf_ggx_sample_reflection(float3 rand, float3 Vt, float alpha, bool do_clamp)
{
if (do_clamp && alpha < square(BSDF_ROUGHNESS_THRESHOLD)) {
BsdfSample samp;
@@ -97,7 +97,7 @@ BsdfSample bxdf_ggx_sample_reflection(float3 rand, float3 Vt, float alpha, const
/* Evaluate the GGX BRDF without the Fresnel term, multiplied by the cosine foreshortening term.
* Also evaluate the probability of sampling the reflection direction. */
BsdfEval bxdf_ggx_eval_reflection(float3 N, float3 L, float3 V, float alpha, const bool do_clamp)
BsdfEval bxdf_ggx_eval_reflection(float3 N, float3 L, float3 V, float alpha, bool do_clamp)
{
float NV = dot(N, V);
if (NV <= 0.0f) {

View File

@@ -22,7 +22,7 @@ BsdfSample bxdf_oren_nayar_sample(float3 random_point_cos_hemisphere)
{
/* Bias the rays so we never get really high energy rays almost parallel to the surface.
* Also reduces shadow terminator artifacts. */
const float bias = 0.05f;
constexpr float bias = 0.05f;
random_point_cos_hemisphere = normalize(random_point_cos_hemisphere + float3(0.0f, 0.0f, bias));
float cos_theta = random_point_cos_hemisphere.z;

View File

@@ -77,7 +77,7 @@ float3 camera_mirror_ball_to_direction(CameraData cam, float2 uv)
return float3(0.0f);
}
dir.z = -safe_sqrt(1.0f - square(dir.x) - square(dir.y));
const float3 I = float3(0.0f, 0.0f, 1.0f);
constexpr float3 I = float3(0.0f, 0.0f, 1.0f);
return reflect(I, dir);
}

View File

@@ -58,7 +58,7 @@ void main()
/* Bias the shading point position because of depth buffer precision.
* Constant is taken from https://www.terathon.com/gdc07_lengyel.pdf. */
const float bias = 2.4e-7f;
constexpr float bias = 2.4e-7f;
depth -= bias;
float3 P = drw_point_screen_to_world(float3(uvcoordsvar.xy, depth));

View File

@@ -115,7 +115,7 @@ void main()
/* Bias the shading point position because of depth buffer precision.
* Constant is taken from https://www.terathon.com/gdc07_lengyel.pdf. */
const float bias = 2.4e-7f;
constexpr float bias = 2.4e-7f;
depth -= bias;
float3 P = drw_point_screen_to_world(float3(uvcoordsvar.xy, depth));

View File

@@ -158,9 +158,9 @@ void dof_gather_accumulate_sample_pair(DofGatherData pair_data[2],
}
#if 0
const float mirroring_threshold = -dof_layer_threshold - dof_layer_offset;
constexpr float mirroring_threshold = -dof_layer_threshold - dof_layer_offset;
/* TODO(fclem) Promote to parameter? dither with Noise? */
const float mirroring_min_distance = 15.0f;
constexpr float mirroring_min_distance = 15.0f;
if (pair_data[0].coc < mirroring_threshold &&
(pair_data[1].coc - mirroring_min_distance) > pair_data[0].coc)
{
@@ -426,7 +426,7 @@ void dof_gather_init(float base_radius,
/* TODO(fclem) Seems like the default lod selection is too big. Bias to avoid blocky moving out
* of focus shapes. */
const float lod_bias = -2.0f;
constexpr float lod_bias = -2.0f;
lod = max(floor(log2(base_radius * unit_sample_radius) + 0.5f) + lod_bias, 0.0f);
if (no_gather_mipmaps) {
@@ -547,8 +547,8 @@ void dof_gather_accumulator(sampler2D color_tx,
ring += gather_density_change_ring;
/* We need to account for the density change in the weights (slide 62).
* For that multiply old kernel data by its area divided by the new kernel area. */
const float outer_rings_weight = 1.0f /
(radius_downscale_factor * radius_downscale_factor);
constexpr float outer_rings_weight = 1.0f /
(radius_downscale_factor * radius_downscale_factor);
/* Samples are already weighted per ring in foreground pass. */
if (!IS_FOREGROUND) {
dof_gather_amend_weight(accum_data, outer_rings_weight);
@@ -628,7 +628,7 @@ void dof_slight_focus_gather(depth2D depth_tx,
int i_radius = clamp(int(radius), 0, int(dof_layer_threshold));
const float sample_count_max = float(DOF_SLIGHT_FOCUS_SAMPLE_MAX);
constexpr float sample_count_max = float(DOF_SLIGHT_FOCUS_SAMPLE_MAX);
/* Scale by search area. */
float sample_count = sample_count_max * saturate(square(radius) / square(dof_layer_threshold));
@@ -657,7 +657,7 @@ void dof_slight_focus_gather(depth2D depth_tx,
}
float bordering_radius = ring_dist + 0.5f;
const float isect_mul = 1.0f;
constexpr float isect_mul = 1.0f;
DofGatherData bg_ring = GATHER_DATA_INIT;
dof_gather_accumulate_sample_pair(
pair_data, bordering_radius, isect_mul, first_ring, false, false, bg_ring, bg_accum);

View File

@@ -74,7 +74,7 @@ float dof_hdr_color_weight(float4 color)
/* Very fast "luma" weighting. */
float luma = (color.g * 2.0f) + (color.r + color.b);
/* TODO(fclem) Pass correct exposure. */
const float exposure = 1.0f;
constexpr float exposure = 1.0f;
return 1.0f / (luma * exposure + 4.0f);
}
@@ -99,7 +99,7 @@ float4 dof_bilateral_coc_weights(float4 cocs)
{
float chosen_coc = dof_coc_select(cocs);
const float scale = 4.0f; /* TODO(fclem) revisit. */
constexpr float scale = 4.0f; /* TODO(fclem) revisit. */
/* NOTE: The difference between the cocs should be inside a abs() function,
* but we follow UE4 implementation to improve how dithered transparency looks (see slide 19). */
return saturate(1.0f - (chosen_coc - cocs) * scale);
@@ -162,7 +162,7 @@ float dof_sample_weight(float coc)
return min(1.0f, 1.0f / square(coc));
#else
/* Full intensity if CoC radius is below the pixel footprint. */
const float min_coc = 1.0f;
constexpr float min_coc = 1.0f;
coc = max(min_coc, abs(coc));
return (M_PI * min_coc * min_coc) / (M_PI * coc * coc);
#endif
@@ -173,7 +173,7 @@ float4 dof_sample_weight(float4 coc)
return min(float4(1.0f), 1.0f / square(coc));
#else
/* Full intensity if CoC radius is below the pixel footprint. */
const float min_coc = 1.0f;
constexpr float min_coc = 1.0f;
coc = max(float4(min_coc), abs(coc));
return (M_PI * min_coc * min_coc) / (M_PI * coc * coc);
#endif

View File

@@ -40,7 +40,7 @@ float dof_scatter_neighborhood_rejection(float3 color)
ref = min(float3(dof_buf.scatter_neighbor_max_color), ref);
float diff = reduce_max(max(float3(0.0f), abs(ref - color)));
const float rejection_threshold = 0.7f;
constexpr float rejection_threshold = 0.7f;
diff = saturate(diff / rejection_threshold - 1.0f);
validity = max(validity, diff);
}
@@ -59,19 +59,19 @@ float dof_scatter_screen_border_rejection(float coc, int2 texel)
/* Full-resolution to half-resolution CoC. */
coc *= 0.5f;
/* Allow 10px transition. */
const float rejection_hardness = 1.0f / 10.0f;
constexpr float rejection_hardness = 1.0f / 10.0f;
return saturate((min_screen_border_distance - abs(coc)) * rejection_hardness + 1.0f);
}
float dof_scatter_luminosity_rejection(float3 color)
{
const float rejection_hardness = 1.0f;
constexpr float rejection_hardness = 1.0f;
return saturate(reduce_max(color - dof_buf.scatter_color_threshold) * rejection_hardness);
}
float dof_scatter_coc_radius_rejection(float coc)
{
const float rejection_hardness = 0.3f;
constexpr float rejection_hardness = 0.3f;
return saturate((abs(coc) - dof_buf.scatter_coc_threshold) * rejection_hardness);
}

View File

@@ -84,7 +84,7 @@ float3 dof_neighborhood_clamp(float2 frag_coord, float3 color, float center_coc,
{
/* Stabilize color by clamping with the stable half res neighborhood. */
float3 neighbor_min, neighbor_max;
const float2 corners[4] = float2_array(
constexpr float2 corners[4] = float2_array(
float2(-1, -1), float2(1, -1), float2(-1, 1), float2(1, 1));
for (int i = 0; i < 4; i++) {
/**
@@ -152,11 +152,11 @@ void main()
float4 layer_color;
float layer_weight;
const float3 hole_fill_color = float3(0.2f, 0.1f, 1.0f);
const float3 background_color = float3(0.1f, 0.2f, 1.0f);
const float3 slight_focus_color = float3(1.0f, 0.2f, 0.1f);
const float3 focus_color = float3(1.0f, 1.0f, 0.1f);
const float3 foreground_color = float3(0.2f, 1.0f, 0.1f);
constexpr float3 hole_fill_color = float3(0.2f, 0.1f, 1.0f);
constexpr float3 background_color = float3(0.1f, 0.2f, 1.0f);
constexpr float3 slight_focus_color = float3(1.0f, 0.2f, 0.1f);
constexpr float3 focus_color = float3(1.0f, 1.0f, 0.1f);
constexpr float3 foreground_color = float3(0.2f, 1.0f, 0.1f);
if (!no_hole_fill_pass && prediction.do_hole_fill) {
layer_color = textureLod(color_hole_fill_tx, uv_halfres, 0.0f);

View File

@@ -53,7 +53,7 @@ void main()
float2 uv = gl_FragCoord.xy / float2(textureSize(occlusion_tx, 0).xy);
float2 occlusion_data = texture(occlusion_tx, uv).rg;
/* Fix tilling artifacts. (Slide 90) */
const float correction_fac = 1.0f - DOF_FAST_GATHER_COC_ERROR;
constexpr float correction_fac = 1.0f - DOF_FAST_GATHER_COC_ERROR;
/* Occlude the sprite with geometry from the same field using a chebychev test (slide 85). */
float mean = occlusion_data.x;
float variance = occlusion_data.y;

View File

@@ -113,7 +113,7 @@ float dof_luma_weight(float luma)
{
/* Slide 20 of "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014. */
/* To preserve more details in dark areas, we use a bigger bias. */
const float exposure_scale = 1.0f; /* TODO. */
constexpr float exposure_scale = 1.0f; /* TODO. */
return 1.0f / (4.0f + luma * exposure_scale);
}
@@ -129,7 +129,7 @@ float dof_bilateral_weight(float reference_coc, float sample_coc)
DofSample dof_spatial_filtering()
{
/* Plus (+) shape offsets. */
const int2 plus_offsets[4] = int2_array(int2(-1, 0), int2(0, -1), int2(1, 0), int2(0, 1));
constexpr int2 plus_offsets[4] = int2_array(int2(-1, 0), int2(0, -1), int2(1, 0), int2(0, 1));
DofSample center = dof_fetch_input_sample(int2(0));
DofSample accum = DofSample(float4(0.0f), 0.0f);
float accum_weight = 0.0f;
@@ -169,7 +169,7 @@ struct DofNeighborhoodMinMax {
DofNeighborhoodMinMax dof_neighbor_boundbox()
{
/* Plus (+) shape offsets. */
const int2 plus_offsets[4] = int2_array(int2(-1, 0), int2(0, -1), int2(1, 0), int2(0, 1));
constexpr int2 plus_offsets[4] = int2_array(int2(-1, 0), int2(0, -1), int2(1, 0), int2(0, 1));
/**
* Simple bounding box calculation in YCoCg as described in:
* "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014
@@ -187,7 +187,7 @@ DofNeighborhoodMinMax dof_neighbor_boundbox()
* Round bbox shape by averaging 2 different min/max from 2 different neighborhood. */
DofSample min_c_3x3 = min_c;
DofSample max_c_3x3 = max_c;
const int2 corners[4] = int2_array(int2(-1, -1), int2(1, -1), int2(-1, 1), int2(1, 1));
constexpr int2 corners[4] = int2_array(int2(-1, -1), int2(1, -1), int2(-1, 1), int2(1, 1));
for (int i = 0; i < 4; i++) {
DofSample samp = dof_fetch_input_sample(corners[i]);
min_c_3x3.color = min(min_c_3x3.color, samp.color);
@@ -210,7 +210,7 @@ float2 dof_pixel_history_motion_vector(int2 texel_sample)
* Dilate velocity by using the nearest pixel in a cross pattern.
* "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014 (Slide 27)
*/
const int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2));
constexpr int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2));
float min_depth = dof_fetch_half_depth(int2(0));
int2 nearest_texel = int2(0);
for (int i = 0; i < 4; i++) {

View File

@@ -13,13 +13,13 @@ void main()
{
/* Constant array moved inside function scope.
* Minimizes local register allocation in MSL. */
const float2 pos[6] = float2_array(float2(-1.0f, -1.0f),
float2(1.0f, -1.0f),
float2(-1.0f, 1.0f),
constexpr float2 pos[6] = float2_array(float2(-1.0f, -1.0f),
float2(1.0f, -1.0f),
float2(-1.0f, 1.0f),
float2(1.0f, -1.0f),
float2(1.0f, 1.0f),
float2(-1.0f, 1.0f));
float2(1.0f, -1.0f),
float2(1.0f, 1.0f),
float2(-1.0f, 1.0f));
float2 lP = pos[gl_VertexID % 6];
int display_index = gl_VertexID / 6;

View File

@@ -13,13 +13,13 @@ void main()
{
/* Constant array moved inside function scope.
* Minimizes local register allocation in MSL. */
const float2 pos[6] = float2_array(float2(-1.0f, -1.0f),
float2(1.0f, -1.0f),
float2(-1.0f, 1.0f),
constexpr float2 pos[6] = float2_array(float2(-1.0f, -1.0f),
float2(1.0f, -1.0f),
float2(-1.0f, 1.0f),
float2(1.0f, -1.0f),
float2(1.0f, 1.0f),
float2(-1.0f, 1.0f));
float2(1.0f, -1.0f),
float2(1.0f, 1.0f),
float2(-1.0f, 1.0f));
lP = pos[gl_VertexID % 6];
int display_index = gl_VertexID / 6;

View File

@@ -13,13 +13,13 @@ void main()
{
/* Constant array moved inside function scope.
* Minimizes local register allocation in MSL. */
const float2 pos[6] = float2_array(float2(-1.0f, -1.0f),
float2(1.0f, -1.0f),
float2(-1.0f, 1.0f),
constexpr float2 pos[6] = float2_array(float2(-1.0f, -1.0f),
float2(1.0f, -1.0f),
float2(-1.0f, 1.0f),
float2(1.0f, -1.0f),
float2(1.0f, 1.0f),
float2(-1.0f, 1.0f));
float2(1.0f, -1.0f),
float2(1.0f, 1.0f),
float2(-1.0f, 1.0f));
lP = pos[gl_VertexID % 6];
int cell_index = gl_VertexID / 6;

View File

@@ -251,7 +251,7 @@ float2 film_pixel_history_motion_vector(int2 texel_sample)
* Dilate velocity by using the nearest pixel in a cross pattern.
* "High Quality Temporal Supersampling" by Brian Karis at SIGGRAPH 2014 (Slide 27)
*/
const int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2));
constexpr int2 corners[4] = int2_array(int2(-2, -2), int2(2, -2), int2(-2, 2), int2(2, 2));
float min_depth = texelFetch(depth_tx, texel_sample, 0).x;
int2 nearest_texel = texel_sample;
for (int i = 0; i < 4; i++) {
@@ -347,11 +347,11 @@ float4 film_sample_catmull_rom(sampler2D color_tx, float2 input_texel)
void film_combined_neighbor_boundbox(int2 texel, out float4 min_c, out float4 max_c)
{
/* Plus (+) shape offsets. */
const int2 plus_offsets[5] = int2_array(int2(0, 0), /* Center */
int2(-1, 0),
int2(0, -1),
int2(1, 0),
int2(0, 1));
constexpr int2 plus_offsets[5] = int2_array(int2(0, 0), /* Center */
int2(-1, 0),
int2(0, -1),
int2(1, 0),
int2(0, 1));
#if 0
/**
* Compute Variance of neighborhood as described in:
@@ -372,7 +372,7 @@ void film_combined_neighbor_boundbox(int2 texel, out float4 min_c, out float4 ma
/* Extent scaling. Range [0.75..1.25].
* Balance between more flickering (0.75) or more ghosting (1.25). */
const float gamma = 1.25f;
constexpr float gamma = 1.25f;
/* Standard deviation. */
float4 sigma = sqrt(abs(mu2 - square(mu1)));
/* eq. 6 in "A Survey of Temporal Anti-aliasing Techniques". */
@@ -394,7 +394,7 @@ void film_combined_neighbor_boundbox(int2 texel, out float4 min_c, out float4 ma
* Round bbox shape by averaging 2 different min/max from 2 different neighborhood. */
float4 min_c_3x3 = min_c;
float4 max_c_3x3 = max_c;
const int2 corners[4] = int2_array(int2(-1, -1), int2(1, -1), int2(-1, 1), int2(1, 1));
constexpr int2 corners[4] = int2_array(int2(-1, -1), int2(1, -1), int2(-1, 1), int2(1, 1));
for (int i = 0; i < 4; i++) {
float4 color = film_texelfetch_as_YCoCg_opacity(combined_tx, texel + corners[i]);
min_c_3x3 = min(min_c_3x3, color);

View File

@@ -27,7 +27,7 @@
float filter_gaussian_factor(float linear_distance, float standard_deviation)
{
/* Account for `filter_gaussian_factor` using `exp2` for speed (`exp(x) = exp2(x / log(2))`). */
const float log_2_inv = 1.442695041f;
constexpr float log_2_inv = 1.442695041f;
return log_2_inv * standard_deviation / square(linear_distance);
}

View File

@@ -312,7 +312,7 @@ bool gbuffer_is_refraction(float4 gbuffer)
uint gbuffer_geometry_normal_pack(float3 Ng, float3 N)
{
/* This is a threshold that minimizes the error over the sphere. */
const float quantization_multiplier = 1.360f;
constexpr float quantization_multiplier = 1.360f;
/* Normalize for comparison. */
float3 Ng_quantize = normalize(round(quantization_multiplier * Ng));
/* Note: Comparing the error using cosines. The greater the cosine value, the lower the error. */
@@ -915,7 +915,7 @@ GBufferWriter gbuffer_pack(GBufferData data_in, float3 Ng)
int gbuffer_closure_count(uint header)
{
/* NOTE: Need to be adjusted for different global GBUFFER_LAYER_MAX. */
const uint bits_per_layer = uint(GBUFFER_HEADER_BITS_PER_LAYER);
constexpr uint bits_per_layer = uint(GBUFFER_HEADER_BITS_PER_LAYER);
uint3 closure_types = (uint3(header) >> (uint3(0u, 1u, 2u) * bits_per_layer)) &
((1u << bits_per_layer) - 1);
return reduce_add(int3(not(equal(closure_types, uint3(0u)))));
@@ -924,10 +924,10 @@ int gbuffer_closure_count(uint header)
bool gbuffer_has_transmission(uint header)
{
/* NOTE: Need to be adjusted for different global GBUFFER_LAYER_MAX. */
const uint bits_per_layer = uint(GBUFFER_HEADER_BITS_PER_LAYER);
const uint header_mask = (GBUF_TRANSMISSION_BIT << (bits_per_layer * 0)) |
(GBUF_TRANSMISSION_BIT << (bits_per_layer * 1)) |
(GBUF_TRANSMISSION_BIT << (bits_per_layer * 2));
constexpr uint bits_per_layer = uint(GBUFFER_HEADER_BITS_PER_LAYER);
constexpr uint header_mask = (GBUF_TRANSMISSION_BIT << (bits_per_layer * 0)) |
(GBUF_TRANSMISSION_BIT << (bits_per_layer * 1)) |
(GBUF_TRANSMISSION_BIT << (bits_per_layer * 2));
return (header & header_mask) != 0;
}
@@ -949,7 +949,7 @@ ClosureType gbuffer_closure_type_get_by_bin(uint header, uchar bin_index)
{
/* TODO(fclem): Doesn't take GBUF_METAL_CLEARCOAT into account or other mode that could merge two
* bins into one layer. */
const int bits_per_layer = GBUFFER_HEADER_BITS_PER_LAYER;
constexpr int bits_per_layer = GBUFFER_HEADER_BITS_PER_LAYER;
uint mode = (header >> (bin_index * bits_per_layer)) & ((1u << bits_per_layer) - 1);
return gbuffer_mode_to_closure_type(mode);
}

View File

@@ -58,7 +58,7 @@ SphericalHarmonicL1 load_spherical_harmonic(int2 texel)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -68,7 +68,7 @@ SphericalHarmonicL1 load_spherical_harmonic(int2 texel, bool valid)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -14,7 +14,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_horizon_scan)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -160,7 +160,7 @@ HorizonScanResult horizon_scan_eval(float3 vP,
}
/* Bias depth a bit to avoid self shadowing issues. */
const float bias = 2.0f * 2.4e-7f;
constexpr float bias = 2.0f * 2.4e-7f;
sample_depth += reversed ? -bias : bias;
float3 vP_sample_front = drw_point_screen_to_view(float3(sample_uv, sample_depth));

View File

@@ -22,7 +22,7 @@
*/
uint horizon_scan_angles_to_bitmask(float2 theta)
{
const int bitmask_len = 32;
constexpr int bitmask_len = 32;
/* Algorithm 1, line 18. Re-ordered to make sure to clamp to the hemisphere range. */
float2 ratio = saturate(theta * M_1_PI + 0.5f);
uint a = uint(floor(float(bitmask_len) * ratio.x));
@@ -34,7 +34,7 @@ uint horizon_scan_angles_to_bitmask(float2 theta)
float horizon_scan_bitmask_to_visibility_uniform(uint bitmask)
{
const int bitmask_len = 32;
constexpr int bitmask_len = 32;
/* Algorithm 1, line 26. */
return float(bitCount(bitmask)) / float(bitmask_len);
}
@@ -59,7 +59,7 @@ float horizon_scan_bitmask_to_occlusion_cosine(uint bitmask)
* distribution in `horizon_scan_angles_to_bitmask()` but that requires more computation per
* samples. The quality difference does not justify it currently. */
#if 0 /* Reference. */
const int bitmask_len = 32;
constexpr int bitmask_len = 32;
float visibility = 0.0f;
for (int bit = 0; bit < bitmask_len; bit++) {
float angle = (((float(bit) + 0.5f) / float(bitmask_len)) - 0.5f) * M_PI;
@@ -73,8 +73,8 @@ float horizon_scan_bitmask_to_occlusion_cosine(uint bitmask)
/* The precomputed weights are the accumulated weights from the reference loop for each of the
* samples in the mask. The weight is distributed evenly for each sample inside a mask.
* This is like a 4 piecewise linear approximation of the cosine lobe. */
const float4 weights = float4(0.0095061f, 0.0270951f, 0.0405571f, 0.0478421f);
const uint4 masks = uint4(0xF000000Fu, 0x0F0000F0u, 0x00F00F00u, 0x000FF000u);
constexpr float4 weights = float4(0.0095061f, 0.0270951f, 0.0405571f, 0.0478421f);
constexpr uint4 masks = uint4(0xF000000Fu, 0x0F0000F0u, 0x00F00F00u, 0x000FF000u);
return saturate(1.0f - dot(float4(bitCount(uint4(bitmask) & masks)), weights));
#endif
}

View File

@@ -34,7 +34,7 @@ void main()
TEST(eevee_horizon_scan, UniformOcclusion)
{
const float esp = 1e-4f;
constexpr float esp = 1e-4f;
EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_uniform(0x00000000u), 1.0f, esp);
EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_uniform(0xFFFFFFFFu), 0.0f, esp);
EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_uniform(0xFFFF0000u), 0.5f, esp);
@@ -45,7 +45,7 @@ void main()
TEST(eevee_horizon_scan, CosineOcclusion)
{
const float esp = 1e-5f;
constexpr float esp = 1e-5f;
EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_cosine(0x00000000u), 1.0f, esp);
EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_cosine(0xFFFFFFFFu), 0.0f, esp);
EXPECT_NEAR(horizon_scan_bitmask_to_occlusion_cosine(0xFFFF0000u), 0.5f, esp);

View File

@@ -58,7 +58,7 @@ float4 tile_bound_cylinder(float3 v00, float3 v01, float3 v10, float3 v11)
float2 tile_to_ndc(float2 tile_co, float2 offset)
{
/* Add a margin to prevent culling too much if the frustum becomes too much unstable. */
const float margin = 0.02f;
constexpr float margin = 0.02f;
tile_co += margin * (offset * 2.0f - 1.0f);
tile_co += offset;

View File

@@ -22,7 +22,7 @@ shared uint zbin_min[CULLING_ZBIN_COUNT];
void main()
{
const uint zbin_iter = CULLING_ZBIN_COUNT / gl_WorkGroupSize.x;
constexpr uint zbin_iter = CULLING_ZBIN_COUNT / gl_WorkGroupSize.x;
const uint zbin_local = gl_LocalInvocationID.x * zbin_iter;
for (uint i = 0u, l = zbin_local; i < zbin_iter; i++, l++) {

View File

@@ -26,7 +26,7 @@ float roughness_from_relative_mip(float prev_mip_roughness, float curr_mip_rough
return curr_mip_roughness;
#else
/* The exponent should be 2 but result is a bit less blurry than expected in practice. */
const float exponent = 3.0f;
constexpr float exponent = 3.0f;
/* From linear roughness to GGX roughness input. */
float m_prev = pow(prev_mip_roughness, exponent);
float m_curr = pow(curr_mip_roughness, exponent);

View File

@@ -26,7 +26,7 @@ void main()
/* First sum onto the local memory. */
uint valid_data_len = probe_remap_dispatch_size.x * probe_remap_dispatch_size.y;
const uint iter_count = uint(SPHERE_PROBE_MAX_HARMONIC) / gl_WorkGroupSize.x;
constexpr uint iter_count = uint(SPHERE_PROBE_MAX_HARMONIC) / gl_WorkGroupSize.x;
for (uint i = 0; i < iter_count; i++) {
uint index = gl_WorkGroupSize.x * i + gl_LocalInvocationIndex;
if (index >= valid_data_len) {
@@ -48,7 +48,7 @@ void main()
local_sh_coefs[local_index][3] = sh.L1.Mp1;
/* Parallel sum. */
const uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y;
constexpr uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y;
uint stride = group_size / 2;
for (int i = 0; i < 10; i++) {
barrier();

View File

@@ -97,8 +97,9 @@ float2 sphere_probe_direction_to_uv(float3 L, float lod, SphereProbeUvArea uv_ar
float sphere_probe_roughness_to_mix_fac(float roughness)
{
const float scale = 1.0f / (SPHERE_PROBE_MIX_END_ROUGHNESS - SPHERE_PROBE_MIX_START_ROUGHNESS);
const float bias = scale * SPHERE_PROBE_MIX_START_ROUGHNESS;
constexpr float scale = 1.0f /
(SPHERE_PROBE_MIX_END_ROUGHNESS - SPHERE_PROBE_MIX_START_ROUGHNESS);
constexpr float bias = scale * SPHERE_PROBE_MIX_START_ROUGHNESS;
return square(saturate(roughness * scale - bias));
}
@@ -119,8 +120,8 @@ float sphere_probe_lod_to_roughness(float lod)
/* Inverse of sphere_probe_roughness_to_lod. */
float mip_ratio = lod / float(SPHERE_PROBE_MIPMAP_LEVELS - 1);
float a = mip_ratio;
const float b = 0.6f; /* Factor of ratio. */
const float c = 0.4f; /* Factor of ratio_sqrt. */
constexpr float b = 0.6f; /* Factor of ratio. */
constexpr float c = 0.4f; /* Factor of ratio_sqrt. */
float b2 = square(b);
float c2 = square(c);
float c4 = square(c2);

View File

@@ -115,7 +115,7 @@ void main()
{
uint work_group_index = gl_NumWorkGroups.x * gl_WorkGroupID.y + gl_WorkGroupID.x;
const uint local_index = gl_LocalInvocationIndex;
const uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y;
constexpr uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y;
SphereProbeUvArea world_coord = reinterpret_as_atlas_coord(world_coord_packed);
SphereProbeUvArea sample_coord = reinterpret_as_atlas_coord(probe_coord_packed);

View File

@@ -26,7 +26,7 @@ void main()
/* First sum onto the local memory. */
uint valid_data_len = probe_remap_dispatch_size.x * probe_remap_dispatch_size.y;
const uint iter_count = uint(SPHERE_PROBE_MAX_HARMONIC) / gl_WorkGroupSize.x;
constexpr uint iter_count = uint(SPHERE_PROBE_MAX_HARMONIC) / gl_WorkGroupSize.x;
for (uint i = 0; i < iter_count; i++) {
uint index = gl_WorkGroupSize.x * i + gl_LocalInvocationIndex;
if (index >= valid_data_len) {
@@ -42,7 +42,7 @@ void main()
local_direction[local_index] = sun.direction;
/* Parallel sum. */
const uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y;
constexpr uint group_size = gl_WorkGroupSize.x * gl_WorkGroupSize.y;
uint stride = group_size / 2;
for (int i = 0; i < 10; i++) {
barrier();

View File

@@ -230,8 +230,8 @@ float ltc_evaluate_disk(
float d11 = dot(V1, V1);
float d22 = dot(V2, V2);
float d12 = dot(V1, V2);
float a, inv_b; /* Eigenvalues */
const float threshold = 0.0007f; /* Can be adjusted. Fix artifacts. */
float a, inv_b; /* Eigenvalues */
constexpr float threshold = 0.0007f; /* Can be adjusted. Fix artifacts. */
if (abs(d12) / sqrt(d11 * d22) > threshold) {
float tr = d11 + d22;
float det = -d12 * d12 + d11 * d22;

View File

@@ -37,7 +37,7 @@ float4 ggx_brdf_split_sum(float3 lut_coord)
float scale = 0.0f;
float bias = 0.0f;
float metal_bias = 0.0f;
const uint sample_count = 512u * 512u;
constexpr uint sample_count = 512u * 512u;
for (uint i = 0u; i < sample_count; i++) {
float2 rand = hammersley_2d(i, sample_count);
float3 Xi = sample_cylinder(rand);
@@ -98,7 +98,7 @@ float4 ggx_bsdf_split_sum(float3 lut_coord)
float scale = 0.0f;
float bias = 0.0f;
float transmission_factor = 0.0f;
const uint sample_count = 512u * 512u;
constexpr uint sample_count = 512u * 512u;
for (uint i = 0u; i < sample_count; i++) {
float2 rand = hammersley_2d(i, sample_count);
float3 Xi = sample_cylinder(rand);
@@ -163,7 +163,7 @@ float4 ggx_btdf_gt_one(float3 lut_coord)
/* Integrating BTDF. */
float transmission_factor = 0.0f;
const uint sample_count = 512u * 512u;
constexpr uint sample_count = 512u * 512u;
for (uint i = 0u; i < sample_count; i++) {
float2 rand = hammersley_2d(i, sample_count);
float3 Xi = sample_cylinder(rand);

View File

@@ -486,9 +486,9 @@ void brdf_f82_tint_lut(float3 F0,
* model multiplied by the tint input.
* Therefore, the factor follows by setting `F82Tint(cosI) = FSchlick(cosI) - b*cosI*(1-cosI)^6`
* and `F82Tint(acos(1/7)) = FSchlick(acos(1/7)) * f82_tint` and solving for `b`. */
const float f = 6.0f / 7.0f;
const float f5 = (f * f) * (f * f) * f;
const float f6 = (f * f) * (f * f) * (f * f);
constexpr float f = 6.0f / 7.0f;
constexpr float f5 = (f * f) * (f * f) * f;
constexpr float f6 = (f * f) * (f * f) * (f * f);
float3 F_schlick = mix(F0, float3(1.0f), f5);
float3 b = F_schlick * (7.0f / f6) * (1.0f - F82);
reflectance -= b * split_sum.z;
@@ -624,7 +624,7 @@ float3 displacement_bump()
# if defined(GPU_FRAGMENT_SHADER) && !defined(MAT_GEOM_CURVES)
/* This is the filter width for automatic displacement + bump mapping, which is fixed.
* NOTE: keep the same as default bump node filter width. */
const float bump_filter_width = 0.1f;
constexpr float bump_filter_width = 0.1f;
float2 dHd;
dF_branch(dot(nodetree_displacement(), g_data.N + dF_impl(g_data.N)), bump_filter_width, dHd);

View File

@@ -40,7 +40,7 @@ float3 from_accumulation_space(float3 color)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);
float2 center_uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv;

View File

@@ -52,7 +52,7 @@ void invalid_pixel_write(int2 texel)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -167,7 +167,7 @@ float2 variance_history_sample(float3 P)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel_fullres = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);
float2 uv = (float2(texel_fullres) + 0.5f) * uniform_buf.raytrace.full_resolution_inv;

View File

@@ -18,7 +18,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_generate)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -22,7 +22,7 @@ BsdfSample ray_generate_direction(float2 noise, ClosureUndetermined cl, float3 V
{
float3 random_point_on_cylinder = sample_cylinder(noise);
/* Bias the rays so we never get really high energy rays almost parallel to the surface. */
const float rng_bias = 0.08f;
constexpr float rng_bias = 0.08f;
/* When modeling object thickness as a sphere, the outgoing rays are distributed uniformly
* over the sphere. We don't want the RAY_BIAS in this case. */
if (cl.type != CLOSURE_BSDF_TRANSLUCENT_ID || thickness <= 0.0f) {

View File

@@ -21,7 +21,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_fallback)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -23,7 +23,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_planar)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -22,7 +22,7 @@ COMPUTE_SHADER_CREATE_INFO(eevee_ray_trace_screen)
void main()
{
const uint tile_size = RAYTRACE_GROUP_SIZE;
constexpr uint tile_size = RAYTRACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -108,7 +108,7 @@ METAL_ATTR ScreenTraceHitData raytrace_screen(RayTraceData rt_data,
#ifdef METAL_AMD_RAYTRACE_WORKAROUND
bool hit_failsafe = true;
#endif
const int max_steps = 255;
constexpr int max_steps = 255;
for (int iter = 1; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) {
float stride = 1.0f + float(iter) * rt_data.quality;
float lod = log2(stride) * lod_fac;
@@ -191,7 +191,7 @@ ScreenTraceHitData raytrace_planar(RayTraceData rt_data,
float t = 0.0f, time = 0.0f;
bool hit = false;
const int max_steps = 32;
constexpr int max_steps = 32;
for (int iter = 1; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) {
float stride = 1.0f + float(iter) * rt_data.quality;

View File

@@ -24,7 +24,7 @@ void raytrace_screenspace_ray_finalize(inout ScreenSpaceRay ray, float2 pixel_si
/* Constant bias (due to depth buffer precision). Helps with self intersection. */
/* Magic numbers for 24bits of precision.
* From http://terathon.com/gdc07_lengyel.pdf (slide 26) */
const float bias = -2.4e-7f * 2.0f;
constexpr float bias = -2.4e-7f * 2.0f;
ray.origin.zw += bias;
ray.direction.zw += bias;

View File

@@ -125,7 +125,7 @@ LightData debug_light_get()
/** Return true if a pixel was written. */
bool debug_tilemaps(float3 P, LightData light, bool do_debug_sample_tile)
{
const int debug_tile_size_px = 4;
constexpr int debug_tile_size_px = 4;
int2 px = int2(gl_FragCoord.xy) / debug_tile_size_px;
int tilemap = px.x / SHADOW_TILEMAP_RES;
int tilemap_index = light.tilemap_index + tilemap;

View File

@@ -25,8 +25,8 @@ float shadow_read_depth(SHADOW_ATLAS_TYPE atlas_tx,
return -1.0f;
}
/* Using bitwise ops is way faster than integer ops. */
const uint page_shift = uint(SHADOW_PAGE_LOD);
const uint page_mask = ~(0xFFFFFFFFu << uint(SHADOW_PAGE_LOD));
constexpr uint page_shift = uint(SHADOW_PAGE_LOD);
constexpr uint page_mask = ~(0xFFFFFFFFu << uint(SHADOW_PAGE_LOD));
uint2 texel = coord.tilemap_texel;
/* Shift LOD0 pixels so that they get wrapped at the right position for the given LOD. */

View File

@@ -34,7 +34,7 @@ int shadow_tile_offset_lds(int2 tile, int lod)
* coordinate fits the given tilemap LOD. */
bool thread_mask(int2 tile_co, int lod)
{
const uint lod_size = uint(SHADOW_TILEMAP_RES);
constexpr uint lod_size = uint(SHADOW_TILEMAP_RES);
return all(lessThan(tile_co, int2(lod_size >> lod)));
}

View File

@@ -96,7 +96,7 @@ void main()
}
/* Raster the bounding rectangle of the Box projection. */
const float tilemap_half_res = float(SHADOW_TILEMAP_RES / 2);
constexpr float tilemap_half_res = float(SHADOW_TILEMAP_RES / 2);
int2 box_min = int2(aabb_tag.min.xy * tilemap_half_res + tilemap_half_res);
int2 box_max = int2(aabb_tag.max.xy * tilemap_half_res + tilemap_half_res);

View File

@@ -115,7 +115,7 @@ void main()
if (lod_min > 0) {
/* Override the effective lod min distance in absolute mode (negative).
* Note that this only changes the sampling for this AA sample. */
const float projection_diagonal = 2.0f * M_SQRT2;
constexpr float projection_diagonal = 2.0f * M_SQRT2;
light_buf[l_idx].lod_min = -(projection_diagonal / float(SHADOW_MAP_MAX_RES >> lod_min));
}
}

View File

@@ -55,17 +55,17 @@ int shadow_tile_offset(uint2 tile, int tiles_index, int lod)
#if SHADOW_TILEMAP_LOD > 5
# error This needs to be adjusted
#endif
const int lod0_width = SHADOW_TILEMAP_RES / 1;
const int lod1_width = SHADOW_TILEMAP_RES / 2;
const int lod2_width = SHADOW_TILEMAP_RES / 4;
const int lod3_width = SHADOW_TILEMAP_RES / 8;
const int lod4_width = SHADOW_TILEMAP_RES / 16;
const int lod5_width = SHADOW_TILEMAP_RES / 32;
const int lod0_size = lod0_width * lod0_width;
const int lod1_size = lod1_width * lod1_width;
const int lod2_size = lod2_width * lod2_width;
const int lod3_size = lod3_width * lod3_width;
const int lod4_size = lod4_width * lod4_width;
constexpr int lod0_width = SHADOW_TILEMAP_RES / 1;
constexpr int lod1_width = SHADOW_TILEMAP_RES / 2;
constexpr int lod2_width = SHADOW_TILEMAP_RES / 4;
constexpr int lod3_width = SHADOW_TILEMAP_RES / 8;
constexpr int lod4_width = SHADOW_TILEMAP_RES / 16;
constexpr int lod5_width = SHADOW_TILEMAP_RES / 32;
constexpr int lod0_size = lod0_width * lod0_width;
constexpr int lod1_size = lod1_width * lod1_width;
constexpr int lod2_size = lod2_width * lod2_width;
constexpr int lod3_size = lod3_width * lod3_width;
constexpr int lod4_size = lod4_width * lod4_width;
/* TODO(fclem): Convert everything to uint. */
int offset = tiles_index;
@@ -132,7 +132,7 @@ int shadow_directional_tilemap_index(LightData light, float3 lP)
int lvl;
if (light.type == LIGHT_SUN) {
/* We need to hide one tile worth of data to hide the moving transition. */
const float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001f);
constexpr float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001f);
/* Avoid using log2 when we can just get the exponent from the floating point. */
frexp(reduce_max(abs(lP)) * narrowing * 2.0f, lvl);
}
@@ -158,7 +158,7 @@ float shadow_directional_level_fractional(LightData light, float3 lP)
float lod;
if (light.type == LIGHT_SUN) {
/* We need to hide one tile worth of data to hide the moving transition. */
const float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001f);
constexpr float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 1.0001f);
/* Since the distance is centered around the camera (and thus by extension the tile-map),
* we need to multiply by 2 to get the lod level which covers the following range:
* [-coverage_get(lod)/2..coverage_get(lod)/2] */
@@ -168,7 +168,7 @@ float shadow_directional_level_fractional(LightData light, float3 lP)
}
else {
/* The narrowing need to be stronger since the tile-map position is not rounded but floored. */
const float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 2.5001f);
constexpr float narrowing = float(SHADOW_TILEMAP_RES) / (float(SHADOW_TILEMAP_RES) - 2.5001f);
/* Since we want half of the size, bias the level by -1. */
float clipmap_lod_min_minus_one = float(light_sun_data_get(light).clipmap_lod_min - 1);
float lod_min_half_size = exp2(clipmap_lod_min_minus_one);
@@ -214,7 +214,7 @@ float shadow_punctual_pixel_ratio(LightData light,
/* Clamp in shadow space. */
film_pixel_footprint = max(film_pixel_footprint, -light.lod_min);
/* Cube-face diagonal divided by LOD0 resolution. */
const float shadow_pixel_radius = (2.0f * M_SQRT2) / SHADOW_MAP_MAX_RES;
constexpr float shadow_pixel_radius = (2.0f * M_SQRT2) / SHADOW_MAP_MAX_RES;
return saturate(shadow_pixel_radius / film_pixel_footprint);
}

View File

@@ -393,7 +393,7 @@ float shadow_texel_radius_at_position(LightData light, const bool is_directional
}
/* Pixel bounding radius inside a tilemap of unit scale.
* Take only half of it because we want the radius and not the diameter. */
const float texel_radius = M_SQRT2 / SHADOW_MAP_MAX_RES;
constexpr float texel_radius = M_SQRT2 / SHADOW_MAP_MAX_RES;
return texel_radius * scale;
}

View File

@@ -468,7 +468,7 @@ SphericalHarmonicL1 spherical_harmonics_triple_product(SphericalHarmonicL1 a,
/* Adapted from:
* "Code Generation and Factoring for Fast Evaluation of Low-order Spherical Harmonic Products
* and Squares" Function "SH_product_3". */
const float L0_M0_coef = 0.282094792f;
constexpr float L0_M0_coef = 0.282094792f;
SphericalHarmonicL1 sh;
sh.L0.M0 = a.L0.M0 * b.L0.M0;
sh.L0.M0 += a.L1.Mn1 * b.L1.Mn1;

View File

@@ -84,7 +84,7 @@ SubSurfaceSample sample_neighborhood(float2 sample_uv)
void main()
{
const uint tile_size = SUBSURFACE_GROUP_SIZE;
constexpr uint tile_size = SUBSURFACE_GROUP_SIZE;
uint2 tile_coord = unpackUvec2x16(tiles_coord_buf[gl_WorkGroupID.x]);
int2 texel = int2(gl_LocalInvocationID.xy + tile_coord * tile_size);

View File

@@ -76,9 +76,9 @@ void main()
int2 out_texel = int2(gl_FragCoord.xy);
#ifdef MAT_SUBSURFACE
const bool use_sss = true;
constexpr bool use_sss = true;
#else
const bool use_sss = false;
constexpr bool use_sss = false;
#endif
ObjectInfos object_infos = drw_infos[drw_resource_id()];
@@ -140,7 +140,7 @@ void main()
gbuf.N[layer].xyyy);
}
if (use_sss || use_light_linking) {
const int layer = GBUF_HEADER_FB_LAYER_COUNT;
constexpr int layer = GBUF_HEADER_FB_LAYER_COUNT;
/* NOTE: The image view start at layer GBUF_HEADER_FB_LAYER_COUNT so all destination layer is
* `layer - GBUF_HEADER_FB_LAYER_COUNT`. */
imageStoreFast(out_gbuf_header_img,

View File

@@ -79,9 +79,9 @@ void main()
int2 out_texel = int2(gl_FragCoord.xy);
#ifdef MAT_SUBSURFACE
const bool use_sss = true;
constexpr bool use_sss = true;
#else
const bool use_sss = false;
constexpr bool use_sss = false;
#endif
ObjectInfos object_infos = drw_infos[drw_resource_id()];
@@ -143,7 +143,7 @@ void main()
gbuf.N[layer].xyyy);
}
if (use_sss || use_light_linking) {
const int layer = GBUF_HEADER_FB_LAYER_COUNT;
constexpr int layer = GBUF_HEADER_FB_LAYER_COUNT;
/* NOTE: The image view start at layer GBUF_HEADER_FB_LAYER_COUNT so all destination layer is
* `layer - GBUF_HEADER_FB_LAYER_COUNT`. */
imageStoreFast(out_gbuf_header_img,

View File

@@ -70,8 +70,8 @@ void main()
int2 texel_co = int2(gl_FragCoord.xy);
/* Using bitwise ops is way faster than integer ops. */
const int page_shift = SHADOW_PAGE_LOD;
const int page_mask = ~(0xFFFFFFFF << SHADOW_PAGE_LOD);
constexpr int page_shift = SHADOW_PAGE_LOD;
constexpr int page_mask = ~(0xFFFFFFFF << SHADOW_PAGE_LOD);
int2 tile_co = texel_co >> page_shift;
int2 texel_page = texel_co & page_mask;

View File

@@ -34,7 +34,7 @@ void radiance_transfer(inout Surfel surfel, float3 in_radiance, float in_visibil
float NL = dot(surfel.normal, L);
/* Lambertian BSDF. Albedo applied later depending on which side of the surfel was hit. */
const float bsdf = M_1_PI;
constexpr float bsdf = M_1_PI;
/* From "Global Illumination using Parallel Global Ray-Bundles"
* Eq. 3: Outgoing light */
float transfert_fn = (M_TAU / capture_info_buf.sample_count) * bsdf * abs(NL);

View File

@@ -43,7 +43,7 @@ float3x3 compute_mat(float4 sphere, float3 bone_vec, out float z_ofs)
* can be bigger than the center disc. Compute the
* max angular size and compensate by sliding the disc
* towards the camera and scale it accordingly. */
const float half_pi = 3.1415926f * 0.5f;
constexpr float half_pi = 3.1415926f * 0.5f;
float rad = sphere.w;
/* Let be :
* V the view vector origin.

View File

@@ -17,7 +17,7 @@ void main()
}
else {
/* Smooth lighting factor. */
const float s = 0.2f; /* [0.0f-0.5f] range */
constexpr float s = 0.2f; /* [0.0f-0.5f] range */
float fac = clamp((n * (1.0f - s)) + s, 0.0f, 1.0f);
fragColor.rgb = mix(finalStateColor, finalBoneColor, fac * fac);
fragColor.a = alpha;

View File

@@ -22,7 +22,7 @@ void main()
float sinb = (data_buf[gl_InstanceID].tail_sphere.w - data_buf[gl_InstanceID].head_sphere.w) *
bone_lenrcp;
#else
const float sinb = 0.0f;
constexpr float sinb = 0.0f;
#endif
float3 y_axis = bone_vec * bone_lenrcp;

View File

@@ -164,15 +164,15 @@ void main()
select_id_set(in_select_buf[gl_InstanceID]);
/* Line Adjacency primitive. */
const uint input_primitive_vertex_count = 4u;
constexpr uint input_primitive_vertex_count = 4u;
/* Line list primitive. */
const uint ouput_primitive_vertex_count = 2u;
const uint ouput_primitive_count = 1u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 2u;
constexpr uint ouput_primitive_count = 1u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -27,11 +27,11 @@ void main()
inverted = int(dot(cross(model_mat[0].xyz, model_mat[1].xyz), model_mat[2].xyz) < 0.0f);
/* Do lighting at an angle to avoid flat shading on front facing bone. */
const float3 light = float3(0.1f, 0.1f, 0.8f);
constexpr float3 light = float3(0.1f, 0.1f, 0.8f);
float n = dot(normal, light);
/* Smooth lighting factor. */
const float s = 0.2f; /* [0.0f-0.5f] range */
constexpr float s = 0.2f; /* [0.0f-0.5f] range */
float fac = clamp((n * (1.0f - s)) + s, 0.0f, 1.0f);
finalColor.rgb = mix(state_color.rgb, bone_color.rgb, fac * fac);
finalColor.a = 1.0f;

View File

@@ -6,6 +6,7 @@
FRAGMENT_SHADER_CREATE_INFO(overlay_armature_shape_wire)
#include "gpu_shader_utildefines_lib.glsl"
#include "select_lib.glsl"
/**
@@ -37,7 +38,7 @@ void main()
float half_size = (do_smooth_wire ? wire_width - 0.5f : wire_width) / 2.0f;
float dist = abs(edgeCoord) - half_size;
const float mix_w = clamp(edge_step(dist), 0.0f, 1.0f);
float mix_w = saturate(edge_step(dist));
fragColor = mix(float4(finalColor.rgb, alpha), float4(0), mix_w);
fragColor.a *= 1.0f - mix_w;

View File

@@ -187,18 +187,18 @@ void main()
/* Line primitive. */
#ifdef FROM_LINE_STRIP
const uint input_primitive_vertex_count = 1u;
constexpr uint input_primitive_vertex_count = 1u;
#else
const uint input_primitive_vertex_count = 2u;
constexpr uint input_primitive_vertex_count = 2u;
#endif
/* Triangle list primitive. */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 2u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 2u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -49,8 +49,8 @@ void main()
* can be bigger than the center disc. Compute the
* max angular size and compensate by sliding the disc
* towards the camera and scale it accordingly. */
const float half_pi = 3.1415926f * 0.5f;
const float rad = 0.05f;
constexpr float half_pi = 3.1415926f * 0.5f;
constexpr float rad = 0.05f;
/* Let be (in local space):
* V the view vector origin.
* O the sphere origin.

View File

@@ -11,7 +11,7 @@ FRAGMENT_SHADER_CREATE_INFO(overlay_armature_sphere_solid)
void main()
{
const float sphere_radius = 0.05f;
constexpr float sphere_radius = 0.05f;
bool is_perp = (drw_view().winmat[3][3] == 0.0f);
float3 ray_ori_view = (is_perp) ? float3(0.0f) : viewPosition.xyz;
@@ -32,7 +32,7 @@ void main()
ray_dir /= ray_len;
/* Line to sphere intersect */
const float sphere_radius_sqr = sphere_radius * sphere_radius;
constexpr float sphere_radius_sqr = sphere_radius * sphere_radius;
float b = dot(ray_ori, ray_dir);
float c = dot(ray_ori, ray_ori) - sphere_radius_sqr;
float h = b * b - c;
@@ -44,7 +44,7 @@ void main()
float3 l = normalize(sphereMatrix[2].xyz); /* Just the view Z axis in the sphere space. */
/* Smooth lighting factor. */
const float s = 0.2f; /* [0.0f-0.5f] range */
constexpr float s = 0.2f; /* [0.0f-0.5f] range */
float fac = clamp((dot(n, l) * (1.0f - s)) + s, 0.0f, 1.0f);
fragColor.rgb = mix(finalStateColor, finalBoneColor, fac * fac);

View File

@@ -47,7 +47,7 @@ void main()
* can be bigger than the center disc. Compute the
* max angular size and compensate by sliding the disc
* towards the camera and scale it accordingly. */
const float half_pi = 3.1415926f * 0.5f;
constexpr float half_pi = 3.1415926f * 0.5f;
/* Let be (in local space):
* V the view vector origin.
* O the sphere origin.

View File

@@ -15,10 +15,10 @@ float dither()
{
/* NOTE(Metal): Declaring constant array in function scope to avoid increasing local shader
* memory pressure. */
const float4 dither_mat4x4[4] = float4_array(float4(P(0.0f), P(8.0f), P(2.0f), P(10.0f)),
float4(P(12.0f), P(4.0f), P(14.0f), P(6.0f)),
float4(P(3.0f), P(11.0f), P(1.0f), P(9.0f)),
float4(P(15.0f), P(7.0f), P(13.0f), P(5.0f)));
constexpr float4 dither_mat4x4[4] = float4_array(float4(P(0.0f), P(8.0f), P(2.0f), P(10.0f)),
float4(P(12.0f), P(4.0f), P(14.0f), P(6.0f)),
float4(P(3.0f), P(11.0f), P(1.0f), P(9.0f)),
float4(P(15.0f), P(7.0f), P(13.0f), P(5.0f)));
int2 co = int2(gl_FragCoord.xy) % 4;
return dither_mat4x4[co.x][co.y];

View File

@@ -24,7 +24,7 @@
float4x4 extract_matrix_packed_data(float4x4 mat, out float4 dataA, out float4 dataB)
{
const float div = 1.0f / 255.0f;
constexpr float div = 1.0f / 255.0f;
int a = int(mat[0][3]);
int b = int(mat[1][3]);
int c = int(mat[2][3]);

View File

@@ -89,7 +89,7 @@ void geometry_main(VertOut geom_in[3],
/* Detect failure cases where triangles would produce no fragments. */
bool2 is_subpixel = lessThan(bbox.zw - bbox.xy, float2(1.0f));
/* View aligned triangle. */
const float threshold = 0.00001f;
constexpr float threshold = 0.00001f;
bool is_coplanar = abs(plane.z) < threshold;
do_vertex(0, out_vertex_id, out_primitive_id, geom_in[0], is_subpixel, is_coplanar);
@@ -102,15 +102,15 @@ void main()
select_id_set(drw_custom_id());
/* Triangle list primitive. */
const uint input_primitive_vertex_count = 3u;
constexpr uint input_primitive_vertex_count = 3u;
/* Triangle list primitive. */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 1u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 1u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -192,15 +192,15 @@ void geometry_main(VertOut geom_in[2],
void main()
{
/* Line list primitive. */
const uint input_primitive_vertex_count = 2u;
constexpr uint input_primitive_vertex_count = 2u;
/* Triangle list primitive (emulating triangle strip). */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 8u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 8u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -15,15 +15,15 @@ VERTEX_SHADER_CREATE_INFO(overlay_edit_curve_normals)
void main()
{
/* Line list primitive. */
const uint input_primitive_vertex_count = 2u;
constexpr uint input_primitive_vertex_count = 2u;
/* Line list primitive. */
const uint ouput_primitive_vertex_count = 2u;
const uint ouput_primitive_count = 2u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 2u;
constexpr uint ouput_primitive_count = 2u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -201,15 +201,15 @@ void geometry_main(VertOut geom_in[2],
void main()
{
/* Line list primitive. */
const uint input_primitive_vertex_count = 2u;
constexpr uint input_primitive_vertex_count = 2u;
/* Triangle list primitive (emulating triangle strip). */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 8u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 8u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -148,15 +148,15 @@ void geometry_main(VertOut geom_in[2], uint out_vert_id, uint out_prim_id, uint
void main()
{
/* Line list primitive. */
const uint input_primitive_vertex_count = 2u;
constexpr uint input_primitive_vertex_count = 2u;
/* Triangle list primitive. */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 2u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 2u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -30,16 +30,16 @@ void main()
#if defined(FACE_NORMAL) || defined(VERT_NORMAL) || defined(LOOP_NORMAL)
/* Point primitive. */
const uint input_primitive_vertex_count = 1u;
constexpr uint input_primitive_vertex_count = 1u;
/* Line list primitive. */
const uint ouput_primitive_vertex_count = 2u;
const uint ouput_primitive_count = 1u;
const uint ouput_invocation_count = 1u;
constexpr uint ouput_primitive_vertex_count = 2u;
constexpr uint ouput_primitive_count = 1u;
constexpr uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -156,16 +156,16 @@ void geometry_main(VertOut geom_in[2],
void main()
{
/* Line list primitive. */
const uint input_primitive_vertex_count = 2u;
constexpr uint input_primitive_vertex_count = 2u;
/* Triangle list primitive. */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 2u;
const uint ouput_invocation_count = 1u;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 2u;
constexpr uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -12,7 +12,7 @@ VERTEX_SHADER_CREATE_INFO(overlay_edit_uv_verts)
void main()
{
/* TODO: Theme? */
const float4 pinned_col = float4(1.0f, 0.0f, 0.0f, 1.0f);
constexpr float4 pinned_col = float4(1.0f, 0.0f, 0.0f, 1.0f);
bool is_selected = (flag & (VERT_UV_SELECT | FACE_UV_SELECT)) != 0u;
bool is_pinned = (flag & VERT_UV_PINNED) != 0u;

View File

@@ -205,7 +205,7 @@ void main()
if ((vclass & VCLASS_LIGHT_SPOT_CONE) != 0) {
/* Compute point on the cone before and after this one. */
float2 perp = float2(pos.y, -pos.x);
const float incr_angle = 2.0f * 3.1415f / 32.0f;
constexpr float incr_angle = 2.0f * 3.1415f / 32.0f;
const float2 slope = float2(cos(incr_angle), sin(incr_angle));
float3 p0 = float3((pos.xy * slope.x + perp * slope.y) * lamp_spot_sine, -lamp_spot_cosine);
float3 p1 = float3((pos.xy * slope.x - perp * slope.y) * lamp_spot_sine, -lamp_spot_cosine);

View File

@@ -14,8 +14,8 @@ void main()
fragColor = finalColor;
/* Stipple */
const float dash_width = 6.0f;
const float dash_factor = 0.5f;
constexpr float dash_width = 6.0f;
constexpr float dash_factor = 0.5f;
lineOutput = pack_line_data(gl_FragCoord.xy, stipple_start, stipple_coord);

View File

@@ -134,16 +134,16 @@ void geometry_main(VertOut geom_in[2],
void main()
{
/* Point list primitive. */
const uint input_primitive_vertex_count = 1u;
constexpr uint input_primitive_vertex_count = 1u;
/* Triangle list primitive. */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 2u;
const uint ouput_invocation_count = 1u;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 2u;
constexpr uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -249,7 +249,7 @@ void main()
float scene_depth = textureLod(sceneDepth, depth_uv, 0.0f).r;
/* Avoid bad cases of Z-fighting for occlusion only. */
const float epsilon = 3.0f / 8388608.0f;
constexpr float epsilon = 3.0f / 8388608.0f;
bool occluded = (ref_depth > scene_depth + epsilon);
/* NOTE: We never set alpha to 1.0 to avoid Anti-aliasing destroying the line. */

View File

@@ -112,15 +112,15 @@ void geometry_main(VertOut geom_in[4],
void main()
{
/* Line adjacency list primitive. */
const uint input_primitive_vertex_count = 4u;
constexpr uint input_primitive_vertex_count = 4u;
/* Line list primitive. */
const uint ouput_primitive_vertex_count = 2u;
const uint ouput_primitive_count = 1u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 2u;
constexpr uint ouput_primitive_count = 1u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -9,9 +9,9 @@ FRAGMENT_SHADER_CREATE_INFO(overlay_paint_weight)
float contours(float value, float steps, float width_px, float max_rel_width, float gradient)
{
/* Minimum visible and minimum full strength line width in screen space for fade out. */
const float min_width_px = 1.3f, fade_width_px = 2.3f;
constexpr float min_width_px = 1.3f, fade_width_px = 2.3f;
/* Line is thinner towards the increase in the weight gradient by this factor. */
const float hi_bias = 2.0f;
constexpr float hi_bias = 2.0f;
/* Don't draw lines at 0 or 1. */
float rel_value = value * steps;

View File

@@ -25,7 +25,7 @@ void main()
gl_Position = float4(-2.0f, -2.0f, -2.0f, 1.0f);
}
const float4 colSel = float4(1.0f);
constexpr float4 colSel = float4(1.0f);
finalColor = (is_select) ? colSel : colorWire;

View File

@@ -12,7 +12,7 @@ void main()
{
float2 centered = gl_PointCoord - float2(0.5f);
float dist_squared = dot(centered, centered);
const float rad_squared = 0.25f;
constexpr float rad_squared = 0.25f;
/* Round point with jagged edges. */
if (dist_squared > rad_squared) {

View File

@@ -93,14 +93,14 @@ void main()
#endif
/* NOTE(Metal): Declaring constant arrays in function scope to avoid increasing local shader
* memory pressure. */
const int indices[8] = int_array(0, 1, 1, 2, 2, 3, 3, 0);
constexpr int indices[8] = int_array(0, 1, 1, 2, 2, 3, 3, 0);
/* Corners for cell outlines. 0.45 is arbitrary. Any value below 0.5f can be used to avoid
* overlapping of the outlines. */
const float3 corners[4] = float3_array(float3(-0.45f, 0.45f, 0.0f),
float3(0.45f, 0.45f, 0.0f),
float3(0.45f, -0.45f, 0.0f),
float3(-0.45f, -0.45f, 0.0f));
constexpr float3 corners[4] = float3_array(float3(-0.45f, 0.45f, 0.0f),
float3(0.45f, 0.45f, 0.0f),
float3(0.45f, -0.45f, 0.0f),
float3(-0.45f, -0.45f, 0.0f));
float3 pos = domainOriginOffset +
cellSize * (float3(cell_co + adaptiveCellOffset) + cell_offset);

View File

@@ -183,12 +183,12 @@ void main()
# ifdef USE_NEEDLE
/* NOTE(Metal): Declaring constant arrays in function scope to avoid increasing local shader
* memory pressure. */
const float3 corners[4] = float3_array(float3(0.0f, 0.2f, -0.5f),
float3(-0.2f * 0.866f, -0.2f * 0.5f, -0.5f),
float3(0.2f * 0.866f, -0.2f * 0.5f, -0.5f),
float3(0.0f, 0.0f, 0.5f));
constexpr float3 corners[4] = float3_array(float3(0.0f, 0.2f, -0.5f),
float3(-0.2f * 0.866f, -0.2f * 0.5f, -0.5f),
float3(0.2f * 0.866f, -0.2f * 0.5f, -0.5f),
float3(0.0f, 0.0f, 0.5f));
const int indices[12] = int_array(0, 1, 1, 2, 2, 0, 0, 3, 1, 3, 2, 3);
constexpr int indices[12] = int_array(0, 1, 1, 2, 2, 0, 0, 3, 1, 3, 2, 3);
float3 rotated_pos = rot_mat * corners[indices[gl_VertexID % 12]];
pos += rotated_pos * vector_length * displaySize * cellSize;

View File

@@ -41,11 +41,11 @@ float2 workbench_normal_encode(bool front_face, float3 n)
/* Encode 2 float into 1 with the desired precision. */
float workbench_float_pair_encode(float v1, float v2)
{
// const uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS);
// const uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS);
// constexpr uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS);
// constexpr uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS);
/* Same as above because some compiler are very dumb and think we use medium int. */
const int v1_mask = 0x1F;
const int v2_mask = 0x7;
constexpr int v1_mask = 0x1F;
constexpr int v2_mask = 0x7;
int iv1 = int(v1 * float(v1_mask));
int iv2 = int(v2 * float(v2_mask)) << int(ROUGHNESS_BITS);
return float(iv1 | iv2);
@@ -53,11 +53,11 @@ float workbench_float_pair_encode(float v1, float v2)
void workbench_float_pair_decode(float data, out float v1, out float v2)
{
// const uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS);
// const uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS);
// constexpr uint v1_mask = ~(0xFFFFFFFFu << ROUGHNESS_BITS);
// constexpr uint v2_mask = ~(0xFFFFFFFFu << METALLIC_BITS);
/* Same as above because some compiler are very dumb and think we use medium int. */
const int v1_mask = 0x1F;
const int v2_mask = 0x7;
constexpr int v1_mask = 0x1F;
constexpr int v2_mask = 0x7;
int idata = int(data);
v1 = float(idata & v1_mask) * (1.0f / float(v1_mask));
v2 = float(idata >> int(ROUGHNESS_BITS)) * (1.0f / float(v2_mask));

View File

@@ -63,10 +63,10 @@ void geometry_main(VertOut geom_in[3], uint out_vertex_id, uint out_invocation_i
/* In case of non manifold geom, we only increase/decrease
* the stencil buffer by one but do every faces as they were facing the light. */
bool invert = backface;
const bool is_manifold = false;
constexpr bool is_manifold = false;
#else
const bool invert = false;
const bool is_manifold = true;
constexpr bool invert = false;
constexpr bool is_manifold = true;
#endif
if (!is_manifold || !backface) {
@@ -78,16 +78,16 @@ void geometry_main(VertOut geom_in[3], uint out_vertex_id, uint out_invocation_i
void main()
{
/* Triangle list primitive. */
const uint input_primitive_vertex_count = 3u;
constexpr uint input_primitive_vertex_count = 3u;
/* Triangle list primitive. */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 1u;
const uint ouput_invocation_count = 2u;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 1u;
constexpr uint ouput_invocation_count = 2u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -8,7 +8,7 @@ FRAGMENT_SHADER_CREATE_INFO(workbench_shadow_debug)
void main()
{
const float a = 0.1f;
constexpr float a = 0.1f;
#ifdef SHADOW_PASS
out_debug_color.rgb = gl_FrontFacing ? float3(a, -a, 0.0f) : float3(-a, a, 0.0f);
#else

View File

@@ -112,19 +112,19 @@ void geometry_main(VertOut geom_in[4],
void main()
{
/* Line adjacency primitive. */
const uint input_primitive_vertex_count = 4u;
constexpr uint input_primitive_vertex_count = 4u;
/* Triangle list primitive. */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 2u;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 2u;
#ifdef DOUBLE_MANIFOLD
const uint ouput_invocation_count = 2u;
constexpr uint ouput_invocation_count = 2u;
#else
const uint ouput_invocation_count = 1u;
constexpr uint ouput_invocation_count = 1u;
#endif
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -201,10 +201,10 @@ float4 volume_integration(
{
/* NOTE: Constant array declared inside function scope to reduce shader core thread memory
* pressure on Apple Silicon. */
const float4 dither_mat[4] = float4_array(float4(P(0.0f), P(8.0f), P(2.0f), P(10.0f)),
float4(P(12.0f), P(4.0f), P(14.0f), P(6.0f)),
float4(P(3.0f), P(11.0f), P(1.0f), P(9.0f)),
float4(P(15.0f), P(7.0f), P(13.0f), P(5.0f)));
constexpr float4 dither_mat[4] = float4_array(float4(P(0.0f), P(8.0f), P(2.0f), P(10.0f)),
float4(P(12.0f), P(4.0f), P(14.0f), P(6.0f)),
float4(P(3.0f), P(11.0f), P(1.0f), P(9.0f)),
float4(P(15.0f), P(7.0f), P(13.0f), P(5.0f)));
/* Start with full transmittance and no scattered light. */
float3 final_scattering = float3(0.0f);
float final_transmittance = 1.0f;
@@ -237,7 +237,7 @@ float4 volume_integration(
void main()
{
uint stencil = texelFetch(stencil_tx, int2(gl_FragCoord.xy), 0).r;
const uint in_front_stencil_bits = 1u << 1;
constexpr uint in_front_stencil_bits = 1u << 1;
if (do_depth_test && (stencil & in_front_stencil_bits) != 0) {
/* Don't draw on top of "in front" objects. */
discard;

View File

@@ -37,9 +37,9 @@ float compute_color_map_coordinate(float coordinate)
{
/* Color maps have a fixed width of 257. We offset by the equivalent of half a pixel and scale
* down such that the normalized coordinate 1.0 corresponds to the center of the last pixel. */
const float sampler_resolution = 257.0f;
const float sampler_offset = 0.5f / sampler_resolution;
const float sampler_scale = 1.0f - (1.0f / sampler_resolution);
constexpr float sampler_resolution = 257.0f;
constexpr float sampler_offset = 0.5f / sampler_resolution;
constexpr float sampler_scale = 1.0f - (1.0f / sampler_resolution);
return coordinate * sampler_scale + sampler_offset;
}

View File

@@ -1521,7 +1521,7 @@ bool is_uniformly_scaled(float3x3 mat)
if (!is_orthogonal(mat)) {
return false;
}
const float eps = 1e-7f;
constexpr float eps = 1e-7f;
float x = length_squared(mat[0]);
float y = length_squared(mat[1]);
float z = length_squared(mat[2]);

View File

@@ -87,7 +87,7 @@ float2 interpolate_dot_slerp(float t, float cosom)
{
float2 w = float2(1.0f - t, t);
/* Within [-1..1] range, avoid aligned axis. */
const float eps = 1e-4f;
constexpr float eps = 1e-4f;
if (abs(cosom) < 1.0f - eps) {
float omega = acos(cosom);
w = sin(w * omega) / sin(omega);

View File

@@ -31,9 +31,9 @@ bool is_any_zero(float4 vec);
* Return true if the deference between`a` and `b` is below the `epsilon` value.
* Epsilon value is scaled by magnitude of `a` before comparison.
*/
bool almost_equal_relative(float2 a, float2 b, const float epsilon_factor);
bool almost_equal_relative(float3 a, float3 b, const float epsilon_factor);
bool almost_equal_relative(float4 a, float4 b, const float epsilon_factor);
bool almost_equal_relative(float2 a, float2 b, float epsilon_factor);
bool almost_equal_relative(float3 a, float3 b, float epsilon_factor);
bool almost_equal_relative(float4 a, float4 b, float epsilon_factor);
/**
* Safe `a` modulo `b`.
@@ -209,9 +209,9 @@ int2 orthogonal(int2 v);
/**
* Return true if the difference between`a` and `b` is below the `epsilon` value.
*/
bool is_equal(float2 a, float2 b, const float epsilon);
bool is_equal(float3 a, float3 b, const float epsilon);
bool is_equal(float4 a, float4 b, const float epsilon);
bool is_equal(float2 a, float2 b, float epsilon);
bool is_equal(float3 a, float3 b, float epsilon);
bool is_equal(float4 a, float4 b, float epsilon);
/**
* Return the maximum component of a vector.
@@ -292,7 +292,7 @@ bool is_any_zero(float4 vec)
return any(equal(vec, float4(0.0f)));
}
bool almost_equal_relative(float2 a, float2 b, const float epsilon_factor)
bool almost_equal_relative(float2 a, float2 b, float epsilon_factor)
{
for (int i = 0; i < 2; i++) {
if (abs(a[i] - b[i]) > epsilon_factor * abs(a[i])) {
@@ -301,7 +301,7 @@ bool almost_equal_relative(float2 a, float2 b, const float epsilon_factor)
}
return true;
}
bool almost_equal_relative(float3 a, float3 b, const float epsilon_factor)
bool almost_equal_relative(float3 a, float3 b, float epsilon_factor)
{
for (int i = 0; i < 3; i++) {
if (abs(a[i] - b[i]) > epsilon_factor * abs(a[i])) {
@@ -310,7 +310,7 @@ bool almost_equal_relative(float3 a, float3 b, const float epsilon_factor)
}
return true;
}
bool almost_equal_relative(float4 a, float4 b, const float epsilon_factor)
bool almost_equal_relative(float4 a, float4 b, float epsilon_factor)
{
for (int i = 0; i < 4; i++) {
if (abs(a[i] - b[i]) > epsilon_factor * abs(a[i])) {
@@ -547,7 +547,7 @@ float3 project(float3 p, float3 v_proj)
float2 normalize_and_get_length(float2 vector, out float out_length)
{
out_length = length_squared(vector);
const float threshold = 1e-35f;
constexpr float threshold = 1e-35f;
if (out_length > threshold) {
out_length = sqrt(out_length);
return vector / out_length;
@@ -559,7 +559,7 @@ float2 normalize_and_get_length(float2 vector, out float out_length)
float3 normalize_and_get_length(float3 vector, out float out_length)
{
out_length = length_squared(vector);
const float threshold = 1e-35f;
constexpr float threshold = 1e-35f;
if (out_length > threshold) {
out_length = sqrt(out_length);
return vector / out_length;
@@ -571,7 +571,7 @@ float3 normalize_and_get_length(float3 vector, out float out_length)
float4 normalize_and_get_length(float4 vector, out float out_length)
{
out_length = length_squared(vector);
const float threshold = 1e-35f;
constexpr float threshold = 1e-35f;
if (out_length > threshold) {
out_length = sqrt(out_length);
return vector / out_length;
@@ -584,7 +584,7 @@ float4 normalize_and_get_length(float4 vector, out float out_length)
float2 safe_normalize_and_get_length(float2 vector, out float out_length)
{
out_length = length_squared(vector);
const float threshold = 1e-35f;
constexpr float threshold = 1e-35f;
if (out_length > threshold) {
out_length = sqrt(out_length);
return vector / out_length;
@@ -596,7 +596,7 @@ float2 safe_normalize_and_get_length(float2 vector, out float out_length)
float3 safe_normalize_and_get_length(float3 vector, out float out_length)
{
out_length = length_squared(vector);
const float threshold = 1e-35f;
constexpr float threshold = 1e-35f;
if (out_length > threshold) {
out_length = sqrt(out_length);
return vector / out_length;
@@ -608,7 +608,7 @@ float3 safe_normalize_and_get_length(float3 vector, out float out_length)
float4 safe_normalize_and_get_length(float4 vector, out float out_length)
{
out_length = length_squared(vector);
const float threshold = 1e-35f;
constexpr float threshold = 1e-35f;
if (out_length > threshold) {
out_length = sqrt(out_length);
return vector / out_length;
@@ -719,15 +719,15 @@ int2 orthogonal(int2 v)
return int2(-v.y, v.x);
}
bool is_equal(float2 a, float2 b, const float epsilon)
bool is_equal(float2 a, float2 b, float epsilon)
{
return all(lessThanEqual(abs(a - b), float2(epsilon)));
}
bool is_equal(float3 a, float3 b, const float epsilon)
bool is_equal(float3 a, float3 b, float epsilon)
{
return all(lessThanEqual(abs(a - b), float3(epsilon)));
}
bool is_equal(float4 a, float4 b, const float epsilon)
bool is_equal(float4 a, float4 b, float epsilon)
{
return all(lessThanEqual(abs(a - b), float4(epsilon)));
}

View File

@@ -46,7 +46,7 @@ struct rgb9e5_t {
rgb9e5_t rgb9e5_from_float3(float3 color)
{
const float max_rgb9e5 = float(0xFF80u);
constexpr float max_rgb9e5 = float(0xFF80u);
color = clamp(color, 0.0f, max_rgb9e5);
float max_component = max(max(color.r, color.g), color.b);

View File

@@ -147,9 +147,9 @@ float orderedIntBitsToFloat(int int_value)
*/
float3 offset_ray(float3 P, float3 Ng)
{
const float origin = 1.0f / 32.0f;
const float float_scale = 1.0f / 65536.0f;
const float int_scale = 256.0f;
constexpr float origin = 1.0f / 32.0f;
constexpr float float_scale = 1.0f / 65536.0f;
constexpr float int_scale = 256.0f;
int3 of_i = int3(int_scale * Ng);
of_i = int3((P.x < 0.0f) ? -of_i.x : of_i.x,

View File

@@ -224,6 +224,11 @@ template<typename T> struct VecBase<T, 1> {
};
template<typename T> struct VecBase<T, 2> : VecOp<T, 2> {
private:
/* Weird non-zero value to avoid error about division by zero in constexpr. */
static constexpr T V = T(0.123f);
public:
union {
struct {
T x, y;
@@ -237,11 +242,17 @@ template<typename T> struct VecBase<T, 2> : VecOp<T, 2> {
VecBase() = default;
template<typename U> explicit VecBase(VecOp<U, 2>) {}
explicit VecBase(T) {}
explicit VecBase(T, T) {}
constexpr explicit VecBase(T) : x(V), y(V) {}
/* Implemented correctly for GCC to compile the constexpr float2 arrays. */
constexpr explicit VecBase(T x_, T y_) : x(x_), y(y_) {}
};
template<typename T> struct VecBase<T, 3> : VecOp<T, 3> {
private:
/* Weird non-zero value to avoid error about division by zero in constexpr. */
static constexpr T V = T(0.123f);
public:
union {
struct {
T x, y, z;
@@ -255,14 +266,19 @@ template<typename T> struct VecBase<T, 3> : VecOp<T, 3> {
VecBase() = default;
template<typename U> explicit VecBase(VecOp<U, 3>) {}
explicit VecBase(T) {}
constexpr explicit VecBase(T) : x(V), y(V), z(V) {}
/* Implemented correctly for GCC to compile the constexpr gl_WorkGroupSize. */
constexpr explicit VecBase(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {}
explicit VecBase(VecOp<T, 2>, T) {}
explicit VecBase(T, VecOp<T, 2>) {}
constexpr explicit VecBase(VecOp<T, 2>, T) : x(V), y(V), z(V) {}
constexpr explicit VecBase(T, VecOp<T, 2>) : x(V), y(V), z(V) {}
};
template<typename T> struct VecBase<T, 4> : VecOp<T, 4> {
private:
/* Weird non-zero value to avoid error about division by zero in constexpr. */
static constexpr T V = T(0.123f);
public:
union {
struct {
T x, y, z, w;
@@ -276,14 +292,15 @@ template<typename T> struct VecBase<T, 4> : VecOp<T, 4> {
VecBase() = default;
template<typename U> explicit VecBase(VecOp<U, 4>) {}
explicit VecBase(T) {}
explicit VecBase(T, T, T, T) {}
explicit VecBase(VecOp<T, 2>, T, T) {}
explicit VecBase(T, VecOp<T, 2>, T) {}
explicit VecBase(T, T, VecOp<T, 2>) {}
explicit VecBase(VecOp<T, 2>, VecOp<T, 2>) {}
explicit VecBase(VecOp<T, 3>, T) {}
explicit VecBase(T, VecOp<T, 3>) {}
constexpr explicit VecBase(T) : x(V), y(V), z(V), w(V) {}
/* Implemented correctly for GCC to compile the constexpr. */
constexpr explicit VecBase(T x_, T y_, T z_, T w_) : x(x_), y(y_), z(z_), w(w_) {}
constexpr explicit VecBase(VecOp<T, 2>, T, T) : x(V), y(V), z(V), w(V) {}
constexpr explicit VecBase(T, VecOp<T, 2>, T) : x(V), y(V), z(V), w(V) {}
constexpr explicit VecBase(T, T, VecOp<T, 2>) : x(V), y(V), z(V), w(V) {}
constexpr explicit VecBase(VecOp<T, 2>, VecOp<T, 2>) : x(V), y(V), z(V), w(V) {}
constexpr explicit VecBase(VecOp<T, 3>, T) : x(V), y(V), z(V), w(V) {}
constexpr explicit VecBase(T, VecOp<T, 3>) : x(V), y(V), z(V), w(V) {}
};
/* Boolean vectors do not have operators and are not convertible from other types. */
@@ -692,12 +709,12 @@ int findMSB(uint) RET;
/* NOTE: Declared inside a namespace and exposed behind macros to prevent
* errors on VS2019 due to `corecrt_math` conflicting functions. */
namespace glsl {
template<typename T> T abs(T) RET;
template<typename T> constexpr T abs(T) RET;
/* TODO(fclem): These should be restricted to floats. */
template<typename T> T ceil(T) RET;
template<typename T> T exp(T) RET;
template<typename T> T exp2(T) RET;
template<typename T> T floor(T) RET;
template<typename T> constexpr T ceil(T) RET;
template<typename T> constexpr T exp(T) RET;
template<typename T> constexpr T exp2(T) RET;
template<typename T> constexpr T floor(T) RET;
template<typename T> T fma(T, T, T) RET;
float fma(float, float, float) RET;
template<typename T> T frexp(T, T) RET;
@@ -705,25 +722,25 @@ bool isinf(float) RET;
template<int D> VecBase<bool, D> isinf(VecOp<float, D>) RET;
bool isnan(float) RET;
template<int D> VecBase<bool, D> isnan(VecOp<float, D>) RET;
template<typename T> T log(T) RET;
template<typename T> T log2(T) RET;
template<typename T> constexpr T log(T) RET;
template<typename T> constexpr T log2(T) RET;
template<typename T> T modf(T, T);
template<typename T, typename U> T pow(T, U) RET;
template<typename T> T round(T) RET;
template<typename T> T sqrt(T) RET;
template<typename T> T trunc(T) RET;
template<typename T, typename U> constexpr T pow(T, U) RET;
template<typename T> constexpr T round(T) RET;
template<typename T> constexpr T sqrt(T) RET;
template<typename T> constexpr T trunc(T) RET;
template<typename T, typename U> T ldexp(T, U) RET;
template<typename T> T acos(T) RET;
template<typename T> constexpr T acos(T) RET;
template<typename T> T acosh(T) RET;
template<typename T> T asin(T) RET;
template<typename T> constexpr T asin(T) RET;
template<typename T> T asinh(T) RET;
template<typename T> T atan(T, T) RET;
template<typename T> T atan(T) RET;
template<typename T> T atanh(T) RET;
template<typename T> T cos(T) RET;
template<typename T> constexpr T cos(T) RET;
template<typename T> T cosh(T) RET;
template<typename T> T sin(T) RET;
template<typename T> constexpr T sin(T) RET;
template<typename T> T sinh(T) RET;
template<typename T> T tan(T) RET;
template<typename T> T tanh(T) RET;
@@ -759,19 +776,19 @@ template<typename T> T tanh(T) RET;
#define tan glsl::tan
#define tanh glsl::tanh
template<typename T> T max(T, T) RET;
template<typename T> T min(T, T) RET;
template<typename T> T sign(T) RET;
template<typename T, typename U> T clamp(T, U, U) RET;
template<typename T> T clamp(T, float, float) RET;
template<typename T, typename U> T max(T, U) RET;
template<typename T, typename U> T min(T, U) RET;
template<typename T> constexpr T max(T, T) RET;
template<typename T> constexpr T min(T, T) RET;
template<typename T> constexpr T sign(T) RET;
template<typename T, typename U> constexpr T clamp(T, U, U) RET;
template<typename T> constexpr T clamp(T, float, float) RET;
template<typename T, typename U> constexpr T max(T, U) RET;
template<typename T, typename U> constexpr T min(T, U) RET;
/* TODO(fclem): These should be restricted to floats. */
template<typename T> T fract(T) RET;
template<typename T> T inversesqrt(T) RET;
float mod(float, float) RET;
template<int D> VecBase<float, D> mod(VecOp<float, D>, float) RET;
template<int D> VecBase<float, D> mod(VecOp<float, D>, VecOp<float, D>) RET;
template<typename T> constexpr T inversesqrt(T) RET;
constexpr float mod(float, float) RET;
template<int D> VecBase<float, D> constexpr mod(VecOp<float, D>, float) RET;
template<int D> VecBase<float, D> constexpr mod(VecOp<float, D>, VecOp<float, D>) RET;
template<typename T> T smoothstep(T, T, T) RET;
float step(float, float) RET;
template<int D> VecBase<float, D> step(VecOp<float, D>, VecOp<float, D>) RET;
@@ -779,8 +796,8 @@ template<int D> VecBase<float, D> step(float, VecOp<float, D>) RET;
float smoothstep(float, float, float) RET;
template<int D> VecBase<float, D> smoothstep(float, float, VecOp<float, D>) RET;
template<typename T> T degrees(T) RET;
template<typename T> T radians(T) RET;
template<typename T> constexpr T degrees(T) RET;
template<typename T> constexpr T radians(T) RET;
/* Declared explicitly to avoid type errors. */
float mix(float, float, float) RET;

View File

@@ -53,10 +53,10 @@ void main()
float alpha_threshold = 0.0f;
float dot_threshold = -1.0f;
const float circle_radius = 0.5f;
constexpr float circle_radius = 0.5f;
const float square_radius = 0.5f / sqrt(2.0f / M_PI) * M_SQRT1_2;
const float diamond_radius = 0.5f / sqrt(2.0f / M_PI) * M_SQRT1_2;
const float corner_rounding = 0.0f;
constexpr float corner_rounding = 0.0f;
switch (finalShape) {
default:

View File

@@ -21,8 +21,8 @@ VERTEX_SHADER_CREATE_INFO(gpu_shader_2D_nodelink)
void main()
{
const float start_gradient_threshold = 0.35f;
const float end_gradient_threshold = 0.65f;
constexpr float start_gradient_threshold = 0.35f;
constexpr float end_gradient_threshold = 0.65f;
#ifdef USE_INSTANCE
# define colStart (colid_doarrow[0] < 3u ? start_color : node_link_data.colors[colid_doarrow[0]])

View File

@@ -45,7 +45,7 @@ float3 compute_masks(float2 uv)
* has been scaled (i.e: Node editor)... */
float line_width = (lineWidth > 0.0f) ? max(fwidth(uv.y), lineWidth) : 0.0f;
const float aa_radius = 0.5f;
constexpr float aa_radius = 0.5f;
float3 masks;
masks.x = smoothstep(-aa_radius, aa_radius, sdf);
masks.y = smoothstep(-aa_radius, aa_radius, sdf - line_width);

View File

@@ -32,7 +32,7 @@ VERTEX_SHADER_CREATE_INFO(gpu_shader_2D_widget_base)
float2 do_widget()
{
/* Offset to avoid losing pixels (mimics conservative rasterization). */
const float2 ofs = float2(0.5f, -0.5f);
constexpr float2 ofs = float2(0.5f, -0.5f);
lineWidth = abs(rect.x - recti.x);
float2 emboss_ofs = float2(0.0f, -lineWidth);

View File

@@ -34,44 +34,44 @@ void main()
{
/* NOTE(Metal): Declaring constant array in function scope to avoid increasing local shader
* memory pressure. */
const float2 cornervec[36] = float2_array(float2(0.0f, 1.0f),
float2(0.02f, 0.805f),
float2(0.067f, 0.617f),
float2(0.169f, 0.45f),
float2(0.293f, 0.293f),
float2(0.45f, 0.169f),
float2(0.617f, 0.076f),
float2(0.805f, 0.02f),
float2(1.0f, 0.0f),
float2(-1.0f, 0.0f),
float2(-0.805f, 0.02f),
float2(-0.617f, 0.067f),
float2(-0.45f, 0.169f),
float2(-0.293f, 0.293f),
float2(-0.169f, 0.45f),
float2(-0.076f, 0.617f),
float2(-0.02f, 0.805f),
float2(0.0f, 1.0f),
float2(0.0f, -1.0f),
float2(-0.02f, -0.805f),
float2(-0.067f, -0.617f),
float2(-0.169f, -0.45f),
float2(-0.293f, -0.293f),
float2(-0.45f, -0.169f),
float2(-0.617f, -0.076f),
float2(-0.805f, -0.02f),
float2(-1.0f, 0.0f),
float2(1.0f, 0.0f),
float2(0.805f, -0.02f),
float2(0.617f, -0.067f),
float2(0.45f, -0.169f),
float2(0.293f, -0.293f),
float2(0.169f, -0.45f),
float2(0.076f, -0.617f),
float2(0.02f, -0.805f),
float2(0.0f, -1.0f));
constexpr float2 cornervec[36] = float2_array(float2(0.0f, 1.0f),
float2(0.02f, 0.805f),
float2(0.067f, 0.617f),
float2(0.169f, 0.45f),
float2(0.293f, 0.293f),
float2(0.45f, 0.169f),
float2(0.617f, 0.076f),
float2(0.805f, 0.02f),
float2(1.0f, 0.0f),
float2(-1.0f, 0.0f),
float2(-0.805f, 0.02f),
float2(-0.617f, 0.067f),
float2(-0.45f, 0.169f),
float2(-0.293f, 0.293f),
float2(-0.169f, 0.45f),
float2(-0.076f, 0.617f),
float2(-0.02f, 0.805f),
float2(0.0f, 1.0f),
float2(0.0f, -1.0f),
float2(-0.02f, -0.805f),
float2(-0.067f, -0.617f),
float2(-0.169f, -0.45f),
float2(-0.293f, -0.293f),
float2(-0.45f, -0.169f),
float2(-0.617f, -0.076f),
float2(-0.805f, -0.02f),
float2(-1.0f, 0.0f),
float2(1.0f, 0.0f),
float2(0.805f, -0.02f),
float2(0.617f, -0.067f),
float2(0.45f, -0.169f),
float2(0.293f, -0.293f),
float2(0.169f, -0.45f),
float2(0.076f, -0.617f),
float2(0.02f, -0.805f),
float2(0.0f, -1.0f));
const float2 center_offset[4] = float2_array(
constexpr float2 center_offset[4] = float2_array(
float2(1.0f, 1.0f), float2(-1.0f, 1.0f), float2(-1.0f, -1.0f), float2(1.0f, -1.0f));
uint cflag = vflag & CNR_FLAG_RANGE;

View File

@@ -179,13 +179,13 @@ void main()
/* Line list primitive. */
uint input_primitive_vertex_count = uint(gpu_vert_stride_count_offset.x);
/* Triangle list primitive (emulating triangle strip). */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 2u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 2u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -8,7 +8,7 @@ FRAGMENT_SHADER_CREATE_INFO(gpu_shader_gpencil_stroke)
void main()
{
const float2 center = float2(0, 0.5f);
constexpr float2 center = float2(0, 0.5f);
float4 tColor = interp.mColor;
/* if alpha < 0, then encap */
if (tColor.a < 0) {

View File

@@ -116,7 +116,7 @@ void strip_EmitVertex(const uint strip_index,
void geometry_main(VertOut geom_in[4], uint out_vertex_id, uint out_primitive_id)
{
const float MiterLimit = 0.75f;
constexpr float MiterLimit = 0.75f;
float4 P0 = geom_in[0].gpu_position;
float4 P1 = geom_in[1].gpu_position;
@@ -313,15 +313,16 @@ void geometry_main(VertOut geom_in[4], uint out_vertex_id, uint out_primitive_id
void main()
{
/* Line Strip Adjacency primitive. */
const uint input_primitive_vertex_count = 1u; /* We read 4 but advance 1. Assume no restart. */
constexpr uint input_primitive_vertex_count =
1u; /* We read 4 but advance 1. Assume no restart. */
/* Triangle list primitive (emulating triangle strip). */
const uint ouput_primitive_vertex_count = 3u;
const uint ouput_primitive_count = 12u;
const uint ouput_invocation_count = 1u;
const uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
const uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
constexpr uint ouput_primitive_vertex_count = 3u;
constexpr uint ouput_primitive_count = 12u;
constexpr uint ouput_invocation_count = 1u;
constexpr uint output_vertex_count_per_invocation = ouput_primitive_count *
ouput_primitive_vertex_count;
constexpr uint output_vertex_count_per_input_primitive = output_vertex_count_per_invocation *
ouput_invocation_count;
uint in_primitive_id = uint(gl_VertexID) / output_vertex_count_per_input_primitive;
uint in_primitive_first_vertex = in_primitive_id * input_primitive_vertex_count;

View File

@@ -21,13 +21,13 @@ void main()
#ifdef DO_CORNER_MASKING
/* Top-left rounded corner parameters. */
const float circle_radius_outer = 0.1f;
const float circle_radius_inner = 0.075f;
constexpr float circle_radius_outer = 0.1f;
constexpr float circle_radius_inner = 0.075f;
/**
* Add a bit transparency to see a bit of the icon, without
* getting on the way of readability. */
const float mask_transparency = 0.25f;
constexpr float mask_transparency = 0.25f;
float2 circle_center = float2(circle_radius_outer - text_width, 0.5f);

View File

@@ -10,7 +10,7 @@ void main()
{
float2 centered = gl_PointCoord - float2(0.5f);
float dist_squared = dot(centered, centered);
const float rad_squared = 0.25f;
constexpr float rad_squared = 0.25f;
/* Round point with jagged edges. */
if (dist_squared > rad_squared) {

View File

@@ -135,7 +135,7 @@ void main()
/* 3x3 blur */
/* clang-format off */
const float weights3x3[16] = float_array(
constexpr float weights3x3[16] = float_array(
1.0f, 2.0f, 1.0f, 0.0f,
2.0f, 4.0f, 2.0f, 0.0f,
1.0f, 2.0f, 1.0f, 0.0f,
@@ -171,7 +171,7 @@ void main()
/* 5x5 blur */
/* clang-format off */
const float weights5x5[36] = float_array(
constexpr float weights5x5[36] = float_array(
1.0f, 2.0f, 2.0f, 2.0f, 1.0f, 0.0f,
2.0f, 5.0f, 6.0f, 5.0f, 2.0f, 0.0f,
2.0f, 6.0f, 8.0f, 6.0f, 2.0f, 0.0f,

View File

@@ -166,7 +166,7 @@ void node_tex_sky_nishita(float3 co,
}
else {
/* evaluate longitudinal position on the map */
const float tau = 6.28318530717958647692f;
constexpr float tau = 6.28318530717958647692f;
float x = (spherical.y + M_PI + sun_rotation) / tau;
if (x > 1.0f) {
x -= 1.0f;

View File

@@ -26,6 +26,10 @@ RESHAPE(float3x3, mat3x3, mat3x4)
#undef RESHAPE
/* constexpr is equivalent to const in GLSL + special chaining rules.
* See "GLSL Specification section 4.3.3. Constant Expressions". */
#define constexpr const
/* Boolean in GLSL are 32bit in interface structs. */
#define bool32_t bool
#define bool2 bvec2
@@ -157,5 +161,5 @@ RESHAPE(float3x3, mat3x3, mat3x4)
#define _enum_dummy /* Needed to please `glslang`. */
#define _enum_type(name) uint
#define _enum_decl(name) const uint
#define _enum_decl(name) constexpr uint
#define _enum_end _enum_dummy;

View File

@@ -113,7 +113,7 @@ void main()
TEST(math_matrix, MatrixModify)
{
const float epsilon = 1e-6f;
constexpr float epsilon = 1e-6f;
float4x4 result, expect;
float4x4 m1 = float4x4(
float4(0, 3, 0, 0), float4(2, 0, 0, 0), float4(0, 0, 2, 0), float4(0, 0, 0, 1));
@@ -241,7 +241,7 @@ void main()
float4(0.000000f, 0.000000f, 0.000000f, 1.000000f)));
float4x4 m1 = mat4x4_identity();
float4x4 result;
const float epsilon = 2e-5f;
constexpr float epsilon = 2e-5f;
result = interpolate_fast(m1, m2, 0.0f);
EXPECT_NEAR(result, m1, epsilon);
result = interpolate_fast(m1, m2, 1.0f);
@@ -260,7 +260,7 @@ void main()
TEST(math_matrix, MatrixTransform)
{
float3 expect, result;
const float3 p = float3(1, 2, 3);
constexpr float3 p = float3(1, 2, 3);
float4x4 m4 = from_loc_rot(float3(10, 0, 0), EulerXYZ(M_PI_2, M_PI_2, M_PI_2));
float3x3 m3 = from_rotation(EulerXYZ(M_PI_2, M_PI_2, M_PI_2));
float4x4 pers4 = projection_perspective(-0.1f, 0.1f, -0.1f, 0.1f, -0.1f, -1.0f);