#pragma once
#include "PVRVk/DeviceVk.h"
namespace pvrvk {
#if defined(_WIN32)
#undef MemoryBarrier
#endif
template<class AccessFlagsType> class MemoryBarrierTemplate
{
protected:
AccessFlagsType srcAccessMask;
AccessFlagsType dstAccessMask;
public:
MemoryBarrierTemplate() : srcAccessMask(AccessFlagsType(0)), dstAccessMask(AccessFlagsType(0)) {}
MemoryBarrierTemplate(AccessFlagsType srcAccessMaskParam, AccessFlagsType dstAccessMaskParam) : srcAccessMask(srcAccessMaskParam), dstAccessMask(dstAccessMaskParam) {}
inline const AccessFlagsType& getSrcAccessMask() const { return srcAccessMask; }
inline void setSrcAccessMask(const AccessFlagsType& inSrcAccessMask) { this->srcAccessMask = inSrcAccessMask; }
inline const AccessFlagsType& getDstAccessMask() const { return dstAccessMask; }
inline void setDstAccessMask(const AccessFlagsType& inDstAccessMask) { this->dstAccessMask = inDstAccessMask; }
};
//class BufferMemoryBarrier : public MemoryBarrier
template<class AccessFlagsType> class BufferMemoryBarrierTemplate: public MemoryBarrierTemplate<AccessFlagsType>
{
protected:
Buffer buffer;
uint32_t offset;
uint32_t size;
public:
BufferMemoryBarrierTemplate()
{}
BufferMemoryBarrierTemplate(AccessFlagsType srcAccessMaskParam, AccessFlagsType dstAccessMaskParam, Buffer bufferParam, uint32_t offsetParam, uint32_t sizeParam)
: MemoryBarrierTemplate<AccessFlagsType>(srcAccessMaskParam, dstAccessMaskParam), buffer(bufferParam), offset(offsetParam), size(sizeParam)
{}
inline const Buffer& getBuffer() const { return buffer; }
inline void setBuffer(const Buffer& inBuffer) { this->buffer = inBuffer; }
inline uint32_t getSize() const { return size; }
inline void setSize(uint32_t inSize) { this->size = inSize; }
inline uint32_t getOffset() const { return offset; }
inline void setOffset(uint32_t inOffset) { this->offset = inOffset; }
};
class BarrierPipelineStageFlag2
{
protected:
pvrvk::PipelineStageFlagBits2KHR srcStageMask;
pvrvk::PipelineStageFlagBits2KHR dstStageMask;
public:
BarrierPipelineStageFlag2() : srcStageMask(static_cast<pvrvk::PipelineStageFlagBits2KHR>(0)), dstStageMask(static_cast<pvrvk::PipelineStageFlagBits2KHR>(0)) {}
BarrierPipelineStageFlag2(pvrvk::PipelineStageFlagBits2KHR srcStageMaskParam, pvrvk::PipelineStageFlagBits2KHR dstStageMaskParam)
: srcStageMask(srcStageMaskParam), dstStageMask(dstStageMaskParam)
{}
inline const PipelineStageFlagBits2KHR& getSrcStageMask() const { return srcStageMask; }
inline void setSrcStageMask(const PipelineStageFlagBits2KHR& inSrcStageMask) { this->srcStageMask = inSrcStageMask; }
inline const PipelineStageFlagBits2KHR& getDstStageMask() const { return dstStageMask; }
inline void setDstStageMask(const PipelineStageFlagBits2KHR& inDstStageMask) { this->dstStageMask = inDstStageMask; }
};
class BarrierQueueFamilyIndex
{
protected:
uint32_t srcQueueFamilyIndex;
uint32_t dstQueueFamilyIndex;
public:
BarrierQueueFamilyIndex() : srcQueueFamilyIndex(0), dstQueueFamilyIndex(0) {}
BarrierQueueFamilyIndex(uint32_t srcQueueFamilyIndexParam, uint32_t dstQueueFamilyIndexParam)
: srcQueueFamilyIndex(srcQueueFamilyIndexParam), dstQueueFamilyIndex(dstQueueFamilyIndexParam)
{}
inline uint32_t getSrcQueueFamilyIndex() const { return srcQueueFamilyIndex; }
inline void setSrcQueueFamilyIndex(uint32_t inSrcQueueFamilyIndex) { this->srcQueueFamilyIndex = inSrcQueueFamilyIndex; }
inline uint32_t getDstQueueFamilyIndex() const { return dstQueueFamilyIndex; }
inline void setDstQueueFamilyIndex(uint32_t inDstQueueFamilyIndex) { this->dstQueueFamilyIndex = inDstQueueFamilyIndex; }
};
template<class AccessFlagsType> class ImageMemoryBarrierTemplate : public MemoryBarrierTemplate<AccessFlagsType>, public BarrierQueueFamilyIndex
{
protected:
pvrvk::ImageLayout oldLayout;
pvrvk::ImageLayout newLayout;
Image image;
ImageSubresourceRange subresourceRange;
public:
ImageMemoryBarrierTemplate()
: oldLayout(pvrvk::ImageLayout::e_UNDEFINED), newLayout(pvrvk::ImageLayout::e_UNDEFINED)
{}
ImageMemoryBarrierTemplate(AccessFlagsType srcMask, AccessFlagsType dstMask, const Image& imageParam, const ImageSubresourceRange& subresourceRangeParam,
pvrvk::ImageLayout oldLayoutParam, pvrvk::ImageLayout newLayoutParam, uint32_t srcQueueFamilyIndexParam, uint32_t dstQueueFamilyIndexParam)
: MemoryBarrierTemplate<AccessFlagsType>(srcMask, dstMask),
BarrierQueueFamilyIndex(srcQueueFamilyIndexParam, dstQueueFamilyIndexParam),
oldLayout(oldLayoutParam), newLayout(newLayoutParam),
image(imageParam), subresourceRange(subresourceRangeParam)
{}
inline const ImageLayout& getOldLayout() const { return oldLayout; }
inline void setOldLayout(const ImageLayout& inOldLayout) { this->oldLayout = inOldLayout; }
inline const ImageLayout& getNewLayout() const { return newLayout; }
inline void setNewLayout(const ImageLayout& inNewLayout) { this->newLayout = inNewLayout; }
inline const Image& getImage() const { return image; }
inline void setImage(const Image& inImage) { this->image = inImage; }
inline const ImageSubresourceRange& getSubresourceRange() const { return subresourceRange; }
inline void setSubresourceRange(const ImageSubresourceRange& inSubresourceRange) { this->subresourceRange = inSubresourceRange; }
};
class MemoryBarrier2 : public MemoryBarrierTemplate<pvrvk::AccessFlagBits2KHR>, public BarrierPipelineStageFlag2
{
public:
MemoryBarrier2() {}
MemoryBarrier2(pvrvk::PipelineStageFlagBits2KHR srcStageMask, pvrvk::PipelineStageFlagBits2KHR dstStageMask, pvrvk::AccessFlagBits2KHR srcAccessMask,
pvrvk::AccessFlagBits2KHR dstAccessMask)
: MemoryBarrierTemplate<pvrvk::AccessFlagBits2KHR>(srcAccessMask, dstAccessMask), BarrierPipelineStageFlag2(srcStageMask, dstStageMask)
{}
};
class BufferMemoryBarrier2 : public BufferMemoryBarrierTemplate<pvrvk::AccessFlagBits2KHR>, public BarrierPipelineStageFlag2, public BarrierQueueFamilyIndex
{
public:
BufferMemoryBarrier2() {}
BufferMemoryBarrier2(pvrvk::PipelineStageFlagBits2KHR srcStageMask, pvrvk::PipelineStageFlagBits2KHR dstStageMask, pvrvk::AccessFlagBits2KHR srcAccessMask,
pvrvk::AccessFlagBits2KHR dstAccessMask, uint32_t srcQueueFamilyIndexParam, uint32_t dstQueueFamilyIndexParam, Buffer buffer, uint32_t offset, uint32_t size)
: BufferMemoryBarrierTemplate(srcAccessMask, dstAccessMask, buffer, offset, size),
BarrierPipelineStageFlag2(srcStageMask, dstStageMask),
BarrierQueueFamilyIndex(srcQueueFamilyIndexParam, dstQueueFamilyIndexParam)
{}
};
class ImageMemoryBarrier2 : public ImageMemoryBarrierTemplate<pvrvk::AccessFlagBits2KHR>, public BarrierPipelineStageFlag2
{
public:
ImageMemoryBarrier2()
{}
ImageMemoryBarrier2(pvrvk::PipelineStageFlagBits2KHR srcStageMask, pvrvk::PipelineStageFlagBits2KHR dstStageMask, pvrvk::AccessFlagBits2KHR srcMask,
pvrvk::AccessFlagBits2KHR dstMask,
const Image& image, const ImageSubresourceRange& subresourceRange,
pvrvk::ImageLayout oldLayout, pvrvk::ImageLayout newLayout, uint32_t srcQueueFamilyIndex, uint32_t dstQueueFamilyIndex)
: ImageMemoryBarrierTemplate<pvrvk::AccessFlagBits2KHR>(srcMask, dstMask, image, subresourceRange, oldLayout, newLayout, srcQueueFamilyIndex, dstQueueFamilyIndex),
BarrierPipelineStageFlag2(srcStageMask, dstStageMask)
{}
};
typedef MemoryBarrierTemplate<pvrvk::AccessFlags> MemoryBarrier;
typedef BufferMemoryBarrierTemplate<pvrvk::AccessFlags> BufferMemoryBarrier;
typedef ImageMemoryBarrierTemplate<pvrvk::AccessFlags> ImageMemoryBarrier;
template<class MemoryBarrierType, class BufferMemoryBarrierType, class ImageMemoryBarrierType>
class MemoryBarrierSetTemplate
{
private:
MemoryBarrierSetTemplate& operator=(const MemoryBarrierSetTemplate&) = delete; // deleted
std::vector<MemoryBarrierType> memBarriers;
std::vector<ImageMemoryBarrierType> imageBarriers;
std::vector<BufferMemoryBarrierType> bufferBarriers;
public:
MemoryBarrierSetTemplate() = default;
MemoryBarrierSetTemplate& clearAllBarriers()
{
memBarriers.clear();
imageBarriers.clear();
bufferBarriers.clear();
return *this;
}
MemoryBarrierSetTemplate& clearAllMemoryBarriers()
{
memBarriers.clear();
return *this;
}
MemoryBarrierSetTemplate& clearAllBufferRangeBarriers()
{
bufferBarriers.clear();
return *this;
}
MemoryBarrierSetTemplate& clearAllImageAreaBarriers()
{
imageBarriers.clear();
return *this;
}
MemoryBarrierSetTemplate& addBarrier(MemoryBarrierType barrier)
{
memBarriers.emplace_back(barrier);
return *this;
}
MemoryBarrierSetTemplate& addBarrier(const BufferMemoryBarrierType& barrier)
{
bufferBarriers.emplace_back(barrier);
return *this;
}
MemoryBarrierSetTemplate& addBarrier(const ImageMemoryBarrierType& barrier)
{
imageBarriers.emplace_back(barrier);
return *this;
}
const std::vector<MemoryBarrierType>& getMemoryBarriers() const { return this->memBarriers; }
const std::vector<ImageMemoryBarrierType>& getImageBarriers() const { return this->imageBarriers; }
const std::vector<BufferMemoryBarrierType>& getBufferBarriers() const { return this->bufferBarriers; }
};
typedef MemoryBarrierSetTemplate<MemoryBarrier, BufferMemoryBarrier, ImageMemoryBarrier> MemoryBarrierSet;
typedef MemoryBarrierSetTemplate<MemoryBarrier2, BufferMemoryBarrier2, ImageMemoryBarrier2> MemoryBarrierSet2;
} // namespace pvrvk