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 Feb 14, 2025
2 parents e250de4 + f900995 commit 936e8d5
Show file tree
Hide file tree
Showing 475 changed files with 718 additions and 3,938 deletions.
16 changes: 16 additions & 0 deletions build_files/cmake/platform/platform_win32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ else()
endif()
endif()

set(WINDOWS_ARM64_MIN_VSCMD_VER 17.12.3)
# We have a minimum version of VSCMD for ARM64 (ie, the version the libs were compiled against)
# This checks for the version on initial run, and caches it, so users do not have to run the VS CMD window every time
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
set(VC_VSCMD_VER $ENV{VSCMD_VER} CACHE STRING "Version of the VSCMD initially run from")
mark_as_advanced(VC_VSCMD_VER)
set(VSCMD_VER ${VC_VSCMD_VER})
if(DEFINED VSCMD_VER)
if(VSCMD_VER VERSION_LESS WINDOWS_ARM64_MIN_VSCMD_VER)
message(FATAL_ERROR "Windows ARM64 requires VS2022 version ${WINDOWS_ARM64_MIN_VSCMD_VER} or greater - please update your VS2022 install!")
endif()
else()
message(FATAL_ERROR "Unable to detect the Visual Studio CMD version, try running from the visual studio developer prompt.")
endif()
endif()

if(WITH_BLENDER AND NOT WITH_PYTHON_MODULE)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT blender)
endif()
Expand Down
2 changes: 0 additions & 2 deletions intern/audaspace/intern/AUD_PyInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#include <python/PyAPI.h>
#include <python/PySound.h>

extern "C" {
extern void *BKE_sound_get_factory(void *sound);
}

static PyObject *AUD_getSoundFromPointer(PyObject *self, PyObject *args)
{
Expand Down
8 changes: 4 additions & 4 deletions intern/cycles/device/cuda/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ void CUDADevice::free_device(void *device_pointer)
cuda_assert(cuMemFree((CUdeviceptr)device_pointer));
}

bool CUDADevice::alloc_host(void *&shared_pointer, const size_t size)
bool CUDADevice::shared_alloc(void *&shared_pointer, const size_t size)
{
CUDAContextScope scope(this);

Expand All @@ -546,14 +546,14 @@ bool CUDADevice::alloc_host(void *&shared_pointer, const size_t size)
return mem_alloc_result == CUDA_SUCCESS;
}

void CUDADevice::free_host(void *shared_pointer)
void CUDADevice::shared_free(void *shared_pointer)
{
CUDAContextScope scope(this);

cuMemFreeHost(shared_pointer);
}

void *CUDADevice::transform_host_to_device_pointer(const void *shared_pointer)
void *CUDADevice::shared_to_device_pointer(const void *shared_pointer)
{
CUDAContextScope scope(this);
void *device_pointer = nullptr;
Expand Down Expand Up @@ -646,7 +646,7 @@ void CUDADevice::mem_zero(device_memory &mem)
return;
}

if (!(mem.is_host_mapped(this) && mem.host_pointer == mem.shared_pointer)) {
if (!(mem.is_shared(this) && mem.host_pointer == mem.shared_pointer)) {
const CUDAContextScope scope(this);
cuda_assert(cuMemsetD8((CUdeviceptr)mem.device_pointer, 0, mem.memory_size()));
}
Expand Down
33 changes: 17 additions & 16 deletions intern/cycles/device/cuda/device_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,43 @@ class CUDADevice : public GPUDevice {
bool force_ptx = false);

bool load_kernels(const uint kernel_features) override;

void reserve_local_memory(const uint kernel_features);

void get_device_memory_info(size_t &total, size_t &free) override;
bool alloc_device(void *&device_pointer, const size_t size) override;
void free_device(void *device_pointer) override;
bool alloc_host(void *&shared_pointer, const size_t size) override;
void free_host(void *shared_pointer) override;
void *transform_host_to_device_pointer(const void *shared_pointer) override;
void copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size) override;

/* All memory types. */
void mem_alloc(device_memory &mem) override;

void mem_copy_to(device_memory &mem) override;

void mem_move_to_host(device_memory &mem) override;

void mem_copy_from(
device_memory &mem, const size_t y, size_t w, const size_t h, size_t elem) override;

void mem_zero(device_memory &mem) override;

void mem_free(device_memory &mem) override;

device_ptr mem_alloc_sub_ptr(device_memory &mem, const size_t offset, size_t /*size*/) override;

void const_copy_to(const char *name, void *host, const size_t size) override;

/* Global memory. */
void global_alloc(device_memory &mem);
void global_copy_to(device_memory &mem);
void global_free(device_memory &mem);

/* Texture memory. */
void tex_alloc(device_texture &mem);
void tex_copy_to(device_texture &mem);
void tex_free(device_texture &mem);

/* Device side memory. */
void get_device_memory_info(size_t &total, size_t &free) override;
bool alloc_device(void *&device_pointer, const size_t size) override;
void free_device(void *device_pointer) override;

/* Shared memory. */
bool shared_alloc(void *&shared_pointer, const size_t size) override;
void shared_free(void *shared_pointer) override;
void *shared_to_device_pointer(const void *shared_pointer) override;

/* Memory copy. */
void copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size) override;
void const_copy_to(const char *name, void *host, const size_t size) override;

bool should_use_graphics_interop() override;

unique_ptr<DeviceQueue> gpu_queue_create() override;
Expand Down
32 changes: 21 additions & 11 deletions intern/cycles/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,16 @@ OSLGlobals *Device::get_cpu_osl_memory()
return nullptr;
}

void *Device::host_alloc(const MemoryType /*type*/, const size_t size)
{
return util_aligned_malloc(size, MIN_ALIGNMENT_CPU_DATA_TYPES);
}

void Device::host_free(const MemoryType /*type*/, void *host_pointer, const size_t size)
{
util_aligned_free(host_pointer, size);
}

GPUDevice::~GPUDevice() noexcept(false) = default;

bool GPUDevice::load_texture_info()
Expand Down Expand Up @@ -572,7 +582,7 @@ void GPUDevice::move_textures_to_host(size_t size, const size_t headroom, const

/* Can only move textures allocated on this device (and not those from peer devices).
* And need to ignore memory that is already on the host. */
if (!mem.is_resident(this) || mem.is_host_mapped(this)) {
if (!mem.is_resident(this) || mem.is_shared(this)) {
continue;
}

Expand Down Expand Up @@ -677,14 +687,14 @@ GPUDevice::Mem *GPUDevice::generic_alloc(device_memory &mem, const size_t pitch_
}
else if (map_host_used + size < map_host_limit) {
/* Allocate host memory ourselves. */
mem_alloc_result = alloc_host(shared_pointer, size);
mem_alloc_result = shared_alloc(shared_pointer, size);

assert((mem_alloc_result && shared_pointer != nullptr) ||
(!mem_alloc_result && shared_pointer == nullptr));
}

if (mem_alloc_result) {
device_pointer = transform_host_to_device_pointer(shared_pointer);
device_pointer = shared_to_device_pointer(shared_pointer);
map_host_used += size;
status = " in host memory";
}
Expand Down Expand Up @@ -728,7 +738,7 @@ GPUDevice::Mem *GPUDevice::generic_alloc(device_memory &mem, const size_t pitch_
mem.host_pointer != shared_pointer)
{
memcpy(shared_pointer, mem.host_pointer, size);
util_aligned_free(mem.host_pointer, mem.memory_size());
host_free(mem.type, mem.host_pointer, mem.memory_size());
mem.host_pointer = shared_pointer;
}
mem.shared_pointer = shared_pointer;
Expand All @@ -752,7 +762,7 @@ void GPUDevice::generic_free(device_memory &mem)
DCHECK(device_mem_map.find(&mem) != device_mem_map.end());

/* For host mapped memory, reference counting is used to safely free it. */
if (mem.is_host_mapped(this)) {
if (mem.is_shared(this)) {
assert(mem.shared_counter > 0);
if (--mem.shared_counter == 0) {
if (mem.host_pointer == mem.shared_pointer) {
Expand All @@ -764,7 +774,7 @@ void GPUDevice::generic_free(device_memory &mem)
mem.host_pointer = mem.host_alloc(size);
memcpy(mem.host_pointer, mem.shared_pointer, size);
}
free_host(mem.shared_pointer);
shared_free(mem.shared_pointer);
mem.shared_pointer = nullptr;
}
map_host_used -= mem.device_size;
Expand All @@ -791,17 +801,17 @@ void GPUDevice::generic_copy_to(device_memory &mem)
/* If not host mapped, the current device only uses device memory allocated by backend
* device allocation regardless of mem.host_pointer and mem.shared_pointer, and should
* copy data from mem.host_pointer. */
if (!(mem.is_host_mapped(this) && mem.host_pointer == mem.shared_pointer)) {
if (!(mem.is_shared(this) && mem.host_pointer == mem.shared_pointer)) {
copy_host_to_device((void *)mem.device_pointer, mem.host_pointer, mem.memory_size());
}
}

bool GPUDevice::is_host_mapped(const void *shared_pointer,
const device_ptr device_pointer,
Device * /*sub_device*/)
bool GPUDevice::is_shared(const void *shared_pointer,
const device_ptr device_pointer,
Device * /*sub_device*/)
{
return (shared_pointer && device_pointer &&
(device_ptr)transform_host_to_device_pointer(shared_pointer) == device_pointer);
(device_ptr)shared_to_device_pointer(shared_pointer) == device_pointer);
}

/* DeviceInfo */
Expand Down
30 changes: 16 additions & 14 deletions intern/cycles/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ class Device {
return false;
}

virtual bool is_host_mapped(const void * /*shared_pointer*/,
const device_ptr /*device_pointer*/,
Device * /*sub_device*/)
virtual bool is_shared(const void * /*shared_pointer*/,
const device_ptr /*device_pointer*/,
Device * /*sub_device*/)
{
return false;
}
Expand Down Expand Up @@ -320,6 +320,9 @@ class Device {
friend class DeviceServer;
friend class device_memory;

virtual void *host_alloc(const MemoryType type, const size_t size);
virtual void host_free(const MemoryType type, void *host_pointer, const size_t size);

virtual void mem_alloc(device_memory &mem) = 0;
virtual void mem_copy_to(device_memory &mem) = 0;
virtual void mem_move_to_host(device_memory &mem) = 0;
Expand Down Expand Up @@ -398,22 +401,21 @@ class GPUDevice : public Device {
/* total - amount of device memory, free - amount of available device memory */
virtual void get_device_memory_info(size_t &total, size_t &free) = 0;

/* Device side memory. */
virtual bool alloc_device(void *&device_pointer, const size_t size) = 0;

virtual void free_device(void *device_pointer) = 0;

virtual bool alloc_host(void *&shared_pointer, const size_t size) = 0;

virtual void free_host(void *shared_pointer) = 0;

bool is_host_mapped(const void *shared_pointer,
const device_ptr device_pointer,
Device *sub_device) override;

/* Shared memory. */
virtual bool shared_alloc(void *&shared_pointer, const size_t size) = 0;
virtual void shared_free(void *shared_pointer) = 0;
bool is_shared(const void *shared_pointer,
const device_ptr device_pointer,
Device *sub_device) override;
/* This function should return device pointer corresponding to shared pointer, which
* is host buffer, allocated in `alloc_host`. */
virtual void *transform_host_to_device_pointer(const void *shared_pointer) = 0;
* is host buffer, allocated in `shared_alloc`. */
virtual void *shared_to_device_pointer(const void *shared_pointer) = 0;

/* Memory copy. */
virtual void copy_host_to_device(void *device_pointer,
void *host_pointer,
const size_t size) = 0;
Expand Down
8 changes: 4 additions & 4 deletions intern/cycles/device/hip/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ void HIPDevice::free_device(void *device_pointer)
hip_assert(hipFree((hipDeviceptr_t)device_pointer));
}

bool HIPDevice::alloc_host(void *&shared_pointer, const size_t size)
bool HIPDevice::shared_alloc(void *&shared_pointer, const size_t size)
{
HIPContextScope scope(this);

Expand All @@ -508,14 +508,14 @@ bool HIPDevice::alloc_host(void *&shared_pointer, const size_t size)
return mem_alloc_result == hipSuccess;
}

void HIPDevice::free_host(void *shared_pointer)
void HIPDevice::shared_free(void *shared_pointer)
{
HIPContextScope scope(this);

hipHostFree(shared_pointer);
}

void *HIPDevice::transform_host_to_device_pointer(const void *shared_pointer)
void *HIPDevice::shared_to_device_pointer(const void *shared_pointer)
{
HIPContextScope scope(this);
void *device_pointer = nullptr;
Expand Down Expand Up @@ -608,7 +608,7 @@ void HIPDevice::mem_zero(device_memory &mem)
return;
}

if (!(mem.is_host_mapped(this) && mem.host_pointer == mem.shared_pointer)) {
if (!(mem.is_shared(this) && mem.host_pointer == mem.shared_pointer)) {
const HIPContextScope scope(this);
hip_assert(hipMemsetD8((hipDeviceptr_t)mem.device_pointer, 0, mem.memory_size()));
}
Expand Down
32 changes: 17 additions & 15 deletions intern/cycles/device/hip/device_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,41 @@ class HIPDevice : public GPUDevice {
bool load_kernels(const uint kernel_features) override;
void reserve_local_memory(const uint kernel_features);

void get_device_memory_info(size_t &total, size_t &free) override;
bool alloc_device(void *&device_pointer, const size_t size) override;
void free_device(void *device_pointer) override;
bool alloc_host(void *&shared_pointer, const size_t size) override;
void free_host(void *shared_pointer) override;
void *transform_host_to_device_pointer(const void *shared_pointer) override;
void copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size) override;

/* All memory types. */
void mem_alloc(device_memory &mem) override;

void mem_copy_to(device_memory &mem) override;

void mem_move_to_host(device_memory &mem) override;

void mem_copy_from(
device_memory &mem, const size_t y, size_t w, const size_t h, size_t elem) override;

void mem_zero(device_memory &mem) override;

void mem_free(device_memory &mem) override;

device_ptr mem_alloc_sub_ptr(device_memory &mem, const size_t offset, size_t /*size*/) override;

void const_copy_to(const char *name, void *host, const size_t size) override;

/* Global memory. */
void global_alloc(device_memory &mem);
void global_copy_to(device_memory &mem);
void global_free(device_memory &mem);

/* Texture memory. */
void tex_alloc(device_texture &mem);
void tex_copy_to(device_texture &mem);
void tex_free(device_texture &mem);

/* Device side memory. */
void get_device_memory_info(size_t &total, size_t &free) override;
bool alloc_device(void *&device_pointer, const size_t size) override;
void free_device(void *device_pointer) override;

/* Shared memory. */
bool shared_alloc(void *&shared_pointer, const size_t size) override;
void shared_free(void *shared_pointer) override;
void *shared_to_device_pointer(const void *shared_pointer) override;

/* Memory copy. */
void copy_host_to_device(void *device_pointer, void *host_pointer, const size_t size) override;
void const_copy_to(const char *name, void *host, const size_t size) override;

/* Graphics resources interoperability. */
bool should_use_graphics_interop() override;

Expand Down
Loading

0 comments on commit 936e8d5

Please sign in to comment.