Merge branch 'blender-v4.0-release' into main
This commit is contained in:
@@ -19,6 +19,9 @@ class BVHMetal : public BVH {
|
||||
API_AVAILABLE(macos(11.0))
|
||||
id<MTLAccelerationStructure> accel_struct = nil;
|
||||
|
||||
API_AVAILABLE(macos(11.0))
|
||||
id<MTLAccelerationStructure> null_BLAS = nil;
|
||||
|
||||
API_AVAILABLE(macos(11.0))
|
||||
vector<id<MTLAccelerationStructure>> blas_array;
|
||||
|
||||
|
||||
@@ -124,6 +124,10 @@ BVHMetal::~BVHMetal()
|
||||
stats.mem_free(accel_struct.allocatedSize);
|
||||
[accel_struct release];
|
||||
}
|
||||
|
||||
if (null_BLAS) {
|
||||
[null_BLAS release];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -964,6 +968,60 @@ bool BVHMetal::build_TLAS(Progress &progress,
|
||||
g_bvh_build_throttler.wait_for_all();
|
||||
|
||||
if (@available(macos 12.0, *)) {
|
||||
/* Defined inside available check, for return type to be available. */
|
||||
auto make_null_BLAS = [](id<MTLDevice> device,
|
||||
id<MTLCommandQueue> queue) -> id<MTLAccelerationStructure> {
|
||||
MTLResourceOptions storage_mode = MTLResourceStorageModeManaged;
|
||||
if (device.hasUnifiedMemory) {
|
||||
storage_mode = MTLResourceStorageModeShared;
|
||||
}
|
||||
|
||||
id<MTLBuffer> nullBuf = [device newBufferWithLength:0 options:storage_mode];
|
||||
|
||||
/* Create an acceleration structure. */
|
||||
MTLAccelerationStructureTriangleGeometryDescriptor *geomDesc =
|
||||
[MTLAccelerationStructureTriangleGeometryDescriptor descriptor];
|
||||
geomDesc.vertexBuffer = nullBuf;
|
||||
geomDesc.vertexBufferOffset = 0;
|
||||
geomDesc.vertexStride = sizeof(float3);
|
||||
geomDesc.indexBuffer = nullBuf;
|
||||
geomDesc.indexBufferOffset = 0;
|
||||
geomDesc.indexType = MTLIndexTypeUInt32;
|
||||
geomDesc.triangleCount = 0;
|
||||
geomDesc.intersectionFunctionTableOffset = 0;
|
||||
geomDesc.opaque = true;
|
||||
geomDesc.allowDuplicateIntersectionFunctionInvocation = false;
|
||||
|
||||
MTLPrimitiveAccelerationStructureDescriptor *accelDesc =
|
||||
[MTLPrimitiveAccelerationStructureDescriptor descriptor];
|
||||
accelDesc.geometryDescriptors = @[ geomDesc ];
|
||||
accelDesc.usage |= MTLAccelerationStructureUsageExtendedLimits;
|
||||
|
||||
MTLAccelerationStructureSizes accelSizes = [device
|
||||
accelerationStructureSizesWithDescriptor:accelDesc];
|
||||
id<MTLAccelerationStructure> accel_struct = [device
|
||||
newAccelerationStructureWithSize:accelSizes.accelerationStructureSize];
|
||||
id<MTLBuffer> scratchBuf = [device newBufferWithLength:accelSizes.buildScratchBufferSize
|
||||
options:MTLResourceStorageModePrivate];
|
||||
id<MTLBuffer> sizeBuf = [device newBufferWithLength:8 options:MTLResourceStorageModeShared];
|
||||
id<MTLCommandBuffer> accelCommands = [queue commandBuffer];
|
||||
id<MTLAccelerationStructureCommandEncoder> accelEnc =
|
||||
[accelCommands accelerationStructureCommandEncoder];
|
||||
[accelEnc buildAccelerationStructure:accel_struct
|
||||
descriptor:accelDesc
|
||||
scratchBuffer:scratchBuf
|
||||
scratchBufferOffset:0];
|
||||
[accelEnc endEncoding];
|
||||
[accelCommands commit];
|
||||
[accelCommands waitUntilCompleted];
|
||||
|
||||
/* free temp resources */
|
||||
[scratchBuf release];
|
||||
[nullBuf release];
|
||||
[sizeBuf release];
|
||||
|
||||
return accel_struct;
|
||||
};
|
||||
|
||||
uint32_t num_instances = 0;
|
||||
uint32_t num_motion_transforms = 0;
|
||||
@@ -1005,7 +1063,7 @@ bool BVHMetal::build_TLAS(Progress &progress,
|
||||
int blas_index = (int)[all_blas count];
|
||||
instance_mapping[blas] = blas_index;
|
||||
if (@available(macos 12.0, *)) {
|
||||
[all_blas addObject:blas->accel_struct];
|
||||
[all_blas addObject:(blas ? blas->accel_struct : null_BLAS)];
|
||||
}
|
||||
return blas_index;
|
||||
}
|
||||
@@ -1052,22 +1110,18 @@ bool BVHMetal::build_TLAS(Progress &progress,
|
||||
if (!blas || !blas->accel_struct) {
|
||||
/* Place a degenerate instance, to ensure [[instance_id]] equals ob->get_device_index()
|
||||
* in our intersection functions */
|
||||
if (motion_blur) {
|
||||
MTLAccelerationStructureMotionInstanceDescriptor *instances =
|
||||
(MTLAccelerationStructureMotionInstanceDescriptor *)[instanceBuf contents];
|
||||
MTLAccelerationStructureMotionInstanceDescriptor &desc = instances[instance_index++];
|
||||
memset(&desc, 0x00, sizeof(desc));
|
||||
blas = nullptr;
|
||||
|
||||
/* Workaround for issue in macOS <= 14.1: Insert degenerate BLAS instead of zero-filling
|
||||
* the descriptor. */
|
||||
if (!null_BLAS) {
|
||||
null_BLAS = make_null_BLAS(device, queue);
|
||||
}
|
||||
else {
|
||||
MTLAccelerationStructureUserIDInstanceDescriptor *instances =
|
||||
(MTLAccelerationStructureUserIDInstanceDescriptor *)[instanceBuf contents];
|
||||
MTLAccelerationStructureUserIDInstanceDescriptor &desc = instances[instance_index++];
|
||||
memset(&desc, 0x00, sizeof(desc));
|
||||
}
|
||||
blas_array.push_back(nil);
|
||||
continue;
|
||||
blas_array.push_back(null_BLAS);
|
||||
}
|
||||
else {
|
||||
blas_array.push_back(blas->accel_struct);
|
||||
}
|
||||
blas_array.push_back(blas->accel_struct);
|
||||
|
||||
uint32_t accel_struct_index = get_blas_index(blas);
|
||||
|
||||
|
||||
@@ -224,7 +224,8 @@ void node_bsdf_principled(vec4 base_color,
|
||||
|
||||
/* Diffuse component */
|
||||
if (true) {
|
||||
diffuse_data.sss_radius = max(subsurface_radius * subsurface_scale, vec3(0.0));
|
||||
diffuse_data.sss_radius = subsurface_weight *
|
||||
max(subsurface_radius * subsurface_scale, vec3(0.0));
|
||||
diffuse_data.sss_id = uint(do_sss);
|
||||
diffuse_data.color += weight * diffuse_sss_base_color.rgb * coat_tint.rgb;
|
||||
}
|
||||
|
||||
@@ -139,6 +139,10 @@ set(LIB
|
||||
|
||||
if(WITH_MATERIALX)
|
||||
add_definitions(-DWITH_MATERIALX)
|
||||
list(APPEND INC
|
||||
${USD_INCLUDE_DIRS}
|
||||
${BOOST_INCLUDE_DIR}
|
||||
)
|
||||
list(APPEND SRC
|
||||
materialx/group_nodes.cc
|
||||
materialx/material.cc
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include <pxr/base/tf/stringUtils.h>
|
||||
|
||||
#include "node_parser.h"
|
||||
|
||||
#include "group_nodes.h"
|
||||
@@ -58,26 +60,40 @@ NodeItem NodeParser::compute_full()
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string NodeParser::node_name() const
|
||||
std::string NodeParser::node_name(bool with_out_socket) const
|
||||
{
|
||||
auto valid_name = [](const std::string &name) {
|
||||
/* Node name should suite to MatX and USD valid names.
|
||||
* It shouldn't start from '_', due to error occured in Storm delegate. */
|
||||
std::string res = MaterialX::createValidName(pxr::TfMakeValidIdentifier(name));
|
||||
if (res[0] == '_') {
|
||||
res = "node" + res;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
std::string name = node_->name;
|
||||
if (node_->output_sockets().size() > 1) {
|
||||
name += std::string("_") + socket_out_->name;
|
||||
}
|
||||
if (ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF, NodeItem::Type::SurfaceOpacity)) {
|
||||
name += "_" + NodeItem::type(to_type_);
|
||||
if (with_out_socket) {
|
||||
if (node_->output_sockets().size() > 1) {
|
||||
name += std::string("_") + socket_out_->name;
|
||||
}
|
||||
if (ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF, NodeItem::Type::SurfaceOpacity))
|
||||
{
|
||||
name += "_" + NodeItem::type(to_type_);
|
||||
}
|
||||
}
|
||||
#ifdef USE_MATERIALX_NODEGRAPH
|
||||
return MaterialX::createValidName(name);
|
||||
return valid_name(name);
|
||||
#else
|
||||
|
||||
std::string prefix;
|
||||
GroupNodeParser *gr = group_parser_;
|
||||
while (gr) {
|
||||
const bNodeTree *ngroup = reinterpret_cast<const bNodeTree *>(gr->node_->id);
|
||||
prefix = MaterialX::createValidName(ngroup->id.name) + "_" + prefix;
|
||||
prefix = valid_name(ngroup->id.name) + "_" + prefix;
|
||||
gr = gr->group_parser_;
|
||||
}
|
||||
return prefix + MaterialX::createValidName(name);
|
||||
return prefix + valid_name(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class NodeParser {
|
||||
virtual NodeItem compute_full();
|
||||
|
||||
protected:
|
||||
std::string node_name() const;
|
||||
std::string node_name(bool with_out_socket = true) const;
|
||||
NodeItem create_node(const std::string &category, NodeItem::Type type);
|
||||
NodeItem create_node(const std::string &category,
|
||||
NodeItem::Type type,
|
||||
|
||||
@@ -178,8 +178,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_MATERIALX
|
||||
{
|
||||
/* Getting node name for Color output. This name will be used for <image> node. */
|
||||
std::string image_node_name = node_name();
|
||||
image_node_name = image_node_name.substr(0, image_node_name.rfind('_')) + "_Color";
|
||||
std::string image_node_name = node_name(false) + "_Color";
|
||||
|
||||
NodeItem res = empty();
|
||||
res.node = graph_->getNode(image_node_name);
|
||||
|
||||
Reference in New Issue
Block a user