-
Notifications
You must be signed in to change notification settings - Fork 28
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
26
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
26 commits
Select commit
Hold shift + click to select a range
10f1eed
feat: apple support
pollend c1f03a2
feat: add templte classes
pollend c03dda8
feat: add command queue mtl
pollend 52fc16a
add ds_store
pollend f7aad2b
feat: update commanQueuMTL
pollend c5463d2
feat: add conversion and start texture
pollend 57b025e
feat: add more to api
pollend e63c331
feat: fix build
pollend 9f465e7
feat: add graphics queu
pollend 6c050b0
feat: add interface
pollend b13bedc
feat: add descriptor
pollend d4621d4
fix compiling errors
pollend 5d98970
feat: start on command buffer logic
pollend 81ea614
add command buffer type
pollend a5f2448
start working on command buffer
pollend 1da2b24
feat: begin shader load logic
pollend c67577b
fix compiling errors
pollend 55f887a
feat: cleanup
pollend 9c16da7
feat: fix compiling errors
pollend b8df84f
feat: update desciprot and textureo
pollend 78d762b
feat: add command buffer impl progress
pollend de9ca9c
feat: add memory mtl
pollend 8c274b5
feat: more progress
pollend a84371e
feat: add descriptor binding logic
pollend 0eaa1a5
feat: more progress with CommandBufferMTL
pollend a9a3121
feat: progress command buffer 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; | ||
const 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.