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:
authorLukas Stockner <lukasstockner97>2020-01-14 02:33:21 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2020-01-16 04:06:49 +0300
commit7d8a186335400cb7ad69d24aab89e7a215a70348 (patch)
tree0919c339e6f9a8a56fed8246af7f365473475784 /source/blender/draw/engines/workbench/workbench_materials.c
parent689a873029b9554a60ee1198344a29cd2f567659 (diff)
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for storing all tiles of a UDIM texture in a single 2D array texture on the GPU. Previously, Eevee was binding one OpenGL texture per tile, quickly running into hardware limits with nontrivial UDIM texture sets. Workbench meanwhile had no UDIM support at all, as reusing the per-tile approach would require splitting the mesh by tile as well as texture. With this commit, both Workbench as well as Eevee now support huge numbers of tiles, with the eventual limits being GPU memory and ultimately GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs. Initially my plan was to have one array texture per unique size, but managing the different textures and keeping everything consistent ended up being way too complex. Therefore, we now use a simpler version that allocates a texture that is large enough to fit the largest tile and then packs all tiles into as many layers as necessary. As a result, each UDIM texture only binds two textures (one for the actual images, one for metadata) regardless of how many tiles are used. Note that this rolls back per-tile GPUTextures, meaning that we again have per-Image GPUTextures like we did before the original UDIM commit, but now with four instead of two types. Reviewed By: fclem Differential Revision: https://developer.blender.org/D6456
Diffstat (limited to 'source/blender/draw/engines/workbench/workbench_materials.c')
-rw-r--r--source/blender/draw/engines/workbench/workbench_materials.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c
index 16fcda54253..2219f5cf2dd 100644
--- a/source/blender/draw/engines/workbench/workbench_materials.c
+++ b/source/blender/draw/engines/workbench/workbench_materials.c
@@ -85,6 +85,7 @@ void workbench_material_update_data(WORKBENCH_PrivateData *wpd,
char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd,
bool is_uniform_color,
bool is_hair,
+ bool is_tiled,
const WORKBENCH_ColorOverride color_override)
{
char *str = NULL;
@@ -102,6 +103,7 @@ char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd,
use_textures = false;
use_vertex_colors = true;
is_hair = false;
+ is_tiled = false;
break;
case WORKBENCH_COLOR_OVERRIDE_OFF:
break;
@@ -151,6 +153,9 @@ char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd,
if (is_hair) {
BLI_dynstr_append(ds, "#define HAIR_SHADER\n");
}
+ if (use_textures && is_tiled) {
+ BLI_dynstr_append(ds, "#define TEXTURE_IMAGE_ARRAY\n");
+ }
str = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds);
@@ -211,6 +216,7 @@ int workbench_material_get_composite_shader_index(WORKBENCH_PrivateData *wpd)
int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd,
bool is_uniform_color,
bool is_hair,
+ bool is_tiled,
const WORKBENCH_ColorOverride color_override)
{
bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color;
@@ -225,6 +231,7 @@ int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd,
case WORKBENCH_COLOR_OVERRIDE_VERTEX:
use_textures = false;
use_vertex_colors = true;
+ is_tiled = false;
break;
case WORKBENCH_COLOR_OVERRIDE_OFF:
break;
@@ -239,6 +246,7 @@ int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd,
SET_FLAG_FROM_TEST(index, MATCAP_ENABLED(wpd), 1 << 4);
SET_FLAG_FROM_TEST(index, use_textures, 1 << 5);
SET_FLAG_FROM_TEST(index, use_vertex_colors, 1 << 6);
+ SET_FLAG_FROM_TEST(index, is_tiled && use_textures, 1 << 7);
BLI_assert(index < MAX_PREPASS_SHADERS);
return index;
}
@@ -246,6 +254,7 @@ int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd,
int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd,
bool is_uniform_color,
bool is_hair,
+ bool is_tiled,
const WORKBENCH_ColorOverride color_override)
{
bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color;
@@ -262,6 +271,7 @@ int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd,
use_textures = false;
use_vertex_colors = true;
is_hair = false;
+ is_tiled = false;
break;
case WORKBENCH_COLOR_OVERRIDE_OFF:
break;
@@ -277,6 +287,7 @@ int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd,
/* 1 bits SHADOWS (only facing factor) */
SET_FLAG_FROM_TEST(index, SHADOW_ENABLED(wpd), 1 << 5);
SET_FLAG_FROM_TEST(index, workbench_is_specular_highlight_enabled(wpd), 1 << 6);
+ SET_FLAG_FROM_TEST(index, is_tiled && use_textures, 1 << 7);
BLI_assert(index < MAX_ACCUM_SHADERS);
return index;
}
@@ -352,6 +363,7 @@ void workbench_material_shgroup_uniform(WORKBENCH_PrivateData *wpd,
WORKBENCH_MaterialData *material,
Object *ob,
const bool deferred,
+ const bool is_tiled,
const int interp)
{
if (deferred && !workbench_is_matdata_pass_enabled(wpd)) {
@@ -362,8 +374,18 @@ void workbench_material_shgroup_uniform(WORKBENCH_PrivateData *wpd,
const bool use_texture = (V3D_SHADING_TEXTURE_COLOR == workbench_material_determine_color_type(
wpd, material->ima, ob, false));
if (use_texture) {
- GPUTexture *tex = GPU_texture_from_blender(material->ima, material->iuser, GL_TEXTURE_2D);
- DRW_shgroup_uniform_texture(grp, "image", tex);
+ if (is_tiled) {
+ GPUTexture *array_tex = GPU_texture_from_blender(
+ material->ima, material->iuser, GL_TEXTURE_2D_ARRAY);
+ GPUTexture *data_tex = GPU_texture_from_blender(
+ material->ima, material->iuser, GL_TEXTURE_1D_ARRAY);
+ DRW_shgroup_uniform_texture(grp, "image_tile_array", array_tex);
+ DRW_shgroup_uniform_texture(grp, "image_tile_data", data_tex);
+ }
+ else {
+ GPUTexture *tex = GPU_texture_from_blender(material->ima, material->iuser, GL_TEXTURE_2D);
+ DRW_shgroup_uniform_texture(grp, "image", tex);
+ }
DRW_shgroup_uniform_bool_copy(
grp, "imagePremultiplied", (material->ima->alpha_mode == IMA_ALPHA_PREMUL));
DRW_shgroup_uniform_bool_copy(grp, "imageNearest", (interp == SHD_INTERP_CLOSEST));