GPU: Refactor texture samplers #105642
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105642
Loading…
Reference in New Issue
No description provided.
Delete Branch "OmarEmaraDev/blender:texture-sampler-refactor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This patch refactors the texture samples code by mainly splitting the
eGPUSamplerState enum into multiple smaller enums and packing them
inside a GPUSamplerState struct. This was done because many members of
the enum were mutually exclusive, which was worked around during setting
up the samplers in the various backends, and additionally made the API
confusing, like the GPU_texture_wrap_mode function, which had two
mutually exclusive parameters.
The new structure also improved and clarified the backend sampler cache,
reducing the cache size from 514 samplers to just 130 samplers, which
also slightly improved the initialization time. Further, the
GPU_SAMPLER_MAX signal value was naturally incorporated into the
structure using the GPU_SAMPLER_STATE_TYPE_INTERNAL type.
The only expected functional change is in the realtime compositor, which
now supports per-axis repetition control, utilizing new API functions
for that purpose.
This patch is loosely based on an older patch D14366 by Ethan Hall.
@blender-bot package macos
Package build started. Download here when ready.
@blender-bot package macos
Package build started. Download here when ready.
@blender-bot package macos
Package build started. Download here when ready.
@ -40,3 +37,1 @@
* extension / wrap mode etc...
*/
typedef enum eGPUSamplerState {
typedef enum eGPUSamplerFiltering {
I think it is a good opportunity to remove the
e
prefix which is not part of the code-style anymore (because it doesn't add more information).@ -46,2 +41,3 @@
*/
GPU_SAMPLER_DEFAULT = 0,
GPU_SAMPLER_FILTERING_DEFAULT = 0,
All these empty lines can be remove.
@ -70,0 +83,4 @@
*/
typedef enum eGPUSamplerWrapType {
/** Extrapolate by extending the edge pixels of the texture, in other words, the texture
coordinates are clamped. */
Comment style.
@ -70,0 +87,4 @@
GPU_SAMPLER_WRAP_EXTEND = 0,
/** Extrapolate by repeating the texture. */
GPU_SAMPLER_WRAP_REPEAT = 1,
I think you can omit the actual value set after the first one. Keep
= 0
but remove= 1
,= 2
, ...@ -75,0 +98,4 @@
* */
GPU_SAMPLER_WRAP_CLIP = 3,
GPU_SAMPLER_WRAP_TYPES_COUNT = 4,
It was discussed that these counts should be defined like this:
#define GPU_SAMPLER_WRAP_TYPES_COUNT (GPU_SAMPLER_WRAP_CLIP + 1)
This is because it allows to skip this case in
switch
statements and not have a compiler warning.@ -97,3 +185,1 @@
static constexpr eGPUSamplerState GPU_SAMPLER_MAX = eGPUSamplerState(GPU_SAMPLER_ICON + 1);
#else
static const int GPU_SAMPLER_MAX = (GPU_SAMPLER_ICON + 1);
static constexpr GPUSamplerState default_sampler()
These should be documented. For example, I'm not sure what an
internal_sampler
is right away.@ -100,0 +222,4 @@
* Enables the given filtering options if and only if the given condition is true, otherwise,
* disables it.
*/
void set_filtering(GPUSamplerFiltering target_filtering, bool condition = true)
I think name of the function is confusing.
To me, you should remove the condition and have an
unset_filtering
equivalent.But this does make the callers use if statements most of the time.
Another possibility is to use a more descriptive name like
set_filtering_flag_from_test
.I tried couple of names and signatures for this function and eventually went for set_filtering because it apparently hides the underlying data and makes sense when reading it, for instance:
The user does not know how filtering is stored internally, the function just promises that it can be enabled or disabled, and reading the function feels natural. What do you think?
The thing is, filtering is too generic of a name. I don't know if this will set the whole
enum
value or just one option if I seeset_filtering(GPU_SAMPLER_FILTERING_MIPMAP)
. And I don't immediatly know whatfalse
refers to when seeingset_filtering(GPU_SAMPLER_FILTERING_MIPMAP, false)
.I would say
enable_filtering_flag(flag)
,disable_filtering_flag(flag)
andset_filtering_flag_from_test(flag, test)
would be better from a semantical point of view.I still have to review all the usages. But the overall approach looks good.
@fclem One thing to note is that my Metal changes are blindly made, so it would be good if someone can test Metal.
@ -453,7 +453,7 @@ static bool createGPUCurveMapping(OCIO_GPUCurveMappping &curvemap,
curvemap.texture = GPU_texture_create_1d(
"OCIOCurveMap", lut_size, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
GPU_texture_filter_mode(curvemap.texture, false);
GPU_texture_wrap_mode(curvemap.texture, false, true);
It seems you did not took into account the clamp to border color case in all of these.
@ -70,0 +78,4 @@
* The `GPUSamplerWrapType` specifies how the texture will be extrapolated for out-of-bound
* texture sampling.
*/
typedef enum GPUSamplerWrapType {
Wrap is a bit misleading terminology here. So maybe
GPUSamplerExtendMode
?@ -75,0 +92,4 @@
* Extrapolate using the value of TEXTURE_BORDER_COLOR, which is always set to a transparent
* black color (0, 0, 0, 0) and can't be changed.
*/
GPU_SAMPLER_WRAP_CLIP,
Rename to
CLAMP_TO_BORDER
instead ofCLIP
.@ -96,0 +178,4 @@
typedef struct GPUSamplerState {
GPUSamplerFiltering filtering : 8;
GPUSamplerWrapType wrapping_x : 4;
GPUSamplerWrapType wrapping_y : 4;
You are missing the
wrapping_z
for 3D texture.Prefer using
extend_x/y/z
.@ -453,7 +453,7 @@ static bool createGPUCurveMapping(OCIO_GPUCurveMappping &curvemap,
curvemap.texture = GPU_texture_create_1d(
"OCIOCurveMap", lut_size, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
GPU_texture_filter_mode(curvemap.texture, false);
GPU_texture_wrap_mode(curvemap.texture, false, true);
Can you clarify this? Where is the clamp to border case here?
@ -96,0 +178,4 @@
typedef struct GPUSamplerState {
GPUSamplerFiltering filtering : 8;
GPUSamplerWrapType wrapping_x : 4;
GPUSamplerWrapType wrapping_y : 4;
I did not add a z wrapping option for now because it had no use in the code base at the moment. So I though maybe we should add it when we really need it.
@ -453,7 +453,7 @@ static bool createGPUCurveMapping(OCIO_GPUCurveMappping &curvemap,
curvemap.texture = GPU_texture_create_1d(
"OCIOCurveMap", lut_size, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
GPU_texture_filter_mode(curvemap.texture, false);
GPU_texture_wrap_mode(curvemap.texture, false, true);
Disregard that. I did check all usage and they look right.
@ -91,0 +157,4 @@
* the texture will be used. In other words, this is a signal value and stores no useful or
* actual data.
*/
GPU_SAMPLER_STATE_TYPE_INTERNAL = 2,
Remaining value.
@ -96,0 +178,4 @@
typedef struct GPUSamplerState {
GPUSamplerFiltering filtering : 8;
GPUSamplerExtendMode extend_x : 4;
GPUSamplerExtendMode extend_y : 4;
The thing is, we already use 3D textures, and some of them use
CLAMP_TO_BORDER
(ex: Volumes Attributes) and some useEXTEND
(ex: EEVEE Volume temp textures). If the choice to omitwrapping_z
is to save a dimension, it should be documented. Maybe renamewrapping_y
towrapping_yz
in this case and make Z follow Y extend mode.@ -545,2 +547,3 @@
GLuint GLTexture::samplers_[GPU_SAMPLER_MAX] = {0};
/** A static array that maps GPUSamplerExtendMode values to their OpenGL enum counterparts. */
static const GLenum gl_texture_wrap_mode_map[] = {
Replace by
GLenum to_gl(GPUSamplerExtendMode mode)
inline function. Seeinline GLenum to_gl(eGPUDataFormat format)
for example.Doing so will produce a compiler error if any new enum value is being added.
It might be better to commit this after the 3.5 release to avoid merge conflict.
@blender-bot package macos
Package build started. Download here when ready.