Skip to content

Commit

Permalink
remove semaphores
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed May 17, 2021
1 parent 25469cc commit 54195b9
Show file tree
Hide file tree
Showing 24 changed files with 48 additions and 262 deletions.
17 changes: 4 additions & 13 deletions Engine/gapi/abstractgraphicsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,10 @@ namespace Tempest {
virtual bool wait(uint64_t time) = 0;
virtual void reset() = 0;
};
struct Semaphore:NoCopy {
virtual ~Semaphore()=default;
};
struct Swapchain:NoCopy {
virtual ~Swapchain()=default;
virtual void reset()=0;
virtual uint32_t nextImage(Semaphore* onReady)=0;
virtual uint32_t nextImage()=0;
virtual uint32_t imageCount() const=0;
virtual uint32_t w() const=0;
virtual uint32_t h() const=0;
Expand Down Expand Up @@ -442,8 +439,6 @@ namespace Tempest {

virtual Fence* createFence(Device *d)=0;

virtual Semaphore* createSemaphore(Device *d)=0;

virtual CommandBuffer*
createCommandBuffer(Device* d)=0;

Expand All @@ -458,14 +453,10 @@ namespace Tempest {
const uint32_t w, const uint32_t h, uint32_t mip) = 0;
virtual void readBytes (Device* d, Buffer* buf, void* out, size_t size) = 0;

virtual void present (Device *d,Swapchain* sw,uint32_t imageId,const Semaphore *wait)=0;
virtual void present (Device *d, Swapchain* sw, uint32_t imageId)=0;

virtual void submit (Device *d,CommandBuffer* cmd,Semaphore* wait,Semaphore* onReady,Fence* onReadyCpu)=0;
virtual void submit (Device *d,
CommandBuffer** cmd,size_t count,
Semaphore** wait, size_t waitCnt,
Semaphore** done, size_t doneCnt,
Fence* doneCpu)=0;
virtual void submit (Device *d, CommandBuffer* cmd, Fence* fence)=0;
virtual void submit (Device *d, CommandBuffer** cmd, size_t count, Fence* fence)=0;

virtual void getCaps (Device *d,Props& caps)=0;

Expand Down
3 changes: 0 additions & 3 deletions Engine/gapi/directx12/dxfence.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@ class DxFence : public AbstractGraphicsApi::Fence {
HANDLE event=nullptr;
};

class DxSemaphore : public AbstractGraphicsApi::Semaphore {
};

}}
5 changes: 2 additions & 3 deletions Engine/gapi/directx12/dxswapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ void DxSwapchain::reset() {
}
}

uint32_t DxSwapchain::nextImage(AbstractGraphicsApi::Semaphore*) {
uint32_t img = impl->GetCurrentBackBufferIndex();
return img;
uint32_t DxSwapchain::nextImage() {
return impl->GetCurrentBackBufferIndex();
}

void DxSwapchain::queuePresent() {
Expand Down
2 changes: 1 addition & 1 deletion Engine/gapi/directx12/dxswapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DxSwapchain : public AbstractGraphicsApi::Swapchain {

void reset() override;
uint32_t imageCount() const override { return imgCount; }
uint32_t nextImage(AbstractGraphicsApi::Semaphore* onReady) override;
uint32_t nextImage() override;

void queuePresent();

Expand Down
21 changes: 5 additions & 16 deletions Engine/gapi/directx12api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ struct DirectX12Api::Impl {

void submit(AbstractGraphicsApi::Device* d,
ID3D12CommandList** cmd, size_t count,
AbstractGraphicsApi::Semaphore** /*wait*/, size_t /*waitCnt*/,
AbstractGraphicsApi::Semaphore** /*done*/, size_t /*doneCnt*/,
AbstractGraphicsApi::Fence* doneCpu){
Detail::DxDevice& dx = *reinterpret_cast<Detail::DxDevice*>(d);
Detail::DxFence& fcpu = *reinterpret_cast<Detail::DxFence*>(doneCpu);
Expand Down Expand Up @@ -222,10 +220,6 @@ AbstractGraphicsApi::Fence* DirectX12Api::createFence(AbstractGraphicsApi::Devic
return new DxFence(*dx);
}

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

AbstractGraphicsApi::PBuffer DirectX12Api::createBuffer(AbstractGraphicsApi::Device* d, const void* mem,
size_t count, size_t size, size_t alignedSz,
MemUsage usage, BufferHeap flg) {
Expand Down Expand Up @@ -418,8 +412,7 @@ AbstractGraphicsApi::CommandBuffer* DirectX12Api::createCommandBuffer(Device* d)
return new DxCommandBuffer(*dx);
}

void DirectX12Api::present(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::Swapchain* sw,
uint32_t imageId, const AbstractGraphicsApi::Semaphore*) {
void DirectX12Api::present(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::Swapchain* sw, uint32_t imageId) {
// TODO: handle imageId
(void)imageId;
Detail::DxDevice& dx = *reinterpret_cast<Detail::DxDevice*>(d);
Expand All @@ -429,20 +422,16 @@ void DirectX12Api::present(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::
sx->queuePresent();
}

void DirectX12Api::submit(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::CommandBuffer* cmd,
AbstractGraphicsApi::Semaphore* wait,
AbstractGraphicsApi::Semaphore* done, AbstractGraphicsApi::Fence* doneCpu) {
void DirectX12Api::submit(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::CommandBuffer* cmd, AbstractGraphicsApi::Fence* doneCpu) {
Detail::DxDevice& dx = *reinterpret_cast<Detail::DxDevice*>(d);
Detail::DxCommandBuffer& bx = *reinterpret_cast<Detail::DxCommandBuffer*>(cmd);
ID3D12CommandList* cmdList[] = { bx.impl.get() };

dx.waitData();
impl->submit(d,cmdList,1,&wait,1,&done,1,doneCpu);
impl->submit(d,cmdList,1,doneCpu);
}

void DirectX12Api::submit(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::CommandBuffer** cmd, size_t count,
AbstractGraphicsApi::Semaphore** wait, size_t waitCnt, AbstractGraphicsApi::Semaphore** done,
size_t doneCnt, AbstractGraphicsApi::Fence* doneCpu) {
void DirectX12Api::submit(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::CommandBuffer** cmd, size_t count, AbstractGraphicsApi::Fence* doneCpu) {
Detail::DxDevice& dx = *reinterpret_cast<Detail::DxDevice*>(d);
ID3D12CommandList* cmdListStk[16]={};
std::unique_ptr<ID3D12CommandList*[]> cmdListHeap;
Expand All @@ -456,7 +445,7 @@ void DirectX12Api::submit(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::C
cmdList[i] = bx.impl.get();
}
dx.waitData();
impl->submit(d,cmdList,count,wait,waitCnt,done,doneCnt,doneCpu);
impl->submit(d,cmdList,count,doneCpu);
}

void DirectX12Api::getCaps(AbstractGraphicsApi::Device* d, AbstractGraphicsApi::Props& caps) {
Expand Down
12 changes: 3 additions & 9 deletions Engine/gapi/directx12api.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class DirectX12Api : public AbstractGraphicsApi {

Fence* createFence(Device *d) override;

Semaphore* createSemaphore(Device *d) override;

PBuffer createBuffer(Device* d, const void *mem, size_t count, size_t size, size_t alignedSz, MemUsage usage, BufferHeap flg) override;

PTexture createTexture(Device* d,const Pixmap& p,TextureFormat frm,uint32_t mips) override;
Expand All @@ -58,14 +56,10 @@ class DirectX12Api : public AbstractGraphicsApi {

CommandBuffer* createCommandBuffer(Device* d) override;

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

void submit (Device *d, CommandBuffer* cmd, Semaphore* wait, Semaphore* onReady, Fence* doneCpu) override;
void submit (Device *d,
CommandBuffer** cmd, size_t count,
Semaphore** wait, size_t waitCnt,
Semaphore** done, size_t doneCnt,
Fence *doneCpu) 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;

Expand Down
2 changes: 1 addition & 1 deletion Engine/gapi/metal/mtswapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MtSwapchain : public AbstractGraphicsApi::Swapchain {
~MtSwapchain();

void reset() override;
uint32_t nextImage(AbstractGraphicsApi::Semaphore* onReady) override;
uint32_t nextImage() override;
uint32_t imageCount() const override;
uint32_t w() const override;
uint32_t h() const override;
Expand Down
11 changes: 3 additions & 8 deletions Engine/gapi/metalapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MetalApi : public AbstractGraphicsApi {
PShader createShader(Device *d, const void* source, size_t src_size) override;

Fence* createFence(Device *d) override;
Semaphore* createSemaphore(Device *d) override;

PBuffer createBuffer(Device* d, const void *mem, size_t count, size_t size, size_t alignedSz, MemUsage usage, BufferHeap flg) override;

Expand All @@ -53,14 +52,10 @@ class MetalApi : public AbstractGraphicsApi {

CommandBuffer* createCommandBuffer(Device* d) override;

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

void submit (Device *d, CommandBuffer* cmd, Semaphore* wait, Semaphore* done, Fence* doneCpu) override;
void submit (Device *d,
CommandBuffer** cmd, size_t count,
Semaphore** wait, size_t waitCnt,
Semaphore** done, size_t doneCnt,
Fence *doneCpu) 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;
};
Expand Down
16 changes: 0 additions & 16 deletions Engine/gapi/vulkan/vdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "vcommandbuffer.h"
#include "vcommandpool.h"
#include "vfence.h"
#include "vsemaphore.h"
#include "vswapchain.h"
#include "vbuffer.h"
#include "vtexture.h"
Expand Down Expand Up @@ -357,21 +356,6 @@ VDevice::MemIndex VDevice::memoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFl
return ret;
}

VkResult VDevice::present(VSwapchain &sw, const VSemaphore *wait, size_t wSize, uint32_t imageId) {
VkPresentInfoKHR presentInfo = {};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;

presentInfo.waitSemaphoreCount = uint32_t(wSize);
presentInfo.pWaitSemaphores = &wait->impl;

VkSwapchainKHR swapChains[] = {sw.swapChain};
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = swapChains;
presentInfo.pImageIndices = &imageId;

return presentQueue->present(presentInfo);
}

void VDevice::waitIdle() {
waitIdleSync(queues,sizeof(queues)/sizeof(queues[0]));
}
Expand Down
2 changes: 0 additions & 2 deletions Engine/gapi/vulkan/vdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace Tempest {
namespace Detail {

class VFence;
class VSemaphore;

class VTexture;

Expand Down Expand Up @@ -203,7 +202,6 @@ class VDevice : public AbstractGraphicsApi::Device {
PFN_vkGetBufferMemoryRequirements2KHR vkGetBufferMemoryRequirements2 = nullptr;
PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2 = nullptr;

VkResult present(VSwapchain& sw,const VSemaphore *wait,size_t wSize,uint32_t imageId);
void waitIdle() override;

void submit(VCommandBuffer& cmd,VFence& sync);
Expand Down
29 changes: 0 additions & 29 deletions Engine/gapi/vulkan/vsemaphore.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions Engine/gapi/vulkan/vsemaphore.h

This file was deleted.

3 changes: 1 addition & 2 deletions Engine/gapi/vulkan/vswapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <Tempest/SystemApi>

#include "vdevice.h"
#include "vsemaphore.h"

using namespace Tempest;
using namespace Tempest::Detail;
Expand Down Expand Up @@ -223,7 +222,7 @@ uint32_t VSwapchain::getImageCount(const SwapChainSupport& support) const {
return imageCount;
}

uint32_t VSwapchain::nextImage(AbstractGraphicsApi::Semaphore*) {
uint32_t VSwapchain::nextImage() {
auto& slot = sync[syncIndex];
uint32_t id = uint32_t(-1);
VkResult code = vkAcquireNextImageKHR(device.device.impl,
Expand Down
4 changes: 1 addition & 3 deletions Engine/gapi/vulkan/vswapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

namespace Tempest {

class Semaphore;

namespace Detail {

class VDevice;
Expand All @@ -30,7 +28,7 @@ class VSwapchain : public AbstractGraphicsApi::Swapchain {

void reset() override;
uint32_t imageCount() const override { return uint32_t(views.size()); }
uint32_t nextImage(AbstractGraphicsApi::Semaphore* onReady) override;
uint32_t nextImage() override;

VkSwapchainKHR swapChain=VK_NULL_HANDLE;
std::vector<VkImageView> views;
Expand Down
1 change: 0 additions & 1 deletion Engine/gapi/vulkan/vulkanapi_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if defined(TEMPEST_BUILD_VULKAN)

#include "vsemaphore.h"
#include "vulkanapi_impl.h"

#include <Tempest/Log>
Expand Down
21 changes: 4 additions & 17 deletions Engine/gapi/vulkanapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "vulkan/vbuffer.h"
#include "vulkan/vshader.h"
#include "vulkan/vfence.h"
#include "vulkan/vsemaphore.h"
#include "vulkan/vcommandpool.h"
#include "vulkan/vcommandbuffer.h"
#include "vulkan/vdescriptorarray.h"
Expand Down Expand Up @@ -139,10 +138,6 @@ AbstractGraphicsApi::Fence *VulkanApi::createFence(AbstractGraphicsApi::Device *
return new Detail::VFence(*dx);
}

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

AbstractGraphicsApi::PBuffer VulkanApi::createBuffer(AbstractGraphicsApi::Device *d,
const void *mem, size_t count, size_t size, size_t alignedSz,
MemUsage usage, BufferHeap flg) {
Expand Down Expand Up @@ -299,7 +294,7 @@ AbstractGraphicsApi::CommandBuffer* VulkanApi::createCommandBuffer(AbstractGraph
return new Detail::VCommandBuffer(*dx);
}

void VulkanApi::present(Device *d, Swapchain *sw, uint32_t imageId, const Semaphore*) {
void VulkanApi::present(Device *d, Swapchain *sw, uint32_t imageId) {
Detail::VDevice* dx=reinterpret_cast<Detail::VDevice*>(d);
Detail::VSwapchain* sx=reinterpret_cast<Detail::VSwapchain*>(sw);

Expand Down Expand Up @@ -333,23 +328,15 @@ void VulkanApi::present(Device *d, Swapchain *sw, uint32_t imageId, const Semaph
Detail::vkAssert(code);
}

void VulkanApi::submit(Device *d,
CommandBuffer* cmd,
Semaphore* wait,
Semaphore* onReady,
Fence *onReadyCpu) {
void VulkanApi::submit(Device *d, CommandBuffer* cmd, Fence *doneCpu) {
Detail::VDevice* dx=reinterpret_cast<Detail::VDevice*>(d);
Detail::VCommandBuffer* cx=reinterpret_cast<Detail::VCommandBuffer*>(cmd);
auto* rc=reinterpret_cast<Detail::VFence*>(onReadyCpu);
auto* rc=reinterpret_cast<Detail::VFence*>(doneCpu);

impl->submit(dx,&cx,1,rc);
}

void VulkanApi::submit(AbstractGraphicsApi::Device *d,
AbstractGraphicsApi::CommandBuffer **cmd, size_t count,
Semaphore **wait, size_t waitCnt,
Semaphore **done, size_t doneCnt,
Fence *doneCpu) {
void VulkanApi::submit(AbstractGraphicsApi::Device *d, AbstractGraphicsApi::CommandBuffer **cmd, size_t count, Fence* doneCpu) {
auto* dx = reinterpret_cast<VDevice*>(d);
auto* rc = reinterpret_cast<VFence*>(doneCpu);
impl->submit(dx,reinterpret_cast<VCommandBuffer**>(cmd),count,rc);
Expand Down
Loading

0 comments on commit 54195b9

Please sign in to comment.