Commit Graph

231 Commits

Author SHA1 Message Date
Campbell Barton 52acf6a6ec Cleanup: correct file names in comments after C -> C++ renaming
Use back-tick quotes to differentiate these from plain text.
2023-07-31 13:02:30 +10:00
Campbell Barton 724755879e Cleanup: spelling in comments, use doxygen doc-strings 2023-07-31 10:18:09 +10:00
Sergey Sharybin d579ac2b3f Refactor: Use ImBuf to store passes in RenderResult
Doing so avoids having duplicated logic for working with pixel
data which is being passed throughout the render pipeline.

Notable changes:

- ImBug can now store GPU texture.
  This is not very finished part of the API, which will be
  worked further to support tiling for very-high-res images.

- Implicit sharing is removed from the image buffer, as it is
  no longer needed.

There should be no functional changes on user level with this
change.

Ref #108618

Pull Request: https://projects.blender.org/blender/blender/pulls/109788
2023-07-10 16:33:32 +02:00
Sergey Sharybin e1b60fdb91 Remove Z Buffer from ImBuf
It was only used by OpenEXR and Iris images, and saving the Z Buffer
in those formats was disabled by default. This option comes from the
times prior to the addition of the Multilayer EXR.

It also worth noting that it was not possible to save Iris with Depth
pass from Blender as internally it is called IRIZ format and it was
not exposed. But even after exposing this format option something still
was missing as saving and loading ITIZ did not show up the Depth pass.

The reason of removal is to make it a more clear match of the ImBuf
with a render pass, and use it instead of a custom type in the render
result and render pass API. This will simplify the API and also avoid
stealing buffers and making shallow copies when showing the render
result.

For the cases when Depth is needed a Multilayer EXR is to be used,
as most likely more than just the Depth will be needed.

On a user level this change:

- Removes the "Z Buffer" option from the interface.

- It preserves existing sockets in compositor nodes, but it will
  output black image. Also changing the image data-block will
  remove the socket unless a Multilayer EXR with Depth pass image
  is selected.

- Removes "Depth" socket of the Viewer and Composite nodes.

Ref #108618

Pull Request: https://projects.blender.org/blender/blender/pulls/109687
2023-07-04 17:03:02 +02:00
Guillermo Venegas 43a0f22be2 Cleanup: Move space sequencer files to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/108959
2023-06-14 18:36:17 +02:00
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Campbell Barton 393d4a6e14 Cleanup: duplicate words in comments
Also use doxygen-comments in files where this is already the convention.
2023-05-26 12:40:06 +10:00
Sergey Sharybin f669f6cd8c Fix #108243: Crash when save before close with modified image
A mistake in the recent API refactor for the buffer sharing.

Pull Request: https://projects.blender.org/blender/blender/pulls/108259
2023-05-25 09:59:23 +02:00
Sergey Sharybin a5677d225b Refactor Render Result to allow implicit buffer sharing
Allows to share buffer data between the render result and image buffers.

The storage of the passes and buffers in the render result have been
wrapped into utility structures, with functions to operate on them.

Currently only image buffers which are sharing buffers with the render
results are using the implicit sharing. This allows proper decoupling of
the image buffers from the lifetime of the underlying render result.

Fixes #107248: Compositor ACCESS VIOLATION when updating datablocks from handlers

Additionally, this lowers the memory usage of multi-layer EXR sequences
by avoiding having two copies of render passes in memory.

It is possible to use implicit sharing in more places, but needs
some API to ensure the render result is the only owner of data before
writing to its pixels.

Pull Request: https://projects.blender.org/blender/blender/pulls/108045
2023-05-23 09:19:37 +02:00
Sergey Sharybin 406cfd214a Refactor ImBuf buffer access
The goal is to make it more explicit and centralized operation to
assign and steal buffer data, with proper ownership tracking.

The buffers and ownership flags are wrapped into their dedicated
structures now.

There should be no functional changes currently, it is a preparation
for allowing implicit sharing of the ImBuf buffers. Additionally, in
the future it is possible to more buffer-specific information (such
as color space) next to the buffer data itself. It is also possible
to clean up the allocation flags (IB_rect, ...) to give them more
clear naming and not have stored in the ImBuf->flags as they are only
needed for allocation.

The most dangerous part of this change is the change of byte buffer
data from `int*` to `uint8_t*`. In a lot of cases the byte buffer was
cast to `uchar*`, so those casts are now gone. But some code is
operating on `int*` so now there are casts in there. In practice this
should be fine, since we only support 64bit platforms, so allocations
are aligned. The real things to watch out for here is the fact that
allocation and offsetting from the byte buffer now need an explicit 4
channel multiplier.

Once everything is C++ it will be possible to simplify public
functions even further.

Pull Request: https://projects.blender.org/blender/blender/pulls/107609
2023-05-18 10:19:01 +02:00
Campbell Barton 6b9a500a3a Cleanup: disambiguate terms "name", "file" & "str" / "string"
- Rename name/filename/path to filepath when it's used for full paths.
- Rename name/path to dirpath when it refers to a directory.
- Rename file to filepath or path (when it may be a file or dir).
- Rename ImBuf::name & anim::name to filepath.
2023-05-03 15:26:14 +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
Chris Blackbourn 254e3e133f Cleanup: format 2023-03-15 18:24:34 +13:00
Jesse Yurkovich 8929ed75d4 Image: Add OIIO support APIs
This adds a new set of APIs supporting the loading and saving of image
formats through OIIO. It makes use of the recent IOProxy work in OIIO
to align with the existing Blender image loading/saving machinery.

The support code here has been prototyped to work with ~7 of our image
formats so far. It includes centralized handling of `IB_test`,
`IB_mem`, and `IB_metadata` flags, which the existing code did not
handle consistently or at all depending on the format.

The PSD format (`format_psd.cc`) is included since the prior location
of the code has been restructured away. It serves as an example of how
the loading code typically flows for all the other formats.

Pull Request: https://projects.blender.org/blender/blender/pulls/105519
2023-03-14 04:42:17 +01:00
Jeroen Bakker f210842a72 Sequencer: Improve Image Transform Quality When Exporting.
Image Transform use linear or nearest sampling during editing and exporting.
This gets sampling is fine for images that aren't scaled. When sequencing
however you mostly want use some sort of scaling, that leads to poorer
quality.

This change will use sub-sampling to improve the quality. This is only
enabled when rendering. During editing the subsampling is disabled to
keep the user interface reacting as expected.

Another improvement is that image transform is stopped at the moment
it hadn't sampled at least 4 samples for a scan line. In that case we
expect that there are no further samples that would change to result.

In a future patch this could be replaced by a ray/bounding bo intersection
as that would remove some unneeded loops in both the single sampled and
sub sampled approach.
2023-01-26 14:25:49 +01:00
Jesse Yurkovich 38573d515e Cleanup: Remove unused IMB tile cache code
This removes the unused code for the IBM tile cache APIs.  These have
been unused for as far back as I could manage to search.

Since TIFF was used for the cached images, this removal will allow for
an easier review when it comes time to move TIFF to OIIO as part of
T101413.

Differential Revision: https://developer.blender.org/D16587
2022-11-23 19:31:10 -08:00
Campbell Barton ae3073323e Cleanup: use bool instead of short for job stop & do_update arguments
Since these values are only ever 0/1, use bool type.
2022-11-05 13:47:01 +11:00
Jeroen Bakker 872a45f42b ImageEngine: Clamp image data to fit half float range.
When image data exceeds half float ranges values are set to +/-
infinity that could lead to artifacts later on in the pipeline.
Color management for example.

This patch adds a utility function `IMB_gpu_clamp_half_float`
that clamps full float values to fit within the range of
half floats.

This fixes T98575 and T101601.
2022-10-12 08:56:14 +02:00
Brecht Van Lommel bc15c83afa Fix T100886: error saving side-by-side stereo EXR image of depth pass
The stereo saving code that combines two image buffers into one did not work
correctly when the number of channels is not equal to 4.
2022-09-12 20:21:13 +02:00
Jeroen Bakker 37533cd6cb ImBuf: Optimize GPU memory by using 1 component format for grayscale images
This is done by checking the number of bitplanes from the image buffer.
We assume that for float buffer to use the same bitplanes as it was a
byte buffer.

Then, the data of the image buffer is packed at the start of the `rect` or
`float_rect` before upload.

**Statistics - einar.v004.blend **

Note that not all grayscale textures have been stored as BW images so the
amount of memory that can be reduced would be more.

Without patch
```
104 Textures - 3294.99 MB (3294.47 MB over 32x32), 37 RTs - 192.52 MB.
Avg. tex dimension: 2201.88x1253.51 (2283.53x2202.13 over 32x32)
464 Buffers - 25.01 MB total 1.24 MB IBs 23.50 MB VBs.
3512.52 MB - Grand total GPU buffer + texture load
```

Patch applied
```
104 Textures - 2917.66 MB (2917.14 MB over 32x32), 39 RTs - 215.45 MB.
Avg. tex dimension: 2221.38x1252.75 (2323.28x2253.47 over 32x32)
467 Buffers - 25.01 MB total 1.24 MB IBs 23.51 MB VBs.
3158.13 MB - Grand total GPU buffer + texture load.
```

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D15484
2022-08-23 14:35:39 +02:00
Campbell Barton 1f2a5fea87 Cleanup: strip blank lines around comment blocks 2022-08-17 12:51:07 +10:00
Angus Stanton ea70687dd5 Image: Display GPU layout in `uiTemplateImageInfo`
Add IMB_gpu_get_texture_format and GPU_texture_format_description to
retrieve and 'stringify' an eGPUTextureFormat. These are then used in the
image info panel used in several areas across blender.

New Information:
{F13330937}

Reviewed By: jbakker

Maniphest Tasks: T99998

Differential Revision: https://developer.blender.org/D15575
2022-08-03 08:15:12 +02:00
Jeroen Bakker f41c7723c9 GPU: Remove cached full/scaled image texture.
full scaled image isn't used anymore. It was added to use a different scale when
displaying an image in the image editor. This was replaced by the image engine
redesign.

This change will reduce complexity of {T98375}.
2022-05-27 10:52:49 +02:00
Brecht Van Lommel 906b9f55af Cleanup: remove redundant float to byte conversion for stereo image saving
For non-stereo cases this is automatically handled by IMB_saveiff, no reason for
stereo to do this separately.

Ref D14899
2022-05-12 22:58:27 +02:00
Harley Acheson 8960c6e060 IMBUF: Faster JPEG Thumbnails
Make preview thumbnails of JPEG files in less time and with less RAM.

See D14727 for more details.

Differential Revision: https://developer.blender.org/D14727

Reviewed by Brecht Van Lommel
2022-05-04 16:55:59 -07:00
Brecht Van Lommel 8530e48f86 Cleanup: move render image and multilayer EXR write code to image_save.cc
These share a lot of logic with regular image saving and should be unified
more in the future.
2022-03-21 16:38:13 +01:00
Campbell Barton aa500c4fca Cleanup: use back-slash for doxygen commands, color after parameters 2022-03-02 12:11:08 +11:00
Jacques Lucke 4b9c77a19a Merge branch 'blender-v3.1-release' 2022-03-01 11:36:46 +01:00
Jeroen Bakker 5e9c1feb8a Image Engine: Performance 8 byte images.
Previously we used to cache a float image representation of the image in
rect_float. This adds some incorrect behavior as many areas only expect
one of these buffers to be used.

This patch stores float buffers inside the image engine. This is done per
instance. In the future we should consider making a global cache.
2022-03-01 08:41:25 +01:00
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Richard Antalik b45e71e22c VSE: Build proxies only for slow movies
This change applies only for automatic proxy building, when strip
is added to timeline. Manual building process is not affected.

Don't build proxy file if movie is already fast enough to seek.
To determine seek performance, check if whole GOP can be decoded
in 100 milliseconds.

To consider some variation in GOP size, large number of packets are
read, assuming that each packet will produce 1 frame. While this is not
technically correct, it does give quite accurate estimate of maximum GOP
size.

This test will ensure consistent performance on wide array of machines.
Check should be done in order of few milliseconds.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D11671
2022-01-25 22:06:46 +01:00
Clément Foucault fb6bd88644 Revert "BLI: Refactor vector types & functions to use templates"
Includes unwanted changes

This reverts commit 46e049d0ce.
2022-01-12 12:50:02 +01:00
Clment Foucault 46e049d0ce BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:`float2`) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the `blender::math` namespace) and are not vector size
dependent for the most part.

In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.

####Motivations:
 - We are aiming to share UBO and SSBO structures between GLSL and C++.
 This means we will use many of the existing vector types and others
 we currently don't have (uintX, intX). All these variations were
 asking for many more code duplication.
 - Deduplicate existing code which is duplicated for each vector size.
 - We also want to share small functions. Which means that vector
 functions should be static and not in the class namespace.
 - Reduce friction to use these types in new projects due to their
 incompleteness.
 - The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a
 bit of a let down. Most clases are incomplete, out of sync with each
 others with different codestyles, and some functions that should be
 static are not (i.e: `float3::reflect()`).

####Upsides:
 - Still support `.x, .y, .z, .w` for readability.
 - Compact, readable and easilly extendable.
 - All of the vector functions are available for all the vectors types
 and can be restricted to certain types. Also template specialization
 let us define exception for special class (like mpq).
 - With optimization ON, the compiler unroll the loops and performance
 is the same.

####Downsides:
 - Might impact debugability. Though I would arge that the bugs are
 rarelly caused by the vector class itself (since the operations are
 quite trivial) but by the type conversions.
 - Might impact compile time. I did not saw a significant impact since
 the usage is not really widespread.
 - Functions needs to be rewritten to support arbitrary vector length.
 For instance, one can't call `len_squared_v3v3` in
 `math::length_squared()` and call it a day.
 - Type cast does not work with the template version of the `math::`
 vector functions. Meaning you need to manually cast `float *` and
 `(float *)[3]` to `float3` for the function calls.
 i.e: `math::distance_squared(float3(nearest.co), positions[i]);`
 - Some parts might loose in readability:
 `float3::dot(v1.normalized(), v2.normalized())`
 becoming
 `math::dot(math::normalize(v1), math::normalize(v2))`
 But I propose, when appropriate, to use
 `using namespace blender::math;` on function local or file scope to
 increase readability.
 `dot(normalize(v1), normalize(v2))`

####Consideration:
 - Include back `.length()` method. It is quite handy and is more C++
 oriented.
 - I considered the GLM library as a candidate for replacement. It felt
 like too much for what we need and would be difficult to extend / modify
 to our needs.
 - I used Macros to reduce code in operators declaration and potential
 copy paste bugs. This could reduce debugability and could be reverted.
 - This touches `delaunay_2d.cc` and the intersection code. I would like
 to know @howardt opinion on the matter.
 - The `noexcept` on the copy constructor of `mpq(2|3)` is being removed.
 But according to @JacquesLucke it is not a real problem for now.

I would like to give a huge thanks to @JacquesLucke who helped during this
and pushed me to reduce the duplication further.

Reviewed By: brecht, sergey, JacquesLucke

Differential Revision: https://developer.blender.org/D13791
2022-01-12 12:47:43 +01:00
Clément Foucault e5766752d0 Revert "BLI: Refactor vector types & functions to use templates"
Reverted because the commit removes a lot of commits.

This reverts commit a2c1c368af.
2022-01-12 12:44:26 +01:00
Clément Foucault a2c1c368af BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:float2) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the blender::math namespace) and are not vector size
dependent for the most part.

In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.

Motivations:
- We are aiming to share UBO and SSBO structures between GLSL and C++.
  This means we will use many of the existing vector types and others we
  currently don't have (uintX, intX). All these variations were asking
  for many more code duplication.
- Deduplicate existing code which is duplicated for each vector size.
- We also want to share small functions. Which means that vector functions
  should be static and not in the class namespace.
- Reduce friction to use these types in new projects due to their
  incompleteness.
- The current state of the BLI_(float|double|mpq)(2|3|4).hh is a bit of a
  let down. Most clases are incomplete, out of sync with each others with
  different codestyles, and some functions that should be static are not
  (i.e: float3::reflect()).

Upsides:
- Still support .x, .y, .z, .w for readability.
- Compact, readable and easilly extendable.
- All of the vector functions are available for all the vectors types and
  can be restricted to certain types. Also template specialization let us
  define exception for special class (like mpq).
- With optimization ON, the compiler unroll the loops and performance is
  the same.

Downsides:
- Might impact debugability. Though I would arge that the bugs are rarelly
  caused by the vector class itself (since the operations are quite trivial)
  but by the type conversions.
- Might impact compile time. I did not saw a significant impact since the
  usage is not really widespread.
- Functions needs to be rewritten to support arbitrary vector length. For
  instance, one can't call len_squared_v3v3 in math::length_squared() and
  call it a day.
- Type cast does not work with the template version of the math:: vector
  functions. Meaning you need to manually cast float * and (float *)[3] to
  float3 for the function calls.
  i.e: math::distance_squared(float3(nearest.co), positions[i]);
- Some parts might loose in readability:
  float3::dot(v1.normalized(), v2.normalized())
  becoming
  math::dot(math::normalize(v1), math::normalize(v2))
  But I propose, when appropriate, to use
  using namespace blender::math; on function local or file scope to
  increase readability. dot(normalize(v1), normalize(v2))

Consideration:
- Include back .length() method. It is quite handy and is more C++
  oriented.
- I considered the GLM library as a candidate for replacement.
  It felt like too much for what we need and would be difficult to
  extend / modify to our needs.
- I used Macros to reduce code in operators declaration and potential
  copy paste bugs. This could reduce debugability and could be reverted.
- This touches delaunay_2d.cc and the intersection code. I would like to
  know @Howard Trickey (howardt) opinion on the matter.
- The noexcept on the copy constructor of mpq(2|3) is being removed.
  But according to @Jacques Lucke (JacquesLucke) it is not a real problem
  for now.

I would like to give a huge thanks to @Jacques Lucke (JacquesLucke) who
helped during this and pushed me to reduce the duplication further.

Reviewed By: brecht, sergey, JacquesLucke

Differential Revision: http://developer.blender.org/D13791
2022-01-12 12:19:39 +01:00
Campbell Barton 0dc309bef6 Cleanup: remove redundant const qualifiers for POD types 2022-01-12 12:51:11 +11:00
Campbell Barton 3d3bc74884 Cleanup: remove redundant const qualifiers for POD types
MSVC used to warn about const mismatch for arguments passed by value.
Remove these as newer versions of MSVC no longer show this warning.
2022-01-07 14:16:26 +11:00
Campbell Barton 4b12f521e3 Cleanup: spelling 2021-12-16 11:38:09 +11:00
Jeroen Bakker 6051b80dd2 Cleanup: Use pixel in stead of texels in naming. 2021-12-15 11:19:29 +01:00
Jeroen Bakker 723fb16343 Images: 1,2,3 channel support for transform function.
Added support for 1, 2, 3 float channel source images. Destination
images must still be 4 channels.
2021-12-15 11:09:31 +01:00
Campbell Barton a207c1cdaf Cleanup: resolve parameter mis-matches in doc-strings
Renamed or removed parameters which no longer exist.
2021-12-14 18:35:23 +11:00
Jeroen Bakker fcf8fc3eaa Fix Crash: Loading Huge Images.
When loading huge images (30k) blender crashed with a buffer overflow.
The reason is that determine the length of a buffer was done in 32bit
precision and afterwards stored in 64 bit precision.

This patch adds a new function to do the correct calculation in 64bit.
It should be added to other sections in blender as well. But that should
be tested on a per case situation.
2021-12-10 10:37:46 +01:00
Campbell Barton 8ef8f3a60a Cleanup: spelling in comments 2021-12-09 20:21:26 +11:00
Campbell Barton 9f546d6908 Cleanup: move public doc-strings into headers for 'imbuf'
Ref T92709
2021-12-09 20:01:45 +11:00
Jeroen Bakker ca0c9757f2 Cleanup: moved IMB_transform to transform.cc.
Part of a refactoring to make IMB_transform more generic to reduce
unneeded branching.
2021-12-08 09:54:52 +01:00
Jeroen Bakker ab927f5ca7 ImBuf: Made Wrapping and Cropping optional in IMB_transform.
`IMB_transform` is used in VSE. It had a required crop parameter
for cropping the source buffer. This is not always needed.

In the image engine we want to use the use the `IMB_transform`
with wrap repeat. Both options are mutual exclusive and due
to performance reasons the wrap repeat is only available when
performing a nearest interpolation.
2021-12-03 13:48:00 +01:00
Richard Antalik e11b33fec3 Remove math for 2D affine transform
Commit e1665c3d31 added math to do 2D affine transformations with 3x3
matrices, but these matrices are also used for 3D transformations.

Remove added functions and use 4x4 matrices for 2D transformation.

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D12510
2021-10-15 23:20:45 +02:00
Campbell Barton 687f70ceca ImBuf: add IMB_allocFromBufferOwn that takes ownership of the buffer
Avoids duplicating the image buffer when saving thumbnails.
2021-09-06 20:05:58 +10:00
Sebastian Parborg ded68fb102 VSE: Fix audaspace not reading ffmpeg files with start offset correctly
The duration and start time for audio strips were not correctly read in
audaspace.

Some video files have a "lead in" section of audio that plays before the
video starts playing back. Before this patch, we would play this lead in
audio at the same time as the video started and thus the audio would not
be in sync anymore.

Now the lead in audio is cut off and the duration should be correctly
calculated with this in mind.

If the audio starts after the video, the audio strip is shifted to
account for this, but it will also lead to cut off audio which might not
be wanted. However we don't have a simple way to solve this at this
point.

Differential Revision: http://developer.blender.org/D11917
2021-08-16 15:10:58 +02:00
Campbell Barton 42017b006e Cleanup: sort struct declarations 2021-07-16 11:48:54 +10:00