Draw: draw_debug improvements

Allow using the drw_debug API in any shader file.
Remove the drw_debug API from Release builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/111710
This commit is contained in:
Miguel Pozo
2023-09-01 15:40:42 +02:00
parent 400f7c22bc
commit 3d7db929a4
7 changed files with 22 additions and 20 deletions

View File

@@ -4,7 +4,6 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(common_debug_draw_lib.glsl)
void main()
{

View File

@@ -7,7 +7,6 @@
* See eShadowDebug for more information.
*/
#pragma BLENDER_REQUIRE(common_debug_print_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_light_iter_lib.glsl)
@@ -32,10 +31,12 @@ vec3 debug_random_color(int v)
void debug_tile_print(ShadowTileData tile, ivec4 tile_coord)
{
#ifdef DRW_DEBUG_PRINT
drw_print("Tile (", tile_coord.x, ",", tile_coord.y, ") in Tilemap ", tile_coord.z, " : ");
drw_print(tile.lod);
drw_print(tile.page);
drw_print(tile.cache_index);
#endif
}
vec3 debug_tile_state_color(ShadowTileData tile)
@@ -113,9 +114,11 @@ bool debug_tilemaps(vec3 P, LightData light)
out_color_add = vec4(debug_tile_state_color(tile), 0.0);
out_color_mul = vec4(0.0);
#ifdef DRW_DEBUG_PRINT
if (all(equal(ivec2(gl_FragCoord.xy), ivec2(0)))) {
drw_print(light.object_mat);
}
#endif
return true;
}
}

View File

@@ -13,8 +13,6 @@
#pragma BLENDER_REQUIRE(eevee_shadow_tag_usage_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_debug_shape_lib.glsl)
float ray_aabb(vec3 ray_origin, vec3 ray_direction, vec3 aabb_min, vec3 aabb_max)
{
/* https://gdbooks.gitbooks.io/3dcollisions/content/Chapter3/raycast_aabb.html */

View File

@@ -12,8 +12,6 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_shape_lib.glsl)
#pragma BLENDER_REQUIRE(common_debug_shape_lib.glsl)
/* Inflate bounds by half a pixel as a conservative rasterization alternative,
* to ensure the tiles needed by all LOD0 pixels get tagged */
void inflate_bounds(vec3 ls_center, inout vec3 P, inout vec3 lP)

View File

@@ -5,10 +5,10 @@
/**
* Debug print implementation for shaders.
*
* `print()`:
* `drw_print()`:
* Log variable or strings inside the viewport.
* Using a unique non string argument will print the variable name with it.
* Concatenate by using multiple arguments. i.e: `print("Looped ", n, "times.")`.
* Concatenate by using multiple arguments. i.e: `drw_print("Looped ", n, "times.")`.
* `drw_print_no_endl()`:
* Same as `print()` but does not finish the line.
* `drw_print_value()`:

View File

@@ -140,6 +140,8 @@ void ShaderCreateInfo::finalize()
depth_write_ = info.depth_write_;
}
builtins_ |= info.builtins_;
validate_merge(info);
auto assert_no_overlap = [&](const bool test, const StringRefNull error) {
@@ -466,20 +468,20 @@ void gpu_shader_create_info_init()
#endif
for (ShaderCreateInfo *info : g_create_infos->values()) {
if (info->do_static_compilation_) {
info->builtins_ |= gpu_shader_dependency_get_builtins(info->vertex_source_);
info->builtins_ |= gpu_shader_dependency_get_builtins(info->fragment_source_);
info->builtins_ |= gpu_shader_dependency_get_builtins(info->geometry_source_);
info->builtins_ |= gpu_shader_dependency_get_builtins(info->compute_source_);
info->builtins_ |= gpu_shader_dependency_get_builtins(info->vertex_source_);
info->builtins_ |= gpu_shader_dependency_get_builtins(info->fragment_source_);
info->builtins_ |= gpu_shader_dependency_get_builtins(info->geometry_source_);
info->builtins_ |= gpu_shader_dependency_get_builtins(info->compute_source_);
/* Automatically amend the create info for ease of use of the debug feature. */
if ((info->builtins_ & BuiltinBits::USE_DEBUG_DRAW) == BuiltinBits::USE_DEBUG_DRAW) {
info->additional_info("draw_debug_draw");
}
if ((info->builtins_ & BuiltinBits::USE_DEBUG_PRINT) == BuiltinBits::USE_DEBUG_PRINT) {
info->additional_info("draw_debug_print");
}
#ifdef DEBUG
/* Automatically amend the create info for ease of use of the debug feature. */
if ((info->builtins_ & BuiltinBits::USE_DEBUG_DRAW) == BuiltinBits::USE_DEBUG_DRAW) {
info->additional_info("draw_debug_draw");
}
if ((info->builtins_ & BuiltinBits::USE_DEBUG_PRINT) == BuiltinBits::USE_DEBUG_PRINT) {
info->additional_info("draw_debug_print");
}
#endif
}
/* TEST */

View File

@@ -108,6 +108,7 @@ struct GPUSource {
if (source.find("'") != StringRef::not_found) {
char_literals_preprocess();
}
#ifdef DEBUG
if (source.find("drw_print") != StringRef::not_found) {
string_preprocess();
}
@@ -119,6 +120,7 @@ struct GPUSource {
{
builtins |= shader::BuiltinBits::USE_DEBUG_DRAW;
}
#endif
check_no_quotes();
}