-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: apple support #89
Draft
pollend
wants to merge
24
commits into
NVIDIAGameWorks:main
Choose a base branch
from
pollend:feature/apple-metal-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a28bda0
feat: apple support
pollend 5d5d8f3
feat: add templte classes
pollend 457200c
feat: add command queue mtl
pollend bd20ca5
add ds_store
pollend 5838a59
feat: update commanQueuMTL
pollend e1a2156
feat: add conversion and start texture
pollend 3ef604e
feat: add more to api
pollend 7c07c32
feat: fix build
pollend 7e45361
feat: add graphics queu
pollend 45462cf
feat: add interface
pollend 07ed0fe
feat: add descriptor
pollend 417d6b2
fix compiling errors
pollend 0a7e5b1
feat: start on command buffer logic
pollend 3d0b300
add command buffer type
pollend 5cdb7e0
start working on command buffer
pollend 2c3918e
feat: begin shader load logic
pollend f0de1b2
fix compiling errors
pollend b027a75
feat: cleanup
pollend 5601601
feat: fix compiling errors
pollend b0ecb16
feat: update desciprot and textureo
pollend d8e29d3
feat: add command buffer impl progress
pollend 177fae3
feat: add memory mtl
pollend 4b283c0
feat: more progress
pollend b4079f3
feat: add descriptor binding logic
pollend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# apple | ||
.DS_Store | ||
|
||
# cmake | ||
CMakeFiles/ | ||
.cmake/ | ||
|
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,52 @@ | ||
// © 2021 NVIDIA Corporation | ||
|
||
#pragma once | ||
|
||
#include "NRIMacro.h" | ||
#include "NRIDeviceCreation.h" | ||
|
||
|
||
NriNamespaceBegin | ||
|
||
|
||
typedef void* MTLHeap; | ||
typedef void* MTLDeviceHandle; // id<MTLDevice> | ||
typedef void* MTLBufferHandle; // id<MTLHeap> | ||
typedef void* MTLTextureHandle; | ||
|
||
NriStruct(DeviceCreationMTLDesc) | ||
{ | ||
bool enableNRIValidation; | ||
MTLDeviceHandle MtlDevice; | ||
}; | ||
|
||
NriStruct(CommandBufferMTLDesc) | ||
{ | ||
|
||
}; | ||
|
||
NriStruct(BufferMTLDesc) | ||
{ | ||
MTLBufferHandle buffer; | ||
void* mappedMemory; | ||
//MTLResourceOptions options; | ||
}; | ||
|
||
NriStruct(TextureMTLDesc) | ||
{ | ||
//MTLTextureHandle mtlTexture; | ||
//MTLTextureDescriptor* descriptor; | ||
}; | ||
|
||
NriStruct(MemoryMTLDesc) | ||
{ | ||
uint64_t size; | ||
// MTLStorageMode storage; | ||
|
||
//MTLResourceOptions options; | ||
}; | ||
|
||
NRI_API Nri(Result) NRI_CALL nriCreateDeviceFromMtlDevice(const NriRef(DeviceCreationMTLDesc) deviceDesc, NriRef(Device*) device); | ||
|
||
NriNamespaceEnd | ||
|
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,58 @@ | ||
// © 2021 NVIDIA Corporation | ||
#pragma once | ||
|
||
#import <MetalKit/MetalKit.h> | ||
|
||
namespace nri { | ||
|
||
struct DeviceMTL; | ||
struct MemoryMTL; | ||
|
||
struct BufferMTL { | ||
|
||
inline BufferMTL(DeviceMTL& device) | ||
: m_Device(device) { | ||
} | ||
|
||
~BufferMTL(); | ||
|
||
inline id<MTLBuffer> GetHandle() const { | ||
return m_Handle; | ||
} | ||
|
||
inline DeviceMTL& GetDevice() const { | ||
return m_Device; | ||
} | ||
|
||
inline const BufferDesc& GetDesc() const { | ||
return m_Desc; | ||
} | ||
|
||
void* Map(uint64_t offset, uint64_t size); | ||
void Unmap(); | ||
|
||
void FinishMemoryBinding(MemoryMTL& memory, uint64_t memoryOffset); | ||
Result Create(const BufferDesc& bufferDesc); | ||
|
||
//================================================================================================================ | ||
// NRI | ||
//================================================================================================================ | ||
|
||
void SetDebugName(const char* name); | ||
|
||
private: | ||
void UpdateLabel(); | ||
|
||
NSString* m_Label = nullptr; | ||
DeviceMTL& m_Device; | ||
id<MTLBuffer> m_Handle; | ||
uint8_t* m_MappedMemory = nullptr; | ||
uint64_t m_MappedMemoryOffset = 0; | ||
uint64_t m_MappedMemoryRangeSize = 0; | ||
uint64_t m_MappedMemoryRangeOffset = 0; | ||
BufferDesc m_Desc = {}; | ||
bool m_OwnsNativeObjects = true; | ||
}; | ||
|
||
|
||
}; |
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,44 @@ | ||
#include "SharedMTL.h" | ||
|
||
#include "BufferMTL.h" | ||
#include "MemoryMTL.h" | ||
|
||
using namespace nri; | ||
|
||
void* BufferMTL::Map(uint64_t offset, uint64_t size) { | ||
return (uint8_t*)[m_Handle contents] + offset; | ||
} | ||
|
||
BufferMTL::~BufferMTL() { | ||
[m_Label release]; | ||
} | ||
|
||
void BufferMTL::Unmap() { | ||
|
||
} | ||
|
||
void BufferMTL::FinishMemoryBinding(MemoryMTL& memory, uint64_t memoryOffset) { | ||
m_Handle = [memory.GetHandle() | ||
newBufferWithLength: m_Desc.size | ||
options: MTLResourceCPUCacheModeDefaultCache | ||
offset: memoryOffset]; | ||
UpdateLabel(); | ||
} | ||
|
||
void BufferMTL::UpdateLabel() { | ||
if(m_Handle && m_Label) { | ||
[m_Handle setLabel: m_Label]; | ||
} | ||
} | ||
|
||
|
||
|
||
Result BufferMTL::Create(const BufferDesc& bufferDesc) { | ||
m_Desc = bufferDesc; | ||
} | ||
|
||
void BufferMTL::SetDebugName(const char* name) { | ||
m_Label = [NSString stringWithUTF8String:name]; | ||
[m_Label retain]; | ||
UpdateLabel(); | ||
} |
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,38 @@ | ||
// © 2021 NVIDIA Corporation | ||
|
||
#pragma once | ||
|
||
namespace nri { | ||
|
||
struct DeviceMTL; | ||
struct CommandQueueMTL; | ||
|
||
struct CommandAllocatorMTL { | ||
inline CommandAllocatorMTL(DeviceMTL& device) | ||
: m_Device(device) { | ||
} | ||
|
||
inline DeviceMTL& GetDevice() const { | ||
return m_Device; | ||
} | ||
|
||
~CommandAllocatorMTL(); | ||
|
||
|
||
Result Create(const CommandQueue& commandQueue); | ||
|
||
//================================================================================================================ | ||
// NRI | ||
//================================================================================================================ | ||
|
||
void SetDebugName(const char* name); | ||
Result CreateCommandBuffer(CommandBuffer*& commandBuffer); | ||
void Reset(); | ||
|
||
private: | ||
DeviceMTL& m_Device; | ||
struct CommandQueueMTL* m_CommandQueue; | ||
}; | ||
|
||
} | ||
|
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,19 @@ | ||
// © 2021 NVIDIA Corporation | ||
|
||
#pragma region[ Core ] | ||
|
||
static void NRI_CALL SetCommandAllocatorDebugName(CommandAllocator& commandAllocator, const char* name) { | ||
//((CommandAllocatorVK&)commandAllocator).SetDebugName(name); | ||
} | ||
|
||
static Result NRI_CALL CreateCommandBuffer(CommandAllocator& commandAllocator, CommandBuffer*& commandBuffer) { | ||
return ((CommandAllocatorMTL&)commandAllocator).CreateCommandBuffer(commandBuffer); | ||
} | ||
|
||
static void NRI_CALL ResetCommandAllocator(CommandAllocator& commandAllocator) { | ||
//((CommandAllocatorVK&)commandAllocator).Reset(); | ||
} | ||
|
||
#pragma endregion | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like these are #defined in apple framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind to add these undefs to the interface.