-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented ShaderCompiler for Metal
- Loading branch information
1 parent
9d4e7ae
commit 985b184
Showing
28 changed files
with
617 additions
and
160 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
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,11 @@ | ||
|
||
#if defined (CGL_RHI_METAL) | ||
|
||
#define NS_PRIVATE_IMPLEMENTATION | ||
#define CA_PRIVATE_IMPLEMENTATION | ||
#define MTL_PRIVATE_IMPLEMENTATION | ||
|
||
#define EXCLUDE_STDHEADERS | ||
#include <Core/Common.h> | ||
|
||
#endif |
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
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,9 @@ | ||
#pragma once | ||
|
||
#include <Metal/Metal.hpp> | ||
|
||
struct METALCompileObjects | ||
{ | ||
MTL::Library** library; | ||
MTL::Device* device; | ||
}; |
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 @@ | ||
#pragma once | ||
|
||
#include "Metal/MTLBuffer.hpp" | ||
|
||
namespace CGL::Graphics | ||
{ | ||
template <class T> | ||
struct METALConstantBuffer | ||
{ | ||
using value_type = T; | ||
|
||
METALConstantBuffer() | ||
{ | ||
static_assert((sizeof(T) % 16) == 0, "Constant buffer size must be 16-byte aligned."); | ||
} | ||
|
||
MTL::Buffer* cBuffer; | ||
}; | ||
} |
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,15 @@ | ||
#pragma once | ||
|
||
#include "Foundation/NSTypes.hpp" | ||
#include "Metal/MTLBuffer.hpp" | ||
|
||
namespace CGL::Graphics | ||
{ | ||
struct METALIndexBuffer | ||
{ | ||
MTL::Buffer* inxBuffer; | ||
|
||
NS::UInteger offset; | ||
NS::UInteger index; | ||
}; | ||
} |
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,35 @@ | ||
#include "METALPipelineHandler.h" | ||
#include "Foundation/NSError.hpp" | ||
#include "Foundation/NSString.hpp" | ||
|
||
namespace CGL::Graphics { | ||
|
||
CGL_DEFINE_LOG_CATEGORY(METALPipelineHandler); | ||
|
||
METALPipelineHandler::METALPipelineHandler() : rpDescriptor { nullptr }, rpState { nullptr } | ||
{ | ||
rpDescriptor = MTL::RenderPipelineDescriptor::alloc()->init(); | ||
|
||
rpDescriptor->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatRGBA8Unorm_sRGB); | ||
|
||
CGL_LOG(METALPipelineHandler, Info, "RenderPipelineDescriptor Initialized"); | ||
} | ||
|
||
void METALPipelineHandler::CreateRenderPipelineState(MTL::Device* gpu_device) | ||
{ | ||
if(!rpDescriptor) return; | ||
|
||
NS::Error* ns_error{}; | ||
|
||
rpState = gpu_device->newRenderPipelineState(rpDescriptor, &ns_error); | ||
|
||
if(!rpState) { | ||
CGL_LOG(METALPipelineHandler, Error, ns_error->localizedDescription()->utf8String()); | ||
return; | ||
} | ||
|
||
CGL_LOG(METALPipelineHandler, Info, "RenderPipelineState Created"); | ||
rpDescriptor->release(); | ||
rpDescriptor = nullptr; | ||
} | ||
} |
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,26 @@ | ||
#pragma once | ||
|
||
#include "Metal/MTLDevice.hpp" | ||
#include "Metal/MTLRenderPipeline.hpp" | ||
|
||
#include "Core/Logging/Log.h" | ||
|
||
namespace CGL::Graphics | ||
{ | ||
CGL_DECLARE_LOG_CATEGORY(METALPipelineHandler); | ||
|
||
class METALPipelineHandler | ||
{ | ||
public: | ||
METALPipelineHandler(); | ||
|
||
inline auto GetRenderPipelineDescriptor() const { return rpDescriptor; } | ||
inline auto GetRenderPipelineState() const { return rpState; } | ||
|
||
void CreateRenderPipelineState(MTL::Device* gpu_device); | ||
|
||
private: | ||
MTL::RenderPipelineDescriptor* rpDescriptor; | ||
MTL::RenderPipelineState* rpState; | ||
}; | ||
} |
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,12 @@ | ||
#pragma once | ||
|
||
#include "Metal/MTLLibrary.hpp" | ||
|
||
namespace CGL::Graphics | ||
{ | ||
struct METALPixelShader | ||
{ | ||
MTL::Library* cSourceContent; | ||
MTL::Function* pShader; | ||
}; | ||
} |
Oops, something went wrong.