Skip to content

Commit

Permalink
Metal alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed May 17, 2021
1 parent 2c3a299 commit 8ee12df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
7 changes: 4 additions & 3 deletions Engine/gapi/metal/mtswapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class MtSwapchain : public AbstractGraphicsApi::Swapchain {
~MtSwapchain();

void reset() override;
uint32_t nextImage() override;
uint32_t currentBackBufferIndex() override;
uint32_t imageCount() const override;
uint32_t w() const override;
uint32_t h() const override;
void present(uint32_t index);
void present();

MTLPixelFormat format() const;

Expand All @@ -41,7 +41,8 @@ class MtSwapchain : public AbstractGraphicsApi::Swapchain {
MetalView* view = nil;
Tempest::Size sz;

uint32_t imgCount = 0;
uint32_t imgCount = 0;
uint32 currentImg = 0;
void releaseTex();
id<MTLTexture> mkTexture();
};
Expand Down
6 changes: 4 additions & 2 deletions Engine/gapi/metal/mtswapchain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,23 @@ - (CALayer *)makeBackingLayer {
}
}

uint32_t MtSwapchain::nextImage(AbstractGraphicsApi::Semaphore*) {
uint32_t MtSwapchain::currentBackBufferIndex() {
for(;;) {
std::lock_guard<SpinLock> guard(sync);
for(size_t i=0; i<img.size(); ++i) {
if(img[i].inUse)
continue;
img[i].inUse = true;
currentImg = i;
return i;
}
}
throw SwapchainSuboptimal();
}

void MtSwapchain::present(uint32_t i) {
void MtSwapchain::present() {
CAMetalLayer* lay = reinterpret_cast<CAMetalLayer*>(wnd.contentView.layer);
uint32_t i = currentImg;

@autoreleasepool {
id<CAMetalDrawable> drawable = [lay nextDrawable];
Expand Down
4 changes: 2 additions & 2 deletions Engine/gapi/metalapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class MetalApi : public AbstractGraphicsApi {

CommandBuffer* createCommandBuffer(Device* d) override;

void present (Device *d, Swapchain* sw, uint32_t imageId) override;
void present (Device *d, Swapchain* sw) override;

void submit (Device *d, CommandBuffer* cmd, Fence* doneCpu) override;
void submit (Device *d, CommandBuffer** cmd, size_t count, Fence *doneCpu) override;

void getCaps (Device *d,Props& caps) override;
void getCaps (Device *d, Props& caps) override;
};

}
20 changes: 3 additions & 17 deletions Engine/gapi/metalapi.mm
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@
return new MtSync();
}

AbstractGraphicsApi::Semaphore *MetalApi::createSemaphore(AbstractGraphicsApi::Device*) {
return nullptr;
}

AbstractGraphicsApi::PBuffer MetalApi::createBuffer(AbstractGraphicsApi::Device *d,
const void *mem, size_t count, size_t sz, size_t alignedSz,
MemUsage /*usage*/, BufferHeap flg) {
Expand Down Expand Up @@ -256,30 +252,20 @@
return new MtCommandBuffer(dx);
}

void MetalApi::present(AbstractGraphicsApi::Device*,
AbstractGraphicsApi::Swapchain *sw,
uint32_t imageId,
const AbstractGraphicsApi::Semaphore*) {
void MetalApi::present(AbstractGraphicsApi::Device*, AbstractGraphicsApi::Swapchain *sw) {
auto& s = *reinterpret_cast<MtSwapchain*>(sw);
s.present(imageId);
s.present();
}

void MetalApi::submit(AbstractGraphicsApi::Device *d,
AbstractGraphicsApi::CommandBuffer *cmd,
AbstractGraphicsApi::Semaphore *wait,
AbstractGraphicsApi::Semaphore *done,
AbstractGraphicsApi::Fence *doneCpu) {
this->submit(d,&cmd,1,&wait,1,&done,1,doneCpu);
this->submit(d,&cmd,1,doneCpu);
}

void MetalApi::submit(AbstractGraphicsApi::Device*,
AbstractGraphicsApi::CommandBuffer **pcmd, size_t count,
AbstractGraphicsApi::Semaphore **wait, size_t waitCnt,
AbstractGraphicsApi::Semaphore **done, size_t doneCnt,
AbstractGraphicsApi::Fence *doneCpu) {
(void)wait; (void)waitCnt;
(void)done; (void)doneCnt;

auto& fence = *reinterpret_cast<MtSync*>(doneCpu);
fence.signal();
for(size_t i=0; i<count; ++i) {
Expand Down

0 comments on commit 8ee12df

Please sign in to comment.