Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2022-10-14 15:51:10 +0300
committerJeroen Bakker <jeroen@blender.org>2022-10-14 15:51:10 +0300
commit396fe9a98af41805ade2e10a1a36f08e1e59bda6 (patch)
tree46564bf3c0b8c01ecf46a7e82453b518c07de414 /source/blender/gpu/shaders
parent5c0e90033fdb9e8e73b56fb304f10a25d17e6517 (diff)
Researching bottlenecks.temp-texture-painting-gpu
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r--source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh4
-rw-r--r--source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl59
-rw-r--r--source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_merge_comp.glsl4
-rw-r--r--source/blender/gpu/shaders/sculpt_paint/sculpt_paint_tile_lib.glsl21
4 files changed, 54 insertions, 34 deletions
diff --git a/source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh b/source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh
index 1051abc63e9..86003867f02 100644
--- a/source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh
+++ b/source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh
@@ -8,7 +8,7 @@
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(sculpt_paint_sub_tiles)
- .storage_buf(0, Qualifier::READ, "PaintTileData", "paint_tile_buf[]")
+ .storage_buf(0, Qualifier::READ_WRITE, "PaintTileData", "paint_tile_buf[]")
.push_constant(Type::INT, "paint_tile_buf_len")
.define("SUB_TILE_SIZE", "1024");
@@ -28,7 +28,7 @@ GPU_SHADER_CREATE_INFO(sculpt_paint_image_compute)
.typedef_source("GPU_sculpt_shader_shared.h");
GPU_SHADER_CREATE_INFO(sculpt_paint_image_merge_compute)
- .local_group_size(1, 1, 1)
+ .local_group_size(32, 1, 1)
.image(0, GPU_RGBA16F, Qualifier::READ, ImageType::FLOAT_3D, "paint_tiles_img")
.image(1, GPU_RGBA16F, Qualifier::READ_WRITE, ImageType::FLOAT_2D, "texture_img")
.push_constant(Type::INT, "layer_id")
diff --git a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl
index 86c90de2d90..f4af1509233 100644
--- a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl
+++ b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl
@@ -20,9 +20,6 @@ void main()
{
PackedPixelRow row = pixel_row_buf[gl_GlobalInvocationID.x + pixel_row_offset];
TrianglePaintInput triangle = paint_input[PIXEL_ROW_PRIM_INDEX(row)];
- PaintTileData paint_tile;
- ivec3 image_coord = paint_tile_coord_from_udim(
- 1001, PIXEL_ROW_START_IMAGE_COORD(row), paint_tile);
uint row_len = PIXEL_ROW_LEN(row);
@@ -34,34 +31,42 @@ void main()
vec3 delta;
SCULPT_get_row_pos_and_delta(co1, co2, co3, triangle, row, pos, delta);
- for (int x = 0; x < row_len; x++) {
- /* TODO: Do clipping test. */
- vec4 color;
- bool color_read = false;
+ int x = 0;
+ while (x < row_len) {
+ PaintTileData paint_tile;
+ ivec3 image_coord = paint_tile_coord_from_udim(
+ 1001, PIXEL_ROW_START_IMAGE_COORD(row) + int2(x, 0), paint_tile);
+ bool in_use = false;
+ for (; x < row_len && image_coord.x < SUB_TILE_SIZE; x++, image_coord.x++, pos += delta) {
+ /* TODO: Do clipping test. */
+ vec4 color;
+ bool color_read = false;
- for (int step_index = paint_step_range[0]; step_index < paint_step_range[1]; step_index++) {
- PaintStepData step_data = paint_step_buf[step_index];
-
- float distance;
- bool test_result = SCULPT_brush_test(paint_brush_buf.test, step_data, pos, distance);
- if (test_result) {
- if (!color_read) {
- color = imageLoad(paint_tiles_img, image_coord);
- color_read = true;
+ for (int step_index = paint_step_range[0]; step_index < paint_step_range[1]; step_index++) {
+ PaintStepData step_data = paint_step_buf[step_index];
+ float distance;
+ bool test_result = SCULPT_brush_test(paint_brush_buf.test, step_data, pos, distance);
+ if (test_result) {
+ if (!color_read) {
+ color = imageLoad(paint_tiles_img, image_coord);
+ color_read = true;
+ in_use = true;
+ }
+ // TODO: blend with color...
+ float factor = SCULPT_hardness_factor(distance, step_data.hardness, step_data.radius);
+ float curve_factor = SCULPT_curve_strength(factor, paint_brush_buf.falloff_shape);
+ vec4 final_paint_color = SCULPT_blend_color(
+ color, paint_brush_buf.color * curve_factor * step_data.strength);
+ final_paint_color *= paint_brush_buf.alpha;
+ color = SCULPT_blend_color(color, final_paint_color);
}
- // TODO: blend with color...
- float factor = SCULPT_hardness_factor(distance, step_data.hardness, step_data.radius);
- float curve_factor = SCULPT_curve_strength(factor, paint_brush_buf.falloff_shape);
- vec4 final_paint_color = SCULPT_blend_color(
- color, paint_brush_buf.color * curve_factor * step_data.strength);
- final_paint_color *= paint_brush_buf.alpha;
- color = SCULPT_blend_color(color, final_paint_color);
+ }
+ if (color_read) {
+ imageStore(paint_tiles_img, image_coord, color);
}
}
- if (color_read) {
- imageStore(paint_tiles_img, image_coord, color);
+ if (in_use) {
+ paint_tile_mark_used(paint_tile);
}
- image_coord.x += 1;
- pos += delta;
}
} \ No newline at end of file
diff --git a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_merge_comp.glsl b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_merge_comp.glsl
index b3ff3ac3ff3..cec4546f783 100644
--- a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_merge_comp.glsl
+++ b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_merge_comp.glsl
@@ -4,6 +4,10 @@ void main()
{
PaintTileData paint_tile;
paint_tile_get_layer(layer_id, paint_tile);
+ if (!paint_tile.in_use_frame) {
+ return;
+ }
+
ivec3 coord_in = ivec3(gl_GlobalInvocationID.xy, layer_id);
vec4 paint_color = imageLoad(paint_tiles_img, coord_in);
paint_color.a = 1.0;
diff --git a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_tile_lib.glsl b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_tile_lib.glsl
index c45664dd97c..88931feecd1 100644
--- a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_tile_lib.glsl
+++ b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_tile_lib.glsl
@@ -3,28 +3,39 @@ ivec2 paint_tile_coord_to_sub_tile_id(ivec2 coord)
return coord / ivec2(SUB_TILE_SIZE);
}
-bool paint_tile_search(int tile_number, ivec2 coord, out PaintTileData r_paint_tile)
+bool paint_tile_search(int tile_number, int2 sub_tile_id, out PaintTileData r_paint_tile)
{
- int2 sub_tile_id = paint_tile_coord_to_sub_tile_id(coord);
for (int i = 0; i < paint_tile_buf_len; i++) {
if (paint_tile_buf[i].tile_number == tile_number &&
paint_tile_buf[i].sub_tile_id == sub_tile_id) {
r_paint_tile = paint_tile_buf[i];
+ r_paint_tile.index = i;
return true;
}
}
return false;
}
+void paint_tile_mark_used(PaintTileData paint_tile)
+{
+ paint_tile_buf[paint_tile.index].in_use_frame = true;
+}
+
void paint_tile_get_layer(int layer_id, out PaintTileData r_paint_tile)
{
r_paint_tile = paint_tile_buf[layer_id];
}
-ivec3 paint_tile_coord_from_udim(int tile_number, ivec2 coord, out PaintTileData r_paint_tile)
+ivec3 paint_tile_coord_from_paint_tile(ivec2 coord, PaintTileData paint_tile)
{
- if (paint_tile_search(tile_number, coord, r_paint_tile)) {
- return ivec3(coord - r_paint_tile.sub_tile_id * ivec2(SUB_TILE_SIZE), r_paint_tile.layer_id);
+ return ivec3(coord - paint_tile.sub_tile_id * ivec2(SUB_TILE_SIZE), paint_tile.layer_id);
+}
+
+ivec3 paint_tile_coord_from_udim(int tile_number, ivec2 coord, inout PaintTileData r_paint_tile)
+{
+ int2 sub_tile_id = paint_tile_coord_to_sub_tile_id(coord);
+ if (paint_tile_search(tile_number, sub_tile_id, r_paint_tile)) {
+ return paint_tile_coord_from_paint_tile(coord, r_paint_tile);
}
return ivec3(0);