Skip to content

Commit

Permalink
feat: update desciprot and textureo
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Nov 19, 2024
1 parent 5601601 commit b0ecb16
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 18 deletions.
4 changes: 3 additions & 1 deletion Source/Metal/CommandAllocatorMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ struct CommandAllocatorMTL {
// NRI
//================================================================================================================

void SetDebugName(const char* name);
Result CreateCommandBuffer(CommandBuffer*& commandBuffer);
void Reset();

private:
struct CommandQueueMTL* m_CommandQueue;
DeviceMTL& m_Device;
struct CommandQueueMTL* m_CommandQueue;
};

}
Expand Down
5 changes: 3 additions & 2 deletions Source/Metal/CommandAllocatorMTL.mm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "SharedMTL.h"

#include "CommandAllocatorMTL.h"

#include "CommandBufferMTL.h"
#include "CommandQueueMTL.h"

using namespace nri;
Expand All @@ -20,8 +20,9 @@
//================================================================================================================

Result CommandAllocatorMTL::CreateCommandBuffer(CommandBuffer*& commandBuffer) {


CommandBufferMTL* commandBufferImpl = Allocate<CommandBufferMTL>(m_Device.GetStdAllocator(), m_Device);
commandBuffer = (CommandBuffer*)commandBufferImpl;
return Result::SUCCESS;
}

Expand Down
26 changes: 23 additions & 3 deletions Source/Metal/CommandBufferMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

Result CommandBufferMTL::Begin(const DescriptorPool* descriptorPool) {
[m_Handle computeCommandEncoderWithDescriptor: NULL];
m_ComputeEncoder = [m_Handle computeCommandEncoderWithDescriptor: NULL];
}

Result CommandBufferMTL::End() {
Expand Down Expand Up @@ -93,15 +93,32 @@
}
void CommandBufferMTL::BeginRendering(const AttachmentsDesc& attachmentsDesc) {
MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];

for(uint32_t i = 0; i < attachmentsDesc.colorNum; i++) {
DescriptorMTL& descriptorMTL = *(DescriptorMTL*)attachmentsDesc.colors[i];

renderPassDescriptor.colorAttachments[i].texture = descriptorMTL.GetImageView() ;
renderPassDescriptor.colorAttachments[i].clearColor = MTLClearColorMake(0, 0, 0, 1);
renderPassDescriptor.colorAttachments[i].loadAction = MTLLoadActionClear;
renderPassDescriptor.colorAttachments[i].storeAction = MTLStoreActionStore;

}

if(attachmentsDesc.depthStencil) {

DescriptorMTL& descriptorMTL = *(DescriptorMTL*)attachmentsDesc.depthStencil;
renderPassDescriptor.depthAttachment.texture = descriptorMTL.GetImageView();
// renderPassDescriptor.depthAttachment.clearColor = MTLClearColorMake(0, 0, 0, 1);
renderPassDescriptor.depthAttachment.loadAction = MTLLoadActionClear;
renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionStore;

}

//renderPassDescriptor.colorAttachments[

//renderPassDescriptor.colorAttachments

m_RendererEncoder = [m_Handle renderCommandEncoderWithDescriptor: NULL];
m_RendererEncoder = [m_Handle renderCommandEncoderWithDescriptor: renderPassDescriptor];
}
void CommandBufferMTL::EndRendering() {
[m_RendererEncoder endEncoding];
Expand All @@ -110,8 +127,11 @@
}
void CommandBufferMTL::SetViewports(const Viewport* viewports, uint32_t viewportNum) {
//MTLViewport* mtlViewports = StackAlloc(MTLViewport, viewportNum);

Scratch<MTLViewport> mtlViewports = AllocateScratch(m_Device, MTLViewport, viewportNum);


// [m_RendererEncoder setViewports:<#(const MTLViewport * _Nonnull)#> count:<#(NSUInteger)#>
[m_RendererEncoder setViewports:mtlViewports count:viewportNum];
}
void CommandBufferMTL::SetScissors(const Rect* rects, uint32_t rectNum) {
NSCAssert(m_RendererEncoder, @"encoder set");
Expand Down
26 changes: 19 additions & 7 deletions Source/Metal/DescriptorMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@ namespace nri {

struct DeviceMTL;

enum class DescriptorTypeMTL {
NONE,
IMAGE_VIEW
};

struct DescriptorMTL {

public:
inline DescriptorMTL (DeviceMTL& device)
: m_Device(device) {
}

inline Result Create(const Texture1DViewDesc& textureViewDesc) {}
inline Result Create(const Texture2DViewDesc& textureViewDesc){}
inline Result Create(const Texture3DViewDesc& textureViewDesc){}
inline Result Create(const SamplerDesc& samplerDesc){}


inline id<MTLTexture> GetImageView() {
return m_texture;
}


Result Create(const BufferViewDesc& bufferViewDesc);
Result Create(const Texture1DViewDesc& textureViewDesc);
Result Create(const Texture2DViewDesc& textureViewDesc);
Result Create(const Texture3DViewDesc& textureViewDesc);
Result Create(const SamplerDesc& samplerDesc);
private:
DeviceMTL& m_Device;

id<MTLTexture> m_texture;
DescriptorTypeMTL m_type = DescriptorTypeMTL::NONE;

};

Expand Down
31 changes: 31 additions & 0 deletions Source/Metal/DescriptorMTL.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "SharedMTL.h"

#include "DescriptorMTL.h"

#include "BufferMTL.h"

namespace nri {

Result DescriptorMTL::Create(const BufferViewDesc& bufferViewDesc) {
// m_Type = DescriptorTypeVK::BUFFER_VIEW;
const BufferMTL& buffer = *(const BufferMTL*)bufferViewDesc.buffer;

return Result::SUCCESS;

}
Result DescriptorMTL::Create(const Texture1DViewDesc& textureViewDesc) {
return Result::SUCCESS;

}
Result DescriptorMTL::Create(const Texture2DViewDesc& textureViewDesc) {

return Result::SUCCESS;
}
Result DescriptorMTL::Create(const Texture3DViewDesc& textureViewDesc){
return Result::SUCCESS;
}
Result DescriptorMTL::Create(const SamplerDesc& samplerDesc){
return Result::SUCCESS;
}

}
5 changes: 4 additions & 1 deletion Source/Metal/PipelineMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
} else if(shader.stage & nri::StageBits::FRAGMENT_SHADER) {
renderPipelineDesc.fragmentFunction = entryPointFunc;
}

}
// Depth-stencil
const DepthAttachmentDesc& da = graphicsPipelineDesc.outputMerger.depth;
Expand Down Expand Up @@ -92,7 +91,11 @@

if (graphicsPipelineDesc.multisample) {
// TODO: multisampling
//
}

// renderPipelineDesc.rasterSampleCount = pCreateInfo->pMultisampleState->pSampleMask[0];


// Blending

Expand Down
7 changes: 3 additions & 4 deletions Source/Metal/TextureMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ struct TextureMTL {
}
~TextureMTL();

//inline id<MTLTexture> GetHandle() const {
// return m_Handle;
//}
inline id<MTLTexture> GetHandle() const {
return m_Handle;
}

inline DeviceMTL& GetDevice() const {
return m_Device;
Expand All @@ -27,7 +27,6 @@ struct TextureMTL {
}

Result Create(const TextureDesc& textureDesc);
//Result Create(const TextureMTLDesc& textureDesc);

private:
// Result CreateFromTextureDesc(const TextureDesc& textureDesc);
Expand Down

0 comments on commit b0ecb16

Please sign in to comment.