Merge branch 'blender-v3.1-release'

This commit is contained in:
Hans Goudey 2022-02-10 11:34:20 -06:00
commit 29674d5e78
11 changed files with 64 additions and 13 deletions

View File

@ -1374,6 +1374,12 @@ class CyclesPreferences(bpy.types.AddonPreferences):
default=False,
)
use_metalrt: BoolProperty(
name="MetalRT (Experimental)",
description="MetalRT for ray tracing uses less memory for scenes which use curves extensively, and can give better performance in specific cases. However this support is experimental and some scenes may render incorrectly",
default=False,
)
def find_existing_device_entry(self, device):
for device_entry in self.devices:
if device_entry.id == device[2] and device_entry.type == device[1]:
@ -1519,6 +1525,12 @@ class CyclesPreferences(bpy.types.AddonPreferences):
row.use_property_split = True
row.prop(self, "peer_memory")
if compute_device_type == 'METAL':
row = layout.row()
row.use_property_split = True
row.prop(self, "use_metalrt")
def draw(self, context):
self.draw_impl(self.layout, context)

View File

@ -118,6 +118,10 @@ DeviceInfo blender_device_info(BL::Preferences &b_preferences, BL::Scene &b_scen
device.has_peer_memory = false;
}
if (get_boolean(cpreferences, "use_metalrt")) {
device.use_metalrt = true;
}
return device;
}

View File

@ -328,6 +328,7 @@ DeviceInfo Device::get_multi_device(const vector<DeviceInfo> &subdevices,
info.has_osl = true;
info.has_profiling = true;
info.has_peer_memory = false;
info.use_metalrt = false;
info.denoisers = DENOISER_ALL;
foreach (const DeviceInfo &device, subdevices) {
@ -374,6 +375,7 @@ DeviceInfo Device::get_multi_device(const vector<DeviceInfo> &subdevices,
info.has_osl &= device.has_osl;
info.has_profiling &= device.has_profiling;
info.has_peer_memory |= device.has_peer_memory;
info.use_metalrt |= device.use_metalrt;
info.denoisers &= device.denoisers;
}

View File

@ -79,6 +79,7 @@ class DeviceInfo {
bool has_profiling; /* Supports runtime collection of profiling info. */
bool has_peer_memory; /* GPU has P2P access to memory of another GPU. */
bool has_gpu_queue; /* Device supports GPU queue. */
bool use_metalrt; /* Use MetalRT to accelerate ray queries (Metal only). */
DenoiserTypeMask denoisers; /* Supported denoiser types. */
int cpu_threads;
vector<DeviceInfo> multi_devices;
@ -96,6 +97,7 @@ class DeviceInfo {
has_profiling = false;
has_peer_memory = false;
has_gpu_queue = false;
use_metalrt = false;
denoisers = DENOISER_NONE;
}

View File

@ -100,6 +100,7 @@ MetalDevice::MetalDevice(const DeviceInfo &info, Stats &stats, Profiler &profile
}
}
use_metalrt = info.use_metalrt;
if (auto metalrt = getenv("CYCLES_METALRT")) {
use_metalrt = (atoi(metalrt) != 0);
}
@ -455,8 +456,14 @@ MetalDevice::MetalMem *MetalDevice::generic_alloc(device_memory &mem)
mem.device_pointer = 0;
id<MTLBuffer> metal_buffer = nil;
MTLResourceOptions options = default_storage_mode;
/* Workaround for "bake" unit tests which fail if RenderBuffers is allocated with MTLResourceStorageModeShared. */
if (strstr(mem.name, "RenderBuffers")) {
options = MTLResourceStorageModeManaged;
}
if (size > 0) {
MTLResourceOptions options = default_storage_mode;
if (mem.type == MEM_DEVICE_ONLY) {
options = MTLResourceStorageModePrivate;
}
@ -490,7 +497,7 @@ MetalDevice::MetalMem *MetalDevice::generic_alloc(device_memory &mem)
mmem->mtlBuffer = metal_buffer;
mmem->offset = 0;
mmem->size = size;
if (mem.type != MEM_DEVICE_ONLY) {
if (options != MTLResourceStorageModePrivate) {
mmem->hostPtr = [metal_buffer contents];
}
else {
@ -759,6 +766,15 @@ void MetalDevice::tex_alloc_as_buffer(device_texture &mem)
void MetalDevice::tex_alloc(device_texture &mem)
{
/* Check that dimensions fit within maximum allowable size.
See https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
*/
if (mem.data_width > 16384 ||
mem.data_height > 16384) {
set_error(string_printf("Texture exceeds maximum allowed size of 16384 x 16384 (requested: %zu x %zu)", mem.data_width, mem.data_height));
return;
}
MTLStorageMode storage_mode = MTLStorageModeManaged;
if (@available(macos 10.15, *)) {
if ([mtlDevice hasUnifiedMemory] &&

View File

@ -59,10 +59,15 @@ bool MetalDeviceKernel::load(MetalDevice *device,
}
bool use_binary_archive = true;
if (getenv("CYCLES_METAL_DISABLE_BINARY_ARCHIVES")) {
if (device->device_vendor == METAL_GPU_APPLE) {
/* Workaround for T94142: Cycles Metal crash with simultaneous viewport and final render */
use_binary_archive = false;
}
if (auto str = getenv("CYCLES_METAL_DISABLE_BINARY_ARCHIVES")) {
use_binary_archive = (atoi(str) == 0);
}
id<MTLBinaryArchive> archive = nil;
string metalbin_path;
if (use_binary_archive) {

View File

@ -327,6 +327,8 @@ void BKE_mesh_vert_coords_apply_with_mat4(struct Mesh *mesh,
const float mat[4][4]);
void BKE_mesh_vert_coords_apply(struct Mesh *mesh, const float (*vert_coords)[3]);
void BKE_mesh_anonymous_attributes_remove(struct Mesh *mesh);
/* *** mesh_tessellate.c *** */
/**

View File

@ -1933,6 +1933,14 @@ void BKE_mesh_vert_coords_apply_with_mat4(Mesh *mesh,
BKE_mesh_normals_tag_dirty(mesh);
}
void BKE_mesh_anonymous_attributes_remove(Mesh *mesh)
{
CustomData_free_layers_anonymous(&mesh->vdata, mesh->totvert);
CustomData_free_layers_anonymous(&mesh->edata, mesh->totedge);
CustomData_free_layers_anonymous(&mesh->pdata, mesh->totpoly);
CustomData_free_layers_anonymous(&mesh->ldata, mesh->totloop);
}
void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spacearr)
{
float(*r_loopnors)[3];

View File

@ -2918,7 +2918,10 @@ static int object_convert_exec(bContext *C, wmOperator *op)
/* Full (edge-angle based) draw calculation should ideally be performed. */
BKE_mesh_edges_set_draw_render(me_eval);
BKE_object_material_from_eval_data(bmain, newob, &me_eval->id);
BKE_mesh_nomain_to_mesh(me_eval, newob->data, newob, &CD_MASK_MESH, true);
Mesh *new_mesh = (Mesh *)newob->data;
BKE_mesh_nomain_to_mesh(me_eval, new_mesh, newob, &CD_MASK_MESH, true);
/* Anonymous attributes shouldn't be available on the applied geometry. */
BKE_mesh_anonymous_attributes_remove(new_mesh);
BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
}
else if (ob->type == OB_FONT) {

View File

@ -765,11 +765,8 @@ static bool modifier_apply_obdata(
BKE_object_material_from_eval_data(bmain, ob, &mesh_applied->id);
BKE_mesh_nomain_to_mesh(mesh_applied, me, ob, &CD_MASK_MESH, true);
/* Anonymous attributes shouldn't by available on the applied geometry. */
CustomData_free_layers_anonymous(&me->vdata, me->totvert);
CustomData_free_layers_anonymous(&me->edata, me->totedge);
CustomData_free_layers_anonymous(&me->pdata, me->totpoly);
CustomData_free_layers_anonymous(&me->ldata, me->totloop);
/* Anonymous attributes shouldn't be available on the applied geometry. */
BKE_mesh_anonymous_attributes_remove(me);
if (md_eval->type == eModifierType_Multires) {
multires_customdata_delete(me);

View File

@ -2224,10 +2224,10 @@ static void lineart_main_load_geometries(
use_mesh = use_ob->data;
}
else {
/* If DEG_ITER_OBJECT_FLAG_DUPLI is set, the curve objects are going to have a mesh
* equivalent already in the object list, so ignore converting the original curve in this
* case. */
if (allow_duplicates) {
/* If DEG_ITER_OBJECT_FLAG_DUPLI is set, some curve objects may also have an evaluated mesh
* object in the list. To avoid adding duplicate geometry, ignore evaluated curve objects in
* those cases. */
if (allow_duplicates && BKE_object_get_evaluated_mesh(ob) != NULL) {
continue;
}
use_mesh = BKE_mesh_new_from_object(depsgraph, use_ob, true, true);