Skip to content

Commit

Permalink
Fixing Xcode 11 build. Moves MetalState constructor to its own module…
Browse files Browse the repository at this point in the history
…, and move intialization to a separate function call
  • Loading branch information
Morteeza committed Feb 26, 2023
1 parent b485f68 commit 75583c0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
1 change: 1 addition & 0 deletions source/MaterialXRenderMsl/MetalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct MetalState

MetalState();

void initialize(id<MTLDevice> mtlDevice, id<MTLCommandQueue> mtlCmdQueue);
void initLinearToSRGBKernel();
void triggerProgrammaticCapture();
void stopProgrammaticCapture();
Expand Down
31 changes: 31 additions & 0 deletions source/MaterialXRenderMsl/MetalState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@

std::unique_ptr<MetalState> MetalState::singleton = nullptr;

MetalState::MetalState()
{
}

void MetalState::initialize(id<MTLDevice> mtlDevice, id<MTLCommandQueue> mtlCmdQueue)
{
device = mtlDevice;
cmdQueue = mtlCmdQueue;

#if MAC_OS_VERSION_11_0
supportsTiledPipeline = [device supportsFamily:MTLGPUFamilyApple4];
#else
supportsTiledPipeline = false;
#endif

MTLDepthStencilDescriptor* depthStencilDesc = [MTLDepthStencilDescriptor new];
depthStencilDesc.depthWriteEnabled = true;
depthStencilDesc.depthCompareFunction = MTLCompareFunctionLess;
opaqueDepthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDesc];

depthStencilDesc.depthWriteEnabled = false;
depthStencilDesc.depthCompareFunction = MTLCompareFunctionLess;
transparentDepthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDesc];

depthStencilDesc.depthWriteEnabled = true;
depthStencilDesc.depthCompareFunction = MTLCompareFunctionAlways;
envMapDepthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDesc];

initLinearToSRGBKernel();
}

void MetalState::initLinearToSRGBKernel()
{
NSError* error = nil;
Expand Down
31 changes: 3 additions & 28 deletions source/MaterialXView/ViewerMSL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,6 @@

using namespace mx;


MetalState::MetalState()
{
device = (id<MTLDevice>)ng::metal_device();
cmdQueue = (id<MTLCommandQueue>)ng::metal_command_queue();

#if MAC_OS_VERSION_11_0
supportsTiledPipeline = [device supportsFamily:MTLGPUFamilyApple4];
#else
supportsTiledPipeline = false;
#endif

MTLDepthStencilDescriptor* depthStencilDesc = [MTLDepthStencilDescriptor new];
depthStencilDesc.depthWriteEnabled = true;
depthStencilDesc.depthCompareFunction = MTLCompareFunctionLess;
opaqueDepthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDesc];

depthStencilDesc.depthWriteEnabled = false;
depthStencilDesc.depthCompareFunction = MTLCompareFunctionLess;
transparentDepthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDesc];

depthStencilDesc.depthWriteEnabled = true;
depthStencilDesc.depthCompareFunction = MTLCompareFunctionAlways;
envMapDepthStencilState = [device newDepthStencilStateWithDescriptor:depthStencilDesc];

initLinearToSRGBKernel();
}

namespace {

const int ALBEDO_TABLE_SIZE = 128;
Expand Down Expand Up @@ -216,6 +188,9 @@ void emitFunctionCall(const mx::ShaderNode& node, mx::GenContext& context, mx::
_materialFilename = localSearchPath.find(_materialFilename);
_meshFilename = localSearchPath.find(_meshFilename);
_envRadianceFilename = localSearchPath.find(_envRadianceFilename);

MTL(initialize((id<MTLDevice>)ng::metal_device(),
(id<MTLCommandQueue>)ng::metal_command_queue()));

// Set the requested background color.
set_background(ng::Color(screenColor[0], screenColor[1], screenColor[2], 1.0f));
Expand Down

0 comments on commit 75583c0

Please sign in to comment.