blob: 63b020e2e3c8a7ef5b3ea0d872a1316016ff0543 [file] [log] [blame]
/*
* MVKCmdPipeline.h
*
* Copyright (c) 2015-2020 The Brenwill Workshop Ltd. (http://www.brenwill.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "MVKCommand.h"
#include "MVKMTLResourceBindings.h"
#include "MVKSync.h"
#include "MVKVector.h"
class MVKCommandBuffer;
class MVKPipeline;
class MVKPipelineLayout;
class MVKDescriptorSet;
class MVKDescriptorUpdateTemplate;
#pragma mark -
#pragma mark MVKCmdPipelineBarrier
/**
* Vulkan command to add a pipeline barrier.
* Template class to balance vector pre-allocations between very common low counts and fewer larger counts.
*/
template <size_t N>
class MVKCmdPipelineBarrier : public MVKCommand {
public:
VkResult setContent(MVKCommandBuffer* cmdBuff,
VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
VkDependencyFlags dependencyFlags,
uint32_t memoryBarrierCount,
const VkMemoryBarrier* pMemoryBarriers,
uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier* pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier* pImageMemoryBarriers);
void encode(MVKCommandEncoder* cmdEncoder) override;
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
bool coversTextures();
VkPipelineStageFlags _srcStageMask;
VkPipelineStageFlags _dstStageMask;
VkDependencyFlags _dependencyFlags;
MVKVectorInline<MVKPipelineBarrier, N> _barriers;
};
// Concrete template class implementations.
typedef MVKCmdPipelineBarrier<1> MVKCmdPipelineBarrier1;
typedef MVKCmdPipelineBarrier<4> MVKCmdPipelineBarrier4;
typedef MVKCmdPipelineBarrier<32> MVKCmdPipelineBarrierMulti;
#pragma mark -
#pragma mark MVKCmdBindPipeline
/** Vulkan command to bind the pipeline state. */
class MVKCmdBindPipeline : public MVKCommand {
public:
VkResult setContent(MVKCommandBuffer* cmdBuff,
VkPipelineBindPoint pipelineBindPoint,
VkPipeline pipeline);
void encode(MVKCommandEncoder* cmdEncoder) override;
bool isTessellationPipeline();
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
VkPipelineBindPoint _bindPoint;
MVKPipeline* _pipeline;
};
#pragma mark -
#pragma mark MVKCmdBindDescriptorSets
/** Vulkan command to bind descriptor sets. */
class MVKCmdBindDescriptorSets : public MVKCommand {
public:
VkResult setContent(MVKCommandBuffer* cmdBuff,
VkPipelineBindPoint pipelineBindPoint,
VkPipelineLayout layout,
uint32_t firstSet,
uint32_t setCount,
const VkDescriptorSet* pDescriptorSets,
uint32_t dynamicOffsetCount,
const uint32_t* pDynamicOffsets);
void encode(MVKCommandEncoder* cmdEncoder) override;
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
VkPipelineBindPoint _pipelineBindPoint;
MVKPipelineLayout* _pipelineLayout;
MVKVectorInline<MVKDescriptorSet*, 8> _descriptorSets;
MVKVectorInline<uint32_t, 8> _dynamicOffsets;
uint32_t _firstSet;
};
#pragma mark -
#pragma mark MVKCmdPushConstants
/** Vulkan command to bind push constants. */
class MVKCmdPushConstants : public MVKCommand {
public:
VkResult setContent(MVKCommandBuffer* cmdBuff,
VkPipelineLayout layout,
VkShaderStageFlags stageFlags,
uint32_t offset,
uint32_t size,
const void* pValues);
void encode(MVKCommandEncoder* cmdEncoder) override;
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
MVKPipelineLayout* _pipelineLayout;
VkShaderStageFlags _stageFlags;
uint32_t _offset;
MVKVectorInline<char, 128> _pushConstants;
};
#pragma mark -
#pragma mark MVKCmdPushDescriptorSet
/** Vulkan command to update a descriptor set. */
class MVKCmdPushDescriptorSet : public MVKCommand {
public:
VkResult setContent(MVKCommandBuffer* cmdBuff,
VkPipelineBindPoint pipelineBindPoint,
VkPipelineLayout layout,
uint32_t set,
uint32_t descriptorWriteCount,
const VkWriteDescriptorSet* pDescriptorWrites);
void encode(MVKCommandEncoder* cmdEncoder) override;
~MVKCmdPushDescriptorSet() override;
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
void clearDescriptorWrites();
VkPipelineBindPoint _pipelineBindPoint;
MVKPipelineLayout* _pipelineLayout;
MVKVectorInline<VkWriteDescriptorSet, 8> _descriptorWrites;
uint32_t _set;
};
#pragma mark -
#pragma mark MVKCmdPushDescriptorSetWithTemplate
/** Vulkan command to update a descriptor set from a template. */
class MVKCmdPushDescriptorSetWithTemplate : public MVKCommand {
public:
VkResult setContent(MVKCommandBuffer* cmdBuff,
VkDescriptorUpdateTemplateKHR descUpdateTemplate,
VkPipelineLayout layout,
uint32_t set,
const void* pData);
void encode(MVKCommandEncoder* cmdEncoder) override;
~MVKCmdPushDescriptorSetWithTemplate() override;
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
MVKDescriptorUpdateTemplate* _descUpdateTemplate;
MVKPipelineLayout* _pipelineLayout;
uint32_t _set;
void* _pData = nullptr;
};
#pragma mark -
#pragma mark MVKCmdSetResetEvent
/** Abstract Vulkan command to set or reset an event. */
class MVKCmdSetResetEvent : public MVKCommand {
public:
VkResult setContent(MVKCommandBuffer* cmdBuff,
VkEvent event,
VkPipelineStageFlags stageMask);
protected:
MVKEvent* _mvkEvent;
};
#pragma mark -
#pragma mark MVKCmdSetEvent
/** Vulkan command to set an event. */
class MVKCmdSetEvent : public MVKCmdSetResetEvent {
public:
void encode(MVKCommandEncoder* cmdEncoder) override;
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
};
#pragma mark -
#pragma mark MVKCmdResetEvent
/** Vulkan command to reset an event. */
class MVKCmdResetEvent : public MVKCmdSetResetEvent {
public:
void encode(MVKCommandEncoder* cmdEncoder) override;
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
};
#pragma mark -
#pragma mark MVKCmdWaitEvents
/** Vulkan command to wait for an event to be signaled. */
/**
* Vulkan command to wait for an event to be signaled.
* Template class to balance vector pre-allocations between very common low counts and fewer larger counts.
*/
template <size_t N>
class MVKCmdWaitEvents : public MVKCommand {
public:
VkResult setContent(MVKCommandBuffer* cmdBuff,
uint32_t eventCount,
const VkEvent* pEvents,
VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
uint32_t memoryBarrierCount,
const VkMemoryBarrier* pMemoryBarriers,
uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier* pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier* pImageMemoryBarriers);
void encode(MVKCommandEncoder* cmdEncoder) override;
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
MVKVectorInline<MVKEvent*, N> _mvkEvents;
};
// Concrete template class implementations.
typedef MVKCmdWaitEvents<1> MVKCmdWaitEvents1;
typedef MVKCmdWaitEvents<8> MVKCmdWaitEventsMulti;