Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/eevee_materials.c
| Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | typedef struct EeveeMaterialCache { | ||||
| * Pointers to ghash values. */ | * Pointers to ghash values. */ | ||||
| struct DRWShadingGroup **depth_grp_p; | struct DRWShadingGroup **depth_grp_p; | ||||
| struct DRWShadingGroup **shading_grp_p; | struct DRWShadingGroup **shading_grp_p; | ||||
| struct DRWShadingGroup **shadow_grp_p; | struct DRWShadingGroup **shadow_grp_p; | ||||
| } EeveeMaterialCache; | } EeveeMaterialCache; | ||||
| /* *********** FUNCTIONS *********** */ | /* *********** FUNCTIONS *********** */ | ||||
| /** | |||||
| * Create the cache key for the given gpu material. Used as key in | |||||
| * `EEVEE_PrivateData.material_hash`. | |||||
| */ | |||||
| BLI_INLINE void *EEVEE_materials_cache_key(GPUMaterial *gpumat, int option) | |||||
| { | |||||
| void *cache_key = (char *)gpumat + option; | |||||
| return cache_key; | |||||
| } | |||||
| /* XXX TODO define all shared resources in a shared place without duplication */ | /* XXX TODO define all shared resources in a shared place without duplication */ | ||||
| struct GPUTexture *EEVEE_materials_get_util_tex(void) | struct GPUTexture *EEVEE_materials_get_util_tex(void) | ||||
| { | { | ||||
| return e_data.util_tex; | return e_data.util_tex; | ||||
| } | } | ||||
| /** | /** | ||||
| * ssr_id can be null to disable ssr contribution. | * ssr_id can be null to disable ssr contribution. | ||||
| ▲ Show 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | GPUMaterial *gpumat = (use_shadow_shader) ? | ||||
| EEVEE_material_default_get(scene, ma, mat_options); | EEVEE_material_default_get(scene, ma, mat_options); | ||||
| /* Avoid possible confusion with depth pre-pass options. */ | /* Avoid possible confusion with depth pre-pass options. */ | ||||
| int option = KEY_SHADOW; | int option = KEY_SHADOW; | ||||
| SET_FLAG_FROM_TEST(option, is_hair, KEY_HAIR); | SET_FLAG_FROM_TEST(option, is_hair, KEY_HAIR); | ||||
| /* Search for the same shaders usage in the pass. */ | /* Search for the same shaders usage in the pass. */ | ||||
| struct GPUShader *sh = GPU_material_get_shader(gpumat); | struct GPUShader *sh = GPU_material_get_shader(gpumat); | ||||
| void *cache_key = (char *)sh + option; | void *cache_key = EEVEE_materials_cache_key(gpumat, option); | ||||
| DRWShadingGroup *grp, **grp_p; | DRWShadingGroup *grp, **grp_p; | ||||
| if (BLI_ghash_ensure_p(pd->material_hash, cache_key, (void ***)&grp_p)) { | if (BLI_ghash_ensure_p(pd->material_hash, cache_key, (void ***)&grp_p)) { | ||||
| /* This GPUShader has already been used by another material. | /* This GPUShader has already been used by another material. | ||||
| * Add new shading group just after to avoid shader switching cost. */ | * Add new shading group just after to avoid shader switching cost. */ | ||||
| grp = DRW_shgroup_create_sub(*grp_p); | grp = DRW_shgroup_create_sub(*grp_p); | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | DRWPass *depth_ps = (DRWPass *[]){ | ||||
| psl->depth_refract_ps, | psl->depth_refract_ps, | ||||
| psl->depth_refract_cull_ps, | psl->depth_refract_cull_ps, | ||||
| }[option]; | }[option]; | ||||
| /* Hair are rendered inside the non-cull pass but needs to have a separate cache key. */ | /* Hair are rendered inside the non-cull pass but needs to have a separate cache key. */ | ||||
| SET_FLAG_FROM_TEST(option, is_hair, KEY_HAIR); | SET_FLAG_FROM_TEST(option, is_hair, KEY_HAIR); | ||||
| /* Search for the same shaders usage in the pass. */ | /* Search for the same shaders usage in the pass. */ | ||||
| struct GPUShader *sh = GPU_material_get_shader(gpumat); | struct GPUShader *sh = GPU_material_get_shader(gpumat); | ||||
| void *cache_key = (char *)sh + option; | void *cache_key = EEVEE_materials_cache_key(gpumat, option); | ||||
| DRWShadingGroup *grp, **grp_p; | DRWShadingGroup *grp, **grp_p; | ||||
| if (BLI_ghash_ensure_p(pd->material_hash, cache_key, (void ***)&grp_p)) { | if (BLI_ghash_ensure_p(pd->material_hash, cache_key, (void ***)&grp_p)) { | ||||
| /* This GPUShader has already been used by another material. | /* This GPUShader has already been used by another material. | ||||
| * Add new shading group just after to avoid shader switching cost. */ | * Add new shading group just after to avoid shader switching cost. */ | ||||
| grp = DRW_shgroup_create_sub(*grp_p); | grp = DRW_shgroup_create_sub(*grp_p); | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 25 Lines | DRWPass *shading_pass = (DRWPass *[]){ | ||||
| psl->material_cull_ps, | psl->material_cull_ps, | ||||
| }[option]; | }[option]; | ||||
| /* Hair are rendered inside the non-cull pass but needs to have a separate cache key */ | /* Hair are rendered inside the non-cull pass but needs to have a separate cache key */ | ||||
| option = option * 2 + is_hair; | option = option * 2 + is_hair; | ||||
| /* Search for the same shaders usage in the pass. */ | /* Search for the same shaders usage in the pass. */ | ||||
| /* HACK: Assume the struct will never be smaller than our variations. | /* HACK: Assume the struct will never be smaller than our variations. | ||||
| * This allow us to only keep one ghash and avoid bigger keys comparisons/hashing. */ | * This allow us to only keep one ghash and avoid bigger keys comparisons/hashing. */ | ||||
| BLI_assert(option <= 16); | BLI_assert(option <= 16); | ||||
jbakker: Could be removed as GPUMaterial is large... | |||||
| struct GPUShader *sh = GPU_material_get_shader(gpumat); | struct GPUShader *sh = GPU_material_get_shader(gpumat); | ||||
| void *cache_key = (char *)sh + option; | void *cache_key = EEVEE_materials_cache_key(gpumat, option); | ||||
| DRWShadingGroup *grp, **grp_p; | DRWShadingGroup *grp, **grp_p; | ||||
| if (BLI_ghash_ensure_p(pd->material_hash, cache_key, (void ***)&grp_p)) { | if (BLI_ghash_ensure_p(pd->material_hash, cache_key, (void ***)&grp_p)) { | ||||
| /* This GPUShader has already been used by another material. | /* This GPUShader has already been used by another material. | ||||
| * Add new shading group just after to avoid shader switching cost. */ | * Add new shading group just after to avoid shader switching cost. */ | ||||
| grp = DRW_shgroup_create_sub(*grp_p); | grp = DRW_shgroup_create_sub(*grp_p); | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 507 Lines • Show Last 20 Lines | |||||
Could be removed as GPUMaterial is large...