Commit Graph

11 Commits

Author SHA1 Message Date
Clément Foucault
fe213f80a4 GPU: Shader: Make info files generated
This is the first step of moving the create infos
back inside shader sources.

All info files are now treated as source files.
However, they are not considered in the include tree
yet. This will come in another following PR.

Each shader source file now generate a `.info` file
containing only the create info declarations.

This renames all info files so that they do not
conflict with their previous versions that were
copied (non-generated).

Pull Request: https://projects.blender.org/blender/blender/pulls/146676
2025-09-25 10:57:02 +02:00
Hans Goudey
59c65a7994 Mesh: Separate GPU subdivision normals and positions
Currently for the result of GPU subdivision, normals are stored in two
places. First, interleaved with the positions, and second, in a separate
"lnor" vertex buffer. This extra duplication costs 12 bytes of GPU
memory usage per subdivided face corner, which is quite a lot. It also
causes problems because it's inconsistent with the format used for
regular non-subdivided meshes, causing various hacks and issues
throughout the code.

This PR moves the normals into just the "lnor" vertex buffer. This
starts some code simplifications, but ends up still more complicated
than I'd like because some edit selection flags are still stored in the
fourth component of the normal vector. Tacking that makes this PR too
big, but it would be a good next step.

Pull Request: https://projects.blender.org/blender/blender/pulls/137158
2025-06-06 18:04:59 +02:00
Clément Foucault
3b3a5731df GPU: Shader: Change vector and matrix type to use blender convention
This unify the C++ and GLSL codebase style.

The GLSL types are still in the backend compatibility
layers to support python shaders. However, the C++
shader compilation layer doesn't have them to enforce
correct type usage.

Note that this is going to break pretty much all PRs
in flight that targets shader code.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137369
2025-04-14 13:46:41 +02:00
Clément Foucault
bb52754652 GPU: Use f suffix for float literals
They are actually already some literals with the `f` suffix
that are in our shader codebase and we never had problem in
the past 5 years (or even 8 years).

So I think it is safe to do and improves convergence of codestyles.

Pull Request: https://projects.blender.org/blender/blender/pulls/137352
2025-04-11 18:28:45 +02:00
Jeroen Bakker
3ad5721a1c Fix #136767: SubDiv: Incorrect attribute interpolation
177bbf12df solved the out of bound read
by limiting the input search. However this lead to incorrect
interpolation. This has been fixed by moving the bound check as a
post check.

Pull Request: https://projects.blender.org/blender/blender/pulls/136769
2025-03-31 15:43:01 +02:00
Jeroen Bakker
177bbf12df Fix #136239: SubDiv: Read out of bounds
GPU subdivision shaders can read out of bound when evaluating
the last face. This seems to be always been the case, but Metal + Vulkan
has validation to detect these mis-usages.

Binary search was initialized with out of bound values so the last
face could select out of bound index due to rounding.

Pull Request: https://projects.blender.org/blender/blender/pulls/136242
2025-03-20 12:17:58 +01:00
Jeroen Bakker
22aad0fde7 SubDiv: Use shader create info for patch evaluation shader
This PR migrates the subdiv_patch_evaluation_comp.glsl to use
shader create info.

The part of OSD that is used is included as a typedef source (osd_patch_basis.glsl).

Pull Request: https://projects.blender.org/blender/blender/pulls/134917
2025-02-27 15:42:08 +01:00
Jeroen Bakker
fcc5681624 SubDiv: Use shader create info for custom data
This PR migrates the custom_data_interp_comp.glsl to use
shader create info.

During development tests have been conducted to use specialization constants,
but due to limitations inside Metal we didn't use them.

Number of ShaderCreateInfos have been reduced by using macros. Variadic macros
have not been used as they don't support CPP compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/134932
2025-02-27 09:50:36 +01:00
Jeroen Bakker
3969e30c6f SubDiv: Add base for polygon offset
Subdiv shader library contains an optional part that shaders can include.
As we are migrating each shader at a time there are now multiple PRs doing
the same thing. Best to add the changes to main already so it doesn't add
confusion during review.

Pull Request: https://projects.blender.org/blender/blender/pulls/134906
2025-02-21 10:21:44 +01:00
Jeroen Bakker
e39669e3c3 SubDiv: Use shader create info for SubdivNormalsFinalize shaders.
This change migrates the first 2 subdiv shaders  to use the ShaderCreateInfo.
Other shaders will follow in separate PRs.

- Should compile when using `WITH_GPU_SHADER_CPP_COMPILATION`
- A `subdiv_` prefix is added only to the functions related to `PosNorLoop`.
    But eventually the prefix should also be added to other lib functions.
- Due to Metal restrictions `subdiv_set_vertex_*` is implemented using a
    functional paradigma. Our Metal backend only supports `inout` qualifier
    on thead local data structures.

Pull Request: https://projects.blender.org/blender/blender/pulls/134218
2025-02-20 12:30:51 +01:00
Jeroen Bakker
d496e69eca Cleanup: Subdiv: Remove common_ prefix
The `common_` prefix can be confusing as there are other common_ files as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/134184
2025-02-07 07:48:49 +01:00