Commit Graph

190 Commits

Author SHA1 Message Date
Campbell Barton 686605a6dd Cleanup: declare arrays as const where possible 2024-03-28 22:57:57 +11:00
Hans Goudey 8b514bccd1 Cleanup: Move remaining GPU headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/119807
2024-03-23 01:24:18 +01:00
Clément Foucault 4205718dce GPU: Cleanup type aliases
This define all aliases for supported types,
document which one to use in C++ shared code,
move relevant defines to their backend file.

Rename `bool1` to `bool32_t` and cleanup
its usage as mentioned in #118961.

Rel. #118961

Pull Request: https://projects.blender.org/blender/blender/pulls/119098
2024-03-08 19:09:10 +01:00
Hans Goudey 1e1d7034ec Cleanup: Move GPU_uniform_buffer.h to C++ 2024-03-06 21:54:28 -05:00
Brecht Van Lommel 94e2973f0b Build: support OpenColorIO 2.3
For Linux distributions or others that upgrade before we do.

Ref #113157

Pull Request: https://projects.blender.org/blender/blender/pulls/113163
2023-10-02 19:31:19 +02:00
Campbell Barton 5b9740c913 Cleanup: use braces for sources in intern/
Omitted intern/itasc as some of these sources are from KDL:
https://www.orocos.org/kdl.html
2023-09-17 09:05:40 +10:00
Campbell Barton e8c812a307 Cleanup: spelling in comments, update dictionary 2023-09-03 21:35:07 +10:00
Campbell Barton eec449ffe8 Cleanup: correct spelling, comments
Hyphenate words in GLSL code-comments.
2023-08-29 15:55:09 +10:00
Campbell Barton 3de8900ed6 Cleanup: spelling in comments 2023-08-25 09:40:42 +10:00
Campbell Barton 0148293520 License headers: add SPDX licenses for '*.glsl' files
When GLSL sources were first included in Blender they were treated as
data (like blend files) and had no license header.
Since then GLSL has been used for more sophisticated features
(EEVEE & real-time compositing)
where it makes sense to include licensing information.

Add SPDX copyright headers to *.glsl files, matching headers used for
C/C++, also include GLSL files in the license checking script.

As leading C-comments are now stripped,
added binary size of comments is no longer a concern.

Ref !111247
2023-08-24 10:57:03 +10:00
Campbell Barton 20b4a77872 datatoc: exclude the initial C-style comment from GLSL/MSL/Cuda files
Add optional argument `STRIP_LEADING_C_COMMENTS` to CMake macros:
data_to_c_simple & data_to_c.

Strip leading C-style comments that don't bloat binary size.
Comments are replaced with blank lines so line numbers in error messages
match. Reduces Blender's binary size by ~70kb.
2023-08-19 17:57:12 +10:00
Sergey Sharybin 3a3390fcdd Cleanup: Strict compiler warning
Pull Request: https://projects.blender.org/blender/blender/pulls/111233
2023-08-17 17:22:08 +02:00
Sergey Sharybin 259bfc4553 Fix GradingPrimaryTransform OCIO transform in Metal
This transform generates code `if ( gamma != vec3(1., 1., 1.) )`
which is not compatible with Metal.

This patch adds an extra OCIO code processing which converts syntax
to a portable version. It only handles this specific case for the
processing performance reasons.

To reproduce the issue add the following look at the end of the
config.ocio:

```
  - !<Look>
    name: Grading
    process_space: Filmic Log
    description: TEST
    transform: !<GroupTransform>
      children:
        - !<GradingPrimaryTransform>
          style: log
          contrast: {rgb: [0.7, 0.7, 0.7], master: 1}
          saturation: 1.15
          pivot: {contrast: -0.2}
```

Ref #110685

Pull Request: https://projects.blender.org/blender/blender/pulls/111231
2023-08-17 15:27:51 +02:00
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Aras Pranckevicius d973355b3a Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).

However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.

This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.

Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
  to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).

Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.

Pull Request #110944
2023-08-10 14:51:40 +03:00
Sergey Sharybin ba81908a2d Color management: Improve no-op color space detection
Make it so transform between color spaces which is a no-op does not
peroform any calculations.

This was initially found when working on #110941, but the issue can
be replicated easily by renaming "Linear" to "Linear Rec.709" and
adding alias as "Linear".

Doing so would result in a failure of the compositor_matte_test.
The reason for that is due to the image data-block still referring
to the "Linear" color space, the name-based comparison not detecting
that "Linear" and "Linear Rec.709" are the same spaces, and that the
cryptomatte requires bit-perfect floating point values.

Pull Request: https://projects.blender.org/blender/blender/pulls/110959
2023-08-09 16:24:49 +02:00
Jason Fielder 2367ed2ef2 macOS: Enable support for EDR rendering
Add a High Dynamic Range option in the Color Management > Display panel.
This enables display of extended color ranges above 1.0 for the 3D
viewport, image editor and render previews.

This requires a monitor that can display HDR colors, and a view
transform designed for HDR output. The Standard view transform works,
but Filmic does not as it was designed to bring values into the 0..1
range for SDR displays.

This patch is limited to allowing the display to visualize extended
colors, but does not include future looking work to better integrate HDR
into the full workflow.

It is implemented by rendering to high bit-depth texture formats for
the user interface, and uncapping the color range in color management.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/105662
2023-08-09 14:25:15 +02:00
Sergey Sharybin d7886ee759 Color management: Further relax threshold for sRGB detection
Apparently, the SSE optimization in the OCIO is not nearly as accurate
as a naive implementation. For example, exponent transform of 1 gives
result of 1.000024.

Ref #110685

Pull Request: https://projects.blender.org/blender/blender/pulls/110895
2023-08-07 15:53:03 +02:00
Sergey Sharybin d50b139b06 Color management: Relax threshold for sRGB detection
The current core was only detecting sRGB transform when it is defined
as sRGB->Linear using srgb.spi1d. If it is defined as an inverse of
Linear->sRGB using srgb_inv.spi1d, or as an analytical formula using
ExponentWithLinearTransform then the code did not detect the color
as sRGB on anything by Apple Silicon platform.

The naming of the checks could be improved to make it more clear that
the check is only used to allow lossless access to 8bit sRGB textures.

Ref #110685

Pull Request: https://projects.blender.org/blender/blender/pulls/110889
2023-08-07 14:32:16 +02:00
Ray Molenkamp 04235d0e55 Cleanup: CMake: Modernize bf_blenlib dependencies
Pretty straightforward

- Remove any blenlib paths from INC
- Add a dependency though LIB

Pull Request: https://projects.blender.org/blender/blender/pulls/109934
2023-07-10 22:04:18 +02:00
Ray Molenkamp 57ad866d81 Cleanup: CMake: Modernize bf_guardedalloc dependencies
Pretty straightforward

- Removes any guardedalloc paths from INC
- Adds a dependency though LIB

Pull Request: https://projects.blender.org/blender/blender/pulls/109925
2023-07-10 18:44:19 +02:00
Ray Molenkamp 7cebb61486 Cleanup: CMake: Modernize bf_dna dependencies
There's quite a few libraries that depend on dna_type_offsets.h
but had gotten to it by just adding the folder that contains it to
their includes INC section without declaring a dependency to
bf_dna in the LIB section.

which occasionally lead to the lib building before bf_dna and the
header being missing, while this generally gets fixed in CMake by
adding bf_dna to the LIB section of the lib, however until last
week all libraries in the LIB section were linked as INTERFACE so
adding it in there did not resolve the build issue.

To make things still build, we sprinkled add_dependencies wherever
we needed it to force a build order.

This diff :

Declares public include folders for the bf_dna target so there's
no more fudging the INC section required to get to them.

Removes all dna related paths from the INC section for all
libraries.

Adds an alias target bf:dna to signify it has been updated to
modern cmake

Declares a dependency on bf::dna for all libraries that require it

Removes (almost) all calls to add_dependencies for bf_dna

Future work:

Because of the manual dependency management that was done, there is
now some "clutter" with libs depending on bf_dna that realistically
don't. Example bf_intern_opencolorio itself has no dependency on
bf_dna at all, doesn't need it, doesn't use it. However the
dna include folder had been added to it in the past since bf_blenlib
uses dna headers in some of its public headers and
bf_intern_opencolorio does use those blenlib headers.

Given bf_blenlib now correctly declares the dependency on bf_dna
as public bf_intern_opencolorio will get the dna header directory
automatically from CMake, hence some cleanup could be done for
bf_intern_opencolorio

Because 99% of the changes in this diff have been automated, this diff
does not seek to address these issues as there is no easy way to
determine why a certain dependency is in place. A developer will have
to make a pass a this at some later point in time. As I'd rather not
mix automated and manual labour.

There are a few libraries that could not be automatically processed
(ie bf_blendthumb) that also will need this manual look-over.

Pull Request: https://projects.blender.org/blender/blender/pulls/109835
2023-07-10 15:07:37 +02:00
Campbell Barton 345d1a4b44 Cleanup: simplify struct declarations in C++
Replace `typedef struct X {} X;` with `struct X {};`

In some cases the first and last name didn't match although this
is rarely useful, even a typo in some cases, e.g. TrachPathPoint.
2023-07-02 19:54:26 +10:00
Campbell Barton 65f99397ec License headers: use SPDX-FileCopyrightText in all sources 2023-06-15 13:35:34 +10:00
Campbell Barton 49594c37ae License headers: use SPDX-FileCopyrightText for CMake files 2023-06-14 23:36:23 +10:00
Sergey Sharybin e3f14b99c3 Refactor: Convert ImBuf to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/107503
2023-05-02 11:32:27 +02:00
Campbell Barton 6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Omar Emara ff3b2226fb GPU: Refactor texture samplers
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.

Pull Request: https://projects.blender.org/blender/blender/pulls/105642
2023-04-04 15:16:07 +02:00
Sergey Sharybin a12a8a71bb Remove "All Rights Reserved" from Blender Foundation copyright code
The goal is to solve confusion of the "All rights reserved" for licensing
code under an open-source license.

The phrase "All rights reserved" comes from a historical convention that
required this phrase for the copyright protection to apply. This convention
is no longer relevant.

However, even though the phrase has no meaning in establishing the copyright
it has not lost meaning in terms of licensing.

This change makes it so code under the Blender Foundation copyright does
not use "all rights reserved". This is also how the GPL license itself
states how to apply it to the source code:

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software ...

This change does not change copyright notice in cases when the copyright
is dual (BF and an author), or just an author of the code. It also does
mot change copyright which is inherited from NaN Holding BV as it needs
some further investigation about what is the proper way to handle it.
2023-03-30 10:51:59 +02:00
Sergey Sharybin d32d787f5f Clang-Format: Allow empty functions to be single-line
For example

```
OIIOOutputDriver::~OIIOOutputDriver()
{
}
```

becomes

```
OIIOOutputDriver::~OIIOOutputDriver() {}
```

Saves quite some vertical space, which is especially handy for
constructors.

Pull Request: https://projects.blender.org/blender/blender/pulls/105594
2023-03-29 16:50:54 +02:00
Brecht Van Lommel 1658de6769 Merge branch 'blender-v3.5-release' 2023-03-06 23:14:18 +01:00
Brecht Van Lommel 83f28793c0 Fix missing data role in color management fallback
This would show as warning in gtests. Does not affect normal operation as
OpenColorIO should have a valid configuration file for Blender itself.
2023-03-06 23:01:50 +01:00
Clément Foucault 9fb1f32f06 Cleanup: GPUTexture: Remove _ex suffix from texture creation
It isn't relevant anymore now that usage flags are mandatory.

Pull Request #105197
2023-02-25 11:39:54 +01:00
Clément Foucault e01b140fb2 GPUTexture: Remove data_format from 3D texture creation function
For every other texture types this is expected to be implicitly
`GPU_DATA_FLOAT`. There is only one case where this is not the case.

I believe this was previously needed because the data type was
conditionning the texture creation. This is not the case anymore.
2023-02-25 11:39:53 +01:00
Campbell Barton 91346755ce Cleanup: use '#' prefix for issues instead of 'T'
Match the convention from Gitea instead of Phabricator's T for tasks.
2023-02-12 14:56:05 +11:00
Jason Fielder 2e61c446ac GPU: Explicit Texture Usage Flags for enabling GPU Backend optimizations.
Texture usage flags can now be provided during texture creation specifying
the ways in which a texture can be used. This allows the GPU backends to
perform contextual optimizations which were not previously possible. This
includes enablement of hardware lossless compression which can result in
a 15%+ performance uplift for bandwidth-limited scenes on hardware such
as Apple-Silicon using Metal.

GPU_TEXTURE_USAGE_GENERAL can be used by default if usage is not known
ahead of time. Patch will also be relevant for the Vulkan backend.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem
Differential Revision: https://developer.blender.org/D15967
2022-12-08 23:31:05 +01:00
Jason Fielder 18b45aabf9 Metal: GLSL shader compatibility changes for global uniform and interface name collision.
For the Metal shader translation support for shader-global uniforms are remapped via macro's, and in such cases where a uniform name matches a vertex attribute name, compilation errors will occur due to this injected syntax being incompatible with the immediate code.

Also adding source-level function interface alternatives where sized arrays are passed in. These are not supported directly in Metal shading language and are instead handled as pointers. These pointers require explicit address-space qualifiers in some cases, if device/constant address space memory is passed into the function.

Ref T96261

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D15898
2022-09-22 17:53:56 +02:00
Sebastian Parborg 8ffc11dbcb Cleanup OpenGL linking and related code after libepoxy merge
This cleans up the OpenGL build flags and linking.
It additionally also removes some dead code.

One of these dead code paths is WITH_X11_ALPHA which actually never was
active even with the build flag on. The call to use this was never
called because the default initializer for GHOST was set to have it off
per default. Nothing called this function with a boolean value to enable it.

These cleanups are needed to support true headless OpenGL rendering.
Without these cleanups libepoxy will fail to load the correct OpenGL
Libraries as we have already linked them to the blender binary.

Reviewed By: Brecht, Campbell, Jeroen

Differential Revision: http://developer.blender.org/D15554
2022-08-15 16:47:20 +02:00
Christian Rauch a296b8f694 GPU: replace GLEW with libepoxy
With libepoxy we can choose between EGL and GLX at runtime, as well as
dynamically open EGL and GLX libraries without linking to them.

This will make it possible to build with Wayland, EGL, GLVND support while
still running on systems that only have X11, GLX and libGL. It also paves
the way for headless rendering through EGL.

libepoxy is a new library dependency, and is included in the precompiled
libraries. GLEW is no longer a dependency, and WITH_SYSTEM_GLEW was removed.

Includes contributions by Brecht Van Lommel, Ray Molenkamp, Campbell Barton
and Sergey Sharybin.

Ref T76428

Differential Revision: https://developer.blender.org/D15291
2022-08-15 16:10:29 +02:00
Brecht Van Lommel eb5e7d0a31 Cleanup: clarify what is scene linear color space in conversion conversion
* Rename ambiguous rgb to scene_linear in some places
* Precompute matrices to directly go to scene instead of through XYZ
* Make function signatures more consistent
2022-05-23 15:34:50 +02:00
Brecht Van Lommel 469ee7ff15 Python API: add mathutils.Color functions to convert color spaces
Between scene linear and sRGB, XYZ, linear Rec.709 and ACES2065-1.

And add some clarifications about color spaces in the docs.

Fixes T98267

Ref T68926

Differential Revision: https://developer.blender.org/D14989
2022-05-23 15:34:50 +02:00
Brecht Van Lommel c65b022e62 Fix OpenColorIO error with configs using <USE_DISPLAY_NAME>
* Don't assume the display colorspace name fully defines the transform
  to display space, this is not true in OpenColorIO 2 where view transforms
  may be defined in more complexs ways than just specifying a colorspace.
* In places where we need to store the display colorspace name, resolve
  <USE_DISPLAY_NAME> token manually.

Ref T96590
2022-04-11 20:10:42 +02:00
Sergey Sharybin a410cea291 Fix prefix used for display OCIO shader
Didn't notice this to have real harmful behavior, but is still best
to do things properly.
2022-04-08 11:27:51 +02:00
Brecht Van Lommel 4a1b0ea902 Fix T94001: OpenColorIO configuration with 1D textures not working 2022-03-24 19:42:59 +01:00
Brecht Van Lommel 5ac4e6c911 Color Management: add support for OpenColorIO color space aliases
This enables the configuration to specify aliases for compatibility with other
configurations.

When a colorspace name is saved in a.blend, that is the alias of a colorspace
in the current configuration, it will show the main colorspace from the
configuration in the user interface and Python API instead.

Loading & saving the .blend file does not make any changes to the stored name,
so as to not make hidden modifications. Only when setting the property again
will the alias name be overwritten by the main colorspace name.

Fixes T96049

Differential Revision: https://developer.blender.org/D14419
2022-03-23 15:21:58 +01:00
Jeroen Bakker 51727fe86f Fix T96502: Compilation error OCIO when using GradingPrimaryTransform.
When using GradingPrimaryTransform the generated GLSL code fails to compile. The actual issue is
inside OCIO (https://github.com/AcademySoftwareFoundation/OpenColorIO/issues/1603).

The reason is that unset clamping values are rendered out as `inf`, which isn't recognizable
by GLSL.

The issue is worked around by defining a default for `inf`.

Reviewed By: brecht

Maniphest Tasks: T96502

Differential Revision: https://developer.blender.org/D14425
2022-03-23 14:13:09 +01:00
Clément Foucault 1685b1dba4 OCIO: Fix mip length in texture creation
Also add an assert to avoid reproducing the error in the future.
2022-02-24 15:48:54 +01:00
Clément Foucault 2f951667c0 OCIO: Fix bool1 vs. bool comparison warning.
Fixes the following warning:
`'!=': unsafe mix of type 'bool1' and type 'bool' in operation`
2022-02-22 17:29:32 +01:00
Clément Foucault 16d5658365 OCIO: Port shader creation logic to use GPUShaderCreateInfo
This commit should suffice to make the shader API agnostic now (given that
all users of it use the GPU API).

This makes the shaders not trigger a false positive error anymore since
the binding slots are now garanteed by the backend and not changed at
after compilation.

This also bundles all uniforms into UBOs. Making them extendable without
limitations of push constants. The generated uniforms from OCIO are not
densely packed in the UBO to avoid complexity. Another approach would be to
use GPU_uniformbuf_create_from_list but this requires converting uniforms
to GPUInputs which is too complex for what it is.

Reviewed by: brecht, jbakker

Differential Revision: https://developer.blender.org/D14123
2022-02-18 22:30:45 +01:00
Clément Foucault e81dda4f38 Merge branch 'blender-v3.1-release'
# Conflicts:
#	intern/opencolorio/ocio_shader_shared.hh
2022-02-18 22:29:31 +01:00