-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michael Pollind <[email protected]>
- Loading branch information
Showing
14 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// © 2021 NVIDIA Corporation | ||
|
||
#pragma once | ||
|
||
#include "NRIDeviceCreation.h" | ||
|
||
NRI_NAMESPACE_BEGIN | ||
|
||
NRI_STRUCT(DeviceCreationMTLDesc) | ||
{ | ||
bool enableNRIValidation; | ||
id<MTLDevice> MtlDevice; | ||
} | ||
|
||
NRI_STRUCT(CommandBufferMTLDesc) | ||
{ | ||
|
||
} | ||
|
||
|
||
NRI_API NRI_NAME(Result) NRI_CALL nriCreateDeviceFromMtlDevice(const NRI_NAME_REF(DeviceCreationMTLDesc) deviceDesc, NRI_NAME_REF(Device*) device); | ||
|
||
NRI_NAMESPACE_END | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
|
||
#import <MetalKit/MetalKit.h> | ||
|
||
struct BufferMetal { | ||
|
||
private: | ||
id<MTLBuffer> pBuffer; | ||
//id<MTLIndirectCommandBuffer> pIndirectCommandBuffer; | ||
uint64_t mOffset; | ||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "BufferMetal.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
namespace nri { | ||
|
||
struct DeviceMetal final : public DeviceBase { | ||
BufferMetal(const CallbackInterface& callbacks, const StdAllocator<uint8_t>& stdAllocator); | ||
~BufferMetal(); | ||
|
||
Result FillFunctionTable(CoreInterface& table) const; | ||
Result FillFunctionTable(HelperInterface& table) const; | ||
Result FillFunctionTable(LowLatencyInterface& table) const; | ||
Result FillFunctionTable(MeshShaderInterface& table) const; | ||
Result FillFunctionTable(RayTracingInterface& table) const; | ||
Result FillFunctionTable(StreamerInterface& table) const; | ||
Result FillFunctionTable(SwapChainInterface& table) const; | ||
Result FillFunctionTable(ResourceAllocatorInterface& table) const; | ||
Result FillFunctionTable(WrapperD3D11Interface& table) const; | ||
Result FillFunctionTable(WrapperD3D12Interface& table) const; | ||
Result FillFunctionTable(WrapperVKInterface& table) const; | ||
|
||
//================================================================================================================ | ||
// DeviceBase | ||
//================================================================================================================ | ||
|
||
inline const DeviceDesc& GetDesc() const { | ||
return m_Desc; | ||
} | ||
|
||
Result Create(const DeviceCreationDesc& deviceCreationDesc, const DeviceCreationMTLDesc& deviceCreationVKDesc, bool isWrapper); | ||
private: | ||
DeviceDesc m_Desc = {}; | ||
id<MTLDevice> m_Device; | ||
DeviceDesc m_Desc = {}; | ||
bool m_OwnsNativeObjects = true; | ||
}; | ||
}; // namespace nri |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Declare_PartiallyFillFunctionTable_Functions(MTL); | ||
|
||
#pragma region[ Core ] | ||
|
||
static const DeviceDesc& NRI_CALL GetDeviceDesc(const Device& device) { | ||
return ((const DeviceMetal&)device).GetDesc(); | ||
} | ||
|
||
#pragma endregion | ||
|
||
|
||
Define_Core_Device_PartiallyFillFunctionTable(MTL); | ||
Define_Helper_Device_PartiallyFillFunctionTable(MTL); | ||
Define_RayTracing_Device_PartiallyFillFunctionTable(MTL); | ||
Define_Streamer_Device_PartiallyFillFunctionTable(MTL); | ||
Define_SwapChain_Device_PartiallyFillFunctionTable(MTL); | ||
Define_ResourceAllocator_Device_PartiallyFillFunctionTable(MTL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "DeviceMetal.h" | ||
|
||
using namespace nri; | ||
|
||
BufferMetal::BufferMetal(const CallbackInterface& callbacks, const StdAllocator<uint8_t>& stdAllocator) | ||
: DeviceBase(callbacks, stdAllocator) { | ||
m_Desc.graphicsAPI = GraphicsAPI::VK; | ||
m_Desc.nriVersionMajor = NRI_VERSION_MAJOR; | ||
m_Desc.nriVersionMinor = NRI_VERSION_MINOR; | ||
|
||
} | ||
BufferMetal::~BufferMetal() { | ||
|
||
} | ||
|
||
Result CreateDeviceMTL(const DeviceCreationDesc& deviceCreationDesc, DeviceBase*& device) { | ||
|
||
} | ||
|
||
Result CreateDeviceMTL(const DeviceCreationMTLDesc& deviceCreationDesc, DeviceBase*& device) { | ||
|
||
} | ||
|
||
Result DeviceMetal::Create(const DeviceCreationDesc& deviceCreationDesc, const DeviceCreationMTLDesc& deviceCreationMTLDesc, bool isWrapper) { | ||
m_OwnsNativeObjects = !isWrapper; | ||
|
||
if(isWrapper) { | ||
m_Device = deviceCreationMTLDesc.MtlDevice; | ||
} | ||
|
||
strncpy(m_Desc.adapterDesc.name, [m_Device.name UTF8String], sizeof(m_Desc.adapterDesc.name)); | ||
// No vendor id, device id for Apple GPUs | ||
if (strstr(m_Desc.adapterDesc.name, "Apple")) | ||
{ | ||
m_Desc.adapterDesc.vendor = nri::Vendor::APPLE; | ||
} else { | ||
const uint64_t regID = [m_Device registryID]; | ||
if (regID) | ||
{ | ||
io_registry_entry_t entry = IOServiceGetMatchingService(kIOMasterPortDefault, IORegistryEntryIDMatching(regID)); | ||
if (entry) | ||
{ | ||
// That returned the IOGraphicsAccelerator nub. Its parent, then, is the actual PCI device. | ||
io_registry_entry_t parent; | ||
if (IORegistryEntryGetParentEntry(entry, kIOServicePlane, &parent) == kIOReturnSuccess) | ||
{ | ||
m_Desc.adapterDesc.vendor = GetVendorFromID(GetEntryProperty(parent, CFSTR("vendor-id"))); | ||
m_Desc.adapterDesc.deviceId = GetEntryProperty(parent, CFSTR("device-id")); | ||
IOObjectRelease(parent); | ||
} | ||
IOObjectRelease(entry); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters