-
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
3f9d317
commit c5f5b1b
Showing
24 changed files
with
524 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include "Metal/MTLLibrary.hpp" | ||
#include <Metal/Metal.hpp> | ||
#include <memory> | ||
|
||
struct METALCompileObjects | ||
{ | ||
std::unique_ptr<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* Buffer; | ||
}; | ||
} |
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* Buffer; | ||
|
||
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() : m_rpDescriptor { nullptr }, m_rpState { nullptr } | ||
{ | ||
m_rpDescriptor = MTL::RenderPipelineDescriptor::alloc()->init(); | ||
|
||
m_rpDescriptor->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatRGBA8Unorm_sRGB); | ||
|
||
CGL_LOG(METALPipelineHandler, Info, "RenderPipelineDescriptor Initialized"); | ||
} | ||
|
||
void METALPipelineHandler::CreateRenderPipelineState(MTL::Device* gpu_device) | ||
{ | ||
if(!m_rpDescriptor) return; | ||
|
||
NS::Error* ns_error{}; | ||
|
||
m_rpState = gpu_device->newRenderPipelineState(m_rpDescriptor, &ns_error); | ||
|
||
if(!m_rpState) { | ||
CGL_LOG(METALPipelineHandler, Error, ns_error->localizedDescription()->utf8String()); | ||
return; | ||
} | ||
|
||
CGL_LOG(METALPipelineHandler, Info, "RenderPipelineState Created"); | ||
m_rpDescriptor->release(); | ||
m_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 m_rpDescriptor; } | ||
inline auto GetRenderPipelineState() const { return m_rpState; } | ||
|
||
void CreateRenderPipelineState(MTL::Device* gpu_device); | ||
|
||
private: | ||
MTL::RenderPipelineDescriptor* m_rpDescriptor; | ||
MTL::RenderPipelineState* m_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 | ||
{ | ||
std::unique_ptr<MTL::Library*> SourceContent; | ||
MTL::Function* Shader; | ||
}; | ||
} |
Oops, something went wrong.