Commit Graph

2432 Commits

Author SHA1 Message Date
Jeroen Bakker
bc6027ebaf Vulkan: Initial/Final Renderpass Layout
Until now the initial renderpass layout wasn't set, resulting
in errors/warnings when using the renderpass. This PR sets the
initial and final renderpass to general so the code knows what
to expect.

In future this needs to be designed better as the layout will
change when used in as a framebuffer attachment, or presenting
on the screen.

Pull Request: https://projects.blender.org/blender/blender/pulls/109000
2023-06-15 08:39:35 +02:00
Campbell Barton
49594c37ae License headers: use SPDX-FileCopyrightText for CMake files 2023-06-14 23:36:23 +10:00
Campbell Barton
a2c6371e3e License headers: use SPDX-FileCopyrightText in intern/ghost 2023-06-14 17:42:15 +10:00
Jeroen Bakker
2ee2ae93fb Vulkan: Initial Cube(Array) Support
This PR adds initial cube (array) support. Depending on how the texture
is used a different image view is created. When used as a framebuffer
attachment only a single side of the cubemap is attached. The image
view is attached as a 2d texture array. When used as a shader resource
the image view is a cubemap.

Also adds test cases to test both scenarios.

Pull Request: https://projects.blender.org/blender/blender/pulls/108794
2023-06-09 16:09:54 +02:00
Brecht Van Lommel
a2bd080cf3 Cleanup: renaming of GPU contexts for clarity
* opengl_context -> system_gpu_context. This is the operating system OpenGL,
  Metal or Vulkan context provided by GHOST.
* gpu_context -> blender_gpu_context. This is the GPUContext provided by
  the Blender GPU module, which wraps the GHOST context and adds some state.
* Various functions create/destroy/enable/disable both contexts, these have
  just gpu_context in the name now.

Pull Request: https://projects.blender.org/blender/blender/pulls/108723
2023-06-08 15:46:53 +02:00
Campbell Barton
989b5de8e9 Cleanup: remove unused window states, add doc-strings
Note that the GHOST_TWindowState is stored in DNA & that
values shouldn't be changed.
2023-06-08 10:32:00 +10:00
Campbell Barton
f31dfa9b74 Merge branch 'blender-v3.6-release' 2023-06-06 09:49:06 +10:00
Campbell Barton
dd1fe31a74 Cleanup: quiet compiler warnings 2023-06-06 09:34:50 +10:00
Campbell Barton
e27bcb6e3e Cleanup: remove redundant struct qualifier 2023-06-04 19:27:38 +10:00
Campbell Barton
b2950b2ad7 Fix saving a quit.blend on exit when a file failed to load
When a file passed in from the command line failed to load,
blender would exit & save the quit.blend.

Resolve by adding a `do_user_exit_actions` to WM_exit_ex which is
false in backgrounds mode or when an error has occurred.

---

Back-ported [0] & [1] from main with fix [2] included.

[0]: c803ddab29451addcf6378dea8c062b13c507d72
[1]: d7d1c524e3dc1ac17577bb262ec033db8ae1b8f3
[2]: d3d91b79e0a7d4c083dfb627b3e715fb293efc21
2023-05-31 12:35:22 +10:00
Harley Acheson
de10126b1f Fix: Build Warning of Unused Variable
Removing unused variable in GHOST_SystemWin32.cc

Own code, introduced in #108397
2023-05-30 08:54:28 -07:00
Campbell Barton
d7d1c524e3 Cleanup: pass the exit-code to WM_exit
Callers to WM_exit needed to set G.is_break for a predictable exit-code.
This is error prone as G.is_break may be set based on the user having
pressed escape during event handling.

Instead, pass the exit code as an argument.
2023-05-30 12:55:10 +10:00
Harley Acheson
c3b58b5f67 Fix #108356: Group Console with App on Taskbar
Set App Id for the process so our console is grouped on the Task Bar.

Pull Request: https://projects.blender.org/blender/blender/pulls/108397
2023-05-29 23:19:12 +02:00
Harley Acheson
e99a2fb61c Merge branch 'blender-v3.6-release' 2023-05-27 18:45:35 -07:00
Harley Acheson
1b7c6cf150 Windows: Do not auto-focus from our console
Although auto-focus only works between a single Blender instance's
child windows, this does include our own console and we don't want
that. Luckily fixing this only requires a single check for null -
because GetFocus() returns null to us for our console.

Pull Request: https://projects.blender.org/blender/blender/pulls/108362
2023-05-28 03:42:13 +02:00
Christoph Lendenfeld
074abff87e Merge branch 'blender-v3.6-release' 2023-05-26 17:02:35 +02:00
Jason Fielder
9e83211b8d Fix: Implement shared Metal Command queue to resolve sync bugs
Previously, each GHOST Context instantiated its own Metal device
queue. Commands are only synchronized within a queue, this was the
root cause of a number of flickering issues which had previously
been worked-around with synchronization primitives.

New solution uses a shared queue to simplify dependencies and
alleviate possibility of stalls and bugs when resources are modified
or shared across separate GPU command queues.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/108223
2023-05-26 16:00:20 +02:00
Harley Acheson
9cf77efaa0 UI: Updated Windows File Registration
Windows file associations using ProgID, needed because of the launcher.
This fixes "pin to taskbar" and Recent Documents lists, allow per-
version jump lists and an "Open with" list with multiple versions.

Pull Request: https://projects.blender.org/blender/blender/pulls/107013
2023-05-24 21:19:56 +02:00
Campbell Barton
13c815085b Cleanup: spelling in comments 2023-05-24 11:21:18 +10:00
Jeroen Bakker
4997748e5e Vulkan: Select Compatible Render Surface
In previous implementation the first available render surface was
selected. For NVIDIA platform this was the correct one, but for
AMD and Intel GPUs this was incorrect. This PR goes over all the
available render surfaces and selects a compatible one.

For now when no compatible render surface is found it will still select
the first available one. With the expectation that the screen is drawn
incorrectly and users would report a bug so we can investigate.

Pull Request: https://projects.blender.org/blender/blender/pulls/108169
2023-05-23 11:03:53 +02:00
Sergey Sharybin
793446cbdc BLI: Replace some macros with inlined functions for C++
Covers the macro ARRAY_SIZE() and STRNCPY.

The problem this change is aimed to solve it to provide cross-platform
compiler-independent safe way pf ensuring that the functions are used
correctly.

The type safety was only ensured for GCC and only for C. The C++
language and Clang compiler would not have detected issues of passing
bare pointer to neither of those macros.

Now the STRNCPY() will only accept a bounded array as the destination
argument, on any compiler.

The ARRAY_SIZE as well, but there are a bit more complications to it
in terms of transparency of the change.

In one place the ARRAY_SIZE was used on float3 type. This worked in the
old code because the type implements subscript operator, and the type
consists of 3 floats. One would argue this is somewhat hidden/implicit
behavior, which better be avoided. So an in-lined value of 3 is used now
there.

Another place is the ARRAY_SIZE used to define a bounded array of the
size which matches bounded array which is a member of a struct. While
the ARRAY_SIZE provides proper size in this case, the compiler does not
believe that the value is known at compile time and errors out with a
message that construction of variable-size arrays is not supported.

Solved by converting the field to std::array<> and adding dedicated
utility to get size of std::array at compile time. There might be a
better way of achieving the same result, or maybe the approach is
fine and just need to find a better place for such utility.

Surely, more macro from the BLI_string.h can be covered with the C++
inlined functions, but need to start somewhere.

There are also quite some changes to ensure the C linkage is not
enforced by code which includes the headers.

Pull Request: https://projects.blender.org/blender/blender/pulls/108041
2023-05-23 09:21:45 +02:00
Campbell Barton
57f593b7ca Merge branch 'blender-v3.6-release' 2023-05-21 13:50:45 +10:00
Campbell Barton
047ff43ee4 Fix GHOST/Wayland configuring an XDG surface before it was handled
xdg_surface_ack_configure must run once the events have been handled
which is not the case configure runs from the event handling thread.

In practice this could lead to glitches resizing windows, although some
flickering on startup remains on KDE which would be good to resolve.
2023-05-21 13:47:56 +10:00
Campbell Barton
3a286a735f Merge branch 'blender-v3.6-release' 2023-05-19 19:56:20 +10:00
Campbell Barton
c007e6a346 Fix occasional crash on exit under Wayland
pthread_cancel was sometimes called once the thread had exited,
resolve this by having the function wait to be canceled.
2023-05-19 19:51:42 +10:00
Campbell Barton
9af19822f0 Merge branch 'blender-v3.6-release' 2023-05-19 16:27:42 +10:00
Campbell Barton
2ce7f3ec71 Fix crash on exit under Wayland with multiple windows open
Exiting with multiple overlapping windows (a file selector for e.g.)
reliably crashes.

Closing the windows on exit caused the the keyboard enter handler to be
called with a NULL window surface (wl_surface).

While this doesn't look to be documented anywhere, SDL's code-comments
note this happens when windows have just been closed.
GTK also check surfaces for NULL.
2023-05-19 16:25:56 +10:00
Campbell Barton
3db0bde21d Merge branch 'blender-v3.6-release' 2023-05-19 15:14:27 +10:00
Campbell Barton
2eaacbaa3f Fix memory leak on exit under GHOST/Wayland 2023-05-19 15:10:51 +10: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
a9358f5274 Fix Blender failing to start in Gnome when X11 isn't available
Only make libdecor a hard-requirement for using Wayland in gnome-shell
when X11 is available, as it's possible to disable Xwayland.

This also fixes window-borders not being used in gnome-shell when
WITH_GHOST_X11 is off.

Now it's possible to test Blender under gnome without libdecor by
uninstalling libdecor & running with DISPLAY environment variable
set to an empty string - useful for troubleshooting issues which
could be caused by libdecor.
2023-05-18 09:33:46 +10:00
Jeroen Bakker
b029db5461 Vulkan: AMD Swapchain
This PR enabled the swapchain to be used with AMD GPUs.
The issue is that we had to separate the swapchain into
2 functions and therefore the rendering is also not
controlled at the same time.

Semaphores were finished, before being used and the
driver stalled when waiting for those Semaphores.

This doesn't solve the issue that renderdoc can still
crash the graphics driver.

Pull Request: https://projects.blender.org/blender/blender/pulls/107840
2023-05-11 14:29:38 +02:00
Jeroen Bakker
6a20b0022c Vulkan: Swap Chain
This PR replaces the previous implementation of the swap chain.
The previous implementation was based on a gaming loop where
inside a single function an image is requested, the drawing occurs
and the requested image is presented on screen.

In blender the drawing isn't controlled in a single function and
this approach lead to freezes, missing frames and other
artifacts.

This approach is not be the final approach but a step into a
direction where the acquiring of the next image in the swap chain
is separated from the swapping.

Pull Request: https://projects.blender.org/blender/blender/pulls/107740
2023-05-11 12:51:05 +02:00
Jeroen Bakker
f428fd8229 Vulkan: Share Device Between Contexts
Previous GHOST_ContextVK would create a logical device for each
context. Blender uses multiple contexts at the same time and wasn't able
to share resources between them as the logical device where different.

This patch will create a single logical device and share them between
multiple contexts. This allows sharing memory/shaders between contexts
and make sure that all memory allocations are freed from the device it
was allocated from.

Some allocations in Blender are freed when there isn't a context, this
was failing in the previous implementation. We didn't noticed it before
as we didn't test multiple contexts.

This patch also moves device specific data structures from VKContext to
VKDevice like the descriptor pools, debug layers etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/107606
2023-05-04 10:06:48 +02:00
Campbell Barton
a0db0a5580 Cleanup: move comments wrapped with MultiLine control statements
In some cases comments at the end of control statements were wrapped
onto new lines which made it read as if they applied to the next line
instead of the (now) previous line.

Relocate comments to the previous line or in some cases the end of the
line (before the brace) to avoid confusion.

Note that in quite a few cases these blocks didn't read well
even before MultiLine was used as comments after the brace caused
wrapping across multiple lines in a way that didn't follow
formatting used everywhere else.
2023-05-02 09:54:48 +10:00
Campbell Barton
6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Campbell Barton
46316b29dc GHOST/Wayland: remove keyboard modifier mismatch warning suppression
Detecting when to show warnings about GHOST/XKB modifier
mismatches was rather involved, remove the check as it's
unnecessary for Gnome-Shell >= v43.

Older versions of Gnome-Shell will show warnings on window activation
with modifier keys held.
2023-05-01 11:57:45 +10:00
Campbell Barton
4efacf7e85 GHOST/Wayland: use GHOST modifiers, not XKB without an active windows
Reading modifiers from XKB caused a complications in getModifierKeys(..)
when called on a window that was activated, before the keyboard enter
handler had run - because the keys held by GHOST had not yet been
updated by XKB. This caused a problem which Gnome-shell which runs
the keyboard-enter handler after window activation.

This change would have fixed the Super key being stuck, see: #107314.
Keep the previous fix since in the unlikely case GHOST & XKB get out of
sync, stuck modifier keys should still be prevented.

This change means the warning for GHOST & XKB getting out of sync
can be enabled for Gnome-shell again, as it was previously suppressed
as it happened frequently on window activation.
2023-05-01 11:57:13 +10:00
Campbell Barton
7b8ba7f101 Fix #107314: OS key stuck when switching windows with GNOME/Wayland
Tapping the OS key to switch windows could cause the OS key to stick.

On window deactivation the OS key was considered held, activating the
window later read the XKB modifier state before the keyboard_enter &
keyboard_modifier callbacks had run.

When they ran later, the mis-match between XKB and GHOST was not taken
into account, causing the OS key to stick.
2023-04-28 16:06:37 +10:00
Jeroen Bakker
26147b29a7 Vulkan: Construct a Vulkan 1.2 Context.
Apparently we always constructed a Vulkan 1.0 Context, although we
are targetting Vulkan 1.2. This also lead to incorrect expectations
when using the Vulkan Memory allocator.

Pull Request: https://projects.blender.org/blender/blender/pulls/107300
2023-04-24 15:32:17 +02:00
AgAmemnno
bebb17a973 Vulkan: Provide Debug Utilities
This PR uses the VK_EXT_debug_utils extension, but it's only for labeling, so it doesn't rely on the VK_LAYER_KHRONOS_validation functionality.

The functions that do these things are loaded into the runtime as vulkan extensions.

Declare the function pointers in a struct and make them members of vk_context.

Pull Request: https://projects.blender.org/blender/blender/pulls/106098
2023-04-21 12:32:40 +02:00
Campbell Barton
54ce0ac922 Cleanup: use const variables when reading X11 events 2023-04-21 09:12:31 +10:00
Campbell Barton
62806012ed Cleanup: resolve uninitialized members in GHOST Window & SystemX11
While this didn't cause bugs, initialize members to avoid problems
in the future.

GHOST::SystemX11
- m_keyboard_vector
- m_keycode_last_repeat_key

GHOST::Window
- m_cursorGrabInitPos
- m_userData
2023-04-21 09:06:25 +10:00
Brecht Van Lommel
13d30b0481 Cleanup: fix various warnings on Windows
Ensure windows.h is included before some other headers to avoid
redefining macros.

Pull Request: https://projects.blender.org/blender/blender/pulls/107189
2023-04-20 20:46:13 +02:00
Ankit Meel
f04a7a07e3 macOS: Add open files to system recent files
Completes the TODO in GHOST_SystemPathsCocoa::addToSystemRecentFiles
Also renames the filename parameter to the more appropriate filepath.

The recently opened/saved file will now also show up in:
- Blender Dock icon > Right click.
- Three finger swipe down in Open Blender i.e., App Expose

Based on a earlier contribution by @jenkm.

Pull Request: https://projects.blender.org/blender/blender/pulls/107174
2023-04-20 23:53:08 +05:30
Campbell Barton
335d32153e Cleanup: remove dead code, reduce variable scope 2023-04-20 13:57:31 +10:00
Campbell Barton
62cc09f267 Cleanup: match argument names between functions & declarations 2023-04-20 13:52:58 +10:00
Campbell Barton
b132118f89 Cleanup: balance doxygen grouping, minor grouping adjustment 2023-04-19 09:02:21 +10:00
Mateusz Albecki
0fd14d659b GHOST/Wayland: Fix disposeContext with VK
During createOffscreenContext with VK backend enabled wl_surface
was not stored in the context's user data. This resulted in nullptr
dereference later on during disposeContext. Added a line that sets
user data and additionally added nullptr checks in disposeContext.

Ref !107057.
2023-04-19 07:44:06 +10:00
Dalai Felinto
664b31ea73 Cleanup: make format 2023-04-18 09:45:01 +02:00