Skip to content

Commit

Permalink
Merge remote-tracking branch 'b/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
youle31 committed Apr 15, 2024
2 parents e20bf8f + b38f27a commit 44d4c37
Show file tree
Hide file tree
Showing 208 changed files with 19,126 additions and 10,350 deletions.
4 changes: 2 additions & 2 deletions intern/cycles/blender/addon/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,8 +2090,8 @@ def draw(self, context):

sub = col.column(align=True)
sub.prop(cbk, "normal_r", text="Swizzle R")
sub.prop(cbk, "normal_g", text="G")
sub.prop(cbk, "normal_b", text="B")
sub.prop(cbk, "normal_g", text="G", text_ctxt=i18n_contexts.color)
sub.prop(cbk, "normal_b", text="B", text_ctxt=i18n_contexts.color)

elif cscene.bake_type == 'COMBINED':

Expand Down
14 changes: 10 additions & 4 deletions intern/cycles/blender/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,21 @@ void BlenderSession::render(BL::Depsgraph &b_depsgraph_)
height,
&python_thread_state,
session_params.device);

/* At the moment we only free if we are not doing multi-view
* (or if we are rendering the last view). See #58142/D4239 for discussion.
*/
const bool can_free_cache = (view_index == num_views - 1);
if (can_free_cache) {
sync->free_data_after_sync(b_depsgraph);
}

builtin_images_load();

/* Attempt to free all data which is held by Blender side, since at this
* point we know that we've got everything to render current view layer.
*/
/* At the moment we only free if we are not doing multi-view
* (or if we are rendering the last view). See #58142/D4239 for discussion.
*/
if (view_index == num_views - 1) {
if (can_free_cache) {
free_blender_memory_if_possible();
}

Expand Down
2 changes: 0 additions & 2 deletions intern/cycles/blender/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ void BlenderSync::sync_data(BL::RenderSettings &b_render,
* false = don't delete unused shaders, not supported. */
shader_map.post_sync(false);

free_data_after_sync(b_depsgraph);

VLOG_INFO << "Total time spent synchronizing data: " << timer.get_time();

has_updates_ = false;
Expand Down
6 changes: 3 additions & 3 deletions intern/cycles/blender/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class BlenderSync {
return view_layer.bound_samples;
}

/* Early data free. */
void free_data_after_sync(BL::Depsgraph &b_depsgraph);

/* get parameters */
static SceneParams get_scene_params(BL::Scene &b_scene,
const bool background,
Expand Down Expand Up @@ -208,9 +211,6 @@ class BlenderSync {
/* Images. */
void sync_images();

/* Early data free. */
void free_data_after_sync(BL::Depsgraph &b_depsgraph);

/* util */
void find_shader(BL::ID &id, array<Node *> &used_shaders, Shader *default_shader);
bool BKE_object_is_modified(BL::Object &b_ob);
Expand Down
4 changes: 2 additions & 2 deletions intern/cycles/device/cuda/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ bool CUDADevice::check_peer_access(Device *peer_device)
{
const CUDAContextScope scope(this);
CUresult result = cuCtxEnablePeerAccess(peer_device_cuda->cuContext, 0);
if (result != CUDA_SUCCESS) {
if (result != CUDA_SUCCESS && result != CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED) {
set_error(string_printf("Failed to enable peer access on CUDA context (%s)",
cuewErrorString(result)));
return false;
Expand All @@ -196,7 +196,7 @@ bool CUDADevice::check_peer_access(Device *peer_device)
{
const CUDAContextScope scope(peer_device_cuda);
CUresult result = cuCtxEnablePeerAccess(cuContext, 0);
if (result != CUDA_SUCCESS) {
if (result != CUDA_SUCCESS && result != CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED) {
set_error(string_printf("Failed to enable peer access on CUDA context (%s)",
cuewErrorString(result)));
return false;
Expand Down
8 changes: 2 additions & 6 deletions intern/cycles/device/metal/device.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ void device_metal_info(vector<DeviceInfo> &devices)
if (@available(macos 14.0, *)) {
info.use_hardware_raytracing = device.supportsRaytracing;

info.use_metalrt_by_default = false;
if (vendor == METAL_GPU_APPLE) {
/* Use hardware raytracing for faster rendering on architectures that support it. */
info.use_metalrt_by_default = (MetalInfo::get_apple_gpu_architecture(device) >=
APPLE_M3);
}
/* Use hardware raytracing for faster rendering on architectures that support it. */
info.use_metalrt_by_default = (MetalInfo::get_apple_gpu_architecture(device) >= APPLE_M3);
}
}
# endif
Expand Down
4 changes: 4 additions & 0 deletions intern/cycles/device/metal/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ enum MetalGPUVendor {
};

enum AppleGPUArchitecture {
/* NOT_APPLE_GPU represents AMD/Intel GPUs. This should remained at the start of this enum to
* ensure that AMD/Intel GPUs don't accidentally get Apple Silicon only features enabled when
* using comparison operators. */
NOT_APPLE_GPU,
APPLE_M1,
APPLE_M2,
APPLE_M2_BIG,
Expand Down
4 changes: 4 additions & 0 deletions intern/cycles/device/metal/util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@

AppleGPUArchitecture MetalInfo::get_apple_gpu_architecture(id<MTLDevice> device)
{
if (MetalInfo::get_device_vendor(device) != METAL_GPU_APPLE) {
return NOT_APPLE_GPU;
}

const char *device_name = [device.name UTF8String];
if (strstr(device_name, "M1")) {
return APPLE_M1;
Expand Down
4 changes: 2 additions & 2 deletions intern/ghost/intern/GHOST_SystemWayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3880,7 +3880,7 @@ static void pointer_handle_frame(void *data, wl_pointer * /*wl_pointer*/)
if (wl_surface *wl_surface_focus = seat->pointer.wl.surface_window) {
GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus);
seat->system->pushEvent_maybe_pending(
new GHOST_EventWheel(event_ms, win, seat->pointer_scroll.discrete_xy[1]));
new GHOST_EventWheel(event_ms, win, -seat->pointer_scroll.discrete_xy[1]));
}
}
seat->pointer_scroll.discrete_xy[0] = 0;
Expand Down Expand Up @@ -4673,7 +4673,7 @@ static void tablet_tool_handle_frame(void *data,
}
case GWL_TabletTool_EventTypes::Wheel: {
seat->system->pushEvent_maybe_pending(
new GHOST_EventWheel(event_ms, win, tablet_tool->frame_pending.wheel.clicks));
new GHOST_EventWheel(event_ms, win, -tablet_tool->frame_pending.wheel.clicks));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion intern/guardedalloc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(INC_SYS

set(SRC
./intern/leak_detector.cc
./intern/mallocn.c
./intern/mallocn.cc
./intern/mallocn_guarded_impl.cc
./intern/mallocn_lockfree_impl.cc
./intern/memory_usage.cc
Expand Down
22 changes: 13 additions & 9 deletions intern/guardedalloc/MEM_guardedalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ extern void *(*MEM_mallocN_aligned)(size_t len,
const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3);

/**
* Allocate an aligned block of memory that is initialized with zeros.
*/
extern void *(*MEM_calloc_arrayN_aligned)(
size_t len,
size_t size,
size_t alignment,
const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1, 2)
ATTR_NONNULL(4);

/**
* Print a list of the names and sizes of all allocated memory
* blocks. as a python dict for easy investigation.
Expand Down Expand Up @@ -311,14 +321,7 @@ template<typename T> inline void MEM_delete(const T *ptr)
template<typename T> inline T *MEM_cnew(const char *allocation_name)
{
static_assert(std::is_trivial_v<T>, "For non-trivial types, MEM_new should be used.");
if (alignof(T) <= MEM_MIN_CPP_ALIGNMENT) {
return static_cast<T *>(MEM_callocN(sizeof(T), allocation_name));
}
void *ptr = MEM_mallocN_aligned(sizeof(T), alignof(T), allocation_name);
if (ptr) {
memset(ptr, 0, sizeof(T));
}
return static_cast<T *>(ptr);
return static_cast<T *>(MEM_calloc_arrayN_aligned(1, sizeof(T), alignof(T), allocation_name));
}

/**
Expand All @@ -327,7 +330,8 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name)
template<typename T> inline T *MEM_cnew_array(const size_t length, const char *allocation_name)
{
static_assert(std::is_trivial_v<T>, "For non-trivial types, MEM_new should be used.");
return static_cast<T *>(MEM_calloc_arrayN(length, sizeof(T), allocation_name));
return static_cast<T *>(
MEM_calloc_arrayN_aligned(length, sizeof(T), alignof(T), allocation_name));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* to ensure strict conversions */
#include "../../source/blender/blenlib/BLI_strict_flags.h"

#include <assert.h>
#include <cassert>

#include "mallocn_intern.h"

Expand All @@ -38,6 +38,10 @@ void *(*MEM_malloc_arrayN)(size_t len, size_t size, const char *str) = MEM_lockf
void *(*MEM_mallocN_aligned)(size_t len,
size_t alignment,
const char *str) = MEM_lockfree_mallocN_aligned;
void *(*MEM_calloc_arrayN_aligned)(size_t len,
size_t size,
size_t alignment,
const char *str) = MEM_lockfree_calloc_arrayN_aligned;
void (*MEM_printmemlist_pydict)(void) = MEM_lockfree_printmemlist_pydict;
void (*MEM_printmemlist)(void) = MEM_lockfree_printmemlist;
void (*MEM_callbackmemlist)(void (*func)(void *)) = MEM_lockfree_callbackmemlist;
Expand Down Expand Up @@ -120,6 +124,7 @@ void MEM_use_lockfree_allocator(void)
MEM_mallocN = MEM_lockfree_mallocN;
MEM_malloc_arrayN = MEM_lockfree_malloc_arrayN;
MEM_mallocN_aligned = MEM_lockfree_mallocN_aligned;
MEM_calloc_arrayN_aligned = MEM_lockfree_calloc_arrayN_aligned;
MEM_printmemlist_pydict = MEM_lockfree_printmemlist_pydict;
MEM_printmemlist = MEM_lockfree_printmemlist;
MEM_callbackmemlist = MEM_lockfree_callbackmemlist;
Expand Down Expand Up @@ -154,6 +159,7 @@ void MEM_use_guarded_allocator(void)
MEM_mallocN = MEM_guarded_mallocN;
MEM_malloc_arrayN = MEM_guarded_malloc_arrayN;
MEM_mallocN_aligned = MEM_guarded_mallocN_aligned;
MEM_calloc_arrayN_aligned = MEM_guarded_calloc_arrayN_aligned;
MEM_printmemlist_pydict = MEM_guarded_printmemlist_pydict;
MEM_printmemlist = MEM_guarded_printmemlist;
MEM_callbackmemlist = MEM_guarded_callbackmemlist;
Expand Down
30 changes: 30 additions & 0 deletions intern/guardedalloc/intern/mallocn_guarded_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,36 @@ void *MEM_guarded_calloc_arrayN(size_t len, size_t size, const char *str)
return MEM_guarded_callocN(total_size, str);
}

void *MEM_guarded_calloc_arrayN_aligned(const size_t len,
const size_t size,
const size_t alignment,
const char *str)
{
size_t bytes_num;
if (UNLIKELY(!MEM_size_safe_multiply(len, size, &bytes_num))) {
print_error(
"Calloc array aborted due to integer overflow: "
"len=" SIZET_FORMAT "x" SIZET_FORMAT " in %s, total " SIZET_FORMAT "\n",
SIZET_ARG(len),
SIZET_ARG(size),
str,
mem_in_use);
abort();
return nullptr;
}
if (alignment <= MEM_MIN_CPP_ALIGNMENT) {
return MEM_callocN(bytes_num, str);
}
/* There is no lower level #calloc with an alignment parameter, so we have to fallback to using
* #memset unfortunately. */
void *ptr = MEM_mallocN_aligned(bytes_num, alignment, str);
if (!ptr) {
return nullptr;
}
memset(ptr, 0, bytes_num);
return ptr;
}

/* Memory statistics print */
typedef struct MemPrintBlock {
const char *name;
Expand Down
7 changes: 7 additions & 0 deletions intern/guardedalloc/intern/mallocn_intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ void *MEM_lockfree_mallocN_aligned(size_t len,
size_t alignment,
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3);
void *MEM_lockfree_calloc_arrayN_aligned(size_t len,
size_t size,
size_t alignment,
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1, 2) ATTR_NONNULL(4);
void MEM_lockfree_printmemlist_pydict(void);
void MEM_lockfree_printmemlist(void);
void MEM_lockfree_callbackmemlist(void (*func)(void *));
Expand Down Expand Up @@ -202,6 +207,8 @@ void *MEM_guarded_mallocN_aligned(size_t len,
size_t alignment,
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3);
void *MEM_guarded_calloc_arrayN_aligned(size_t len, size_t size, size_t alignment, const char *str)
ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1, 2) ATTR_NONNULL(4);
void MEM_guarded_printmemlist_pydict(void);
void MEM_guarded_printmemlist(void);
void MEM_guarded_callbackmemlist(void (*func)(void *));
Expand Down
30 changes: 30 additions & 0 deletions intern/guardedalloc/intern/mallocn_lockfree_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,36 @@ void *MEM_lockfree_mallocN_aligned(size_t len, size_t alignment, const char *str
return nullptr;
}

void *MEM_lockfree_calloc_arrayN_aligned(const size_t len,
const size_t size,
const size_t alignment,
const char *str)
{
size_t bytes_num;
if (UNLIKELY(!MEM_size_safe_multiply(len, size, &bytes_num))) {
print_error(
"Calloc array aborted due to integer overflow: "
"len=" SIZET_FORMAT "x" SIZET_FORMAT " in %s, total " SIZET_FORMAT "\n",
SIZET_ARG(len),
SIZET_ARG(size),
str,
memory_usage_current());
abort();
return nullptr;
}
if (alignment <= MEM_MIN_CPP_ALIGNMENT) {
return MEM_callocN(bytes_num, str);
}
/* There is no lower level #calloc with an alignment parameter, so we have to fallback to using
* #memset unfortunately. */
void *ptr = MEM_mallocN_aligned(bytes_num, alignment, str);
if (!ptr) {
return nullptr;
}
memset(ptr, 0, bytes_num);
return ptr;
}

void MEM_lockfree_printmemlist_pydict() {}

void MEM_lockfree_printmemlist() {}
Expand Down
2 changes: 1 addition & 1 deletion locale/po/ab.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

msgid ""
msgstr ""
"Project-Id-Version: Blender 4.2.0 Alpha (b'cb66cc3028dd')\n"
"Project-Id-Version: Blender 4.2.0 Alpha (b'c30667711948')\n"
"Report-Msgid-Bugs-To: \n"
"\"POT-Creation-Date: 2019-02-25 20:41:30\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
Expand Down

0 comments on commit 44d4c37

Please sign in to comment.