Skip to content

Commit

Permalink
Merge pull request #660 from billhollings/master
Browse files Browse the repository at this point in the history
Move push constant binding to vkCmdBindPipeline() from vkCmdBindDescriptorSet().
  • Loading branch information
billhollings authored Jul 10, 2019
2 parents 9c635d2 + f46575d commit 11c96c4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
5 changes: 4 additions & 1 deletion MoltenVK/MoltenVK/Commands/MVKCommandEncoderState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
MVKPipeline* MVKPipelineCommandEncoderState::getPipeline() { return _pipeline; }

void MVKPipelineCommandEncoderState::encodeImpl(uint32_t stage) {
if (_pipeline) { _pipeline->encode(_cmdEncoder, stage); }
if (_pipeline) {
_pipeline->encode(_cmdEncoder, stage);
_pipeline->bindPushConstants(_cmdEncoder);
}
}

void MVKPipelineCommandEncoderState::resetImpl() {
Expand Down
17 changes: 11 additions & 6 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class MVKPipelineLayout : public MVKVulkanAPIDeviceObject {
uint32_t firstSet,
MVKVector<uint32_t>& dynamicOffsets);

/** Populates the specified shader converter context. */
void populateShaderConverterContext(SPIRVToMSLConversionConfiguration& context);

/** Updates a descriptor set in a command encoder. */
void pushDescriptorSet(MVKCommandEncoder* cmdEncoder,
MVKVector<VkWriteDescriptorSet>& descriptorWrites,
Expand All @@ -72,6 +69,9 @@ class MVKPipelineLayout : public MVKVulkanAPIDeviceObject {
uint32_t set,
const void* pData);

/** Populates the specified shader converter context. */
void populateShaderConverterContext(SPIRVToMSLConversionConfiguration& context);

/** Returns the current swizzle buffer bindings. */
const MVKShaderImplicitRezBinding& getSwizzleBufferIndex() { return _swizzleBufferIndex; }

Expand All @@ -96,6 +96,9 @@ class MVKPipelineLayout : public MVKVulkanAPIDeviceObject {
/** Returns the number of buffers in this layout. This is used to calculate the size of the buffer size buffer. */
uint32_t getBufferCount() { return _pushConstantsMTLResourceIndexes.getMaxBufferIndex(); }

/** Returns the push constant binding info. */
const MVKShaderResourceBinding& getPushConstantBindings() { return _pushConstantsMTLResourceIndexes; }

/** Constructs an instance for the specified device. */
MVKPipelineLayout(MVKDevice* device, const VkPipelineLayoutCreateInfo* pCreateInfo);

Expand Down Expand Up @@ -144,6 +147,9 @@ class MVKPipeline : public MVKVulkanAPIDeviceObject {
/** Binds this pipeline to the specified command encoder. */
virtual void encode(MVKCommandEncoder* cmdEncoder, uint32_t stage = 0) = 0;

/** Binds the push constants to a command encoder. */
void bindPushConstants(MVKCommandEncoder* cmdEncoder);

/** Returns the current swizzle buffer bindings. */
const MVKShaderImplicitRezBinding& getSwizzleBufferIndex() { return _swizzleBufferIndex; }

Expand All @@ -157,16 +163,15 @@ class MVKPipeline : public MVKVulkanAPIDeviceObject {
bool hasValidMTLPipelineStates() { return _hasValidMTLPipelineStates; }

/** Constructs an instance for the device. layout, and parent (which may be NULL). */
MVKPipeline(MVKDevice* device, MVKPipelineCache* pipelineCache, MVKPipeline* parent) : MVKVulkanAPIDeviceObject(device),
_pipelineCache(pipelineCache),
_fullImageViewSwizzle(device->_pMVKConfig->fullImageViewSwizzle) {}
MVKPipeline(MVKDevice* device, MVKPipelineCache* pipelineCache, MVKPipelineLayout* layout, MVKPipeline* parent);

protected:
void propogateDebugName() override {}

MVKPipelineCache* _pipelineCache;
MVKShaderImplicitRezBinding _swizzleBufferIndex;
MVKShaderImplicitRezBinding _bufferSizeBufferIndex;
MVKShaderResourceBinding _pushConstantsMTLResourceIndexes;
bool _fullImageViewSwizzle;
bool _hasValidMTLPipelineStates = true;

Expand Down
42 changes: 23 additions & 19 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@
dynamicOffsets, &pDynamicOffsetIndex);
setConfigurationResult(dsl.getConfigurationResult());
}
if (cmdEncoder) {
for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageMax; i++) {
cmdEncoder->getPushConstants(mvkVkShaderStageFlagBitsFromMVKShaderStage(MVKShaderStage(i)))->setMTLBufferIndex(_pushConstantsMTLResourceIndexes.stages[i].bufferIndex);
}
}
}

// A null cmdEncoder can be passed to perform a validation pass
Expand All @@ -68,12 +63,6 @@
auto& dsl = _descriptorSetLayouts[set];
dsl.pushDescriptorSet(cmdEncoder, descriptorWrites, _dslMTLResourceIndexOffsets[set]);
setConfigurationResult(dsl.getConfigurationResult());

if (cmdEncoder) {
for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageMax; i++) {
cmdEncoder->getPushConstants(mvkVkShaderStageFlagBitsFromMVKShaderStage(MVKShaderStage(i)))->setMTLBufferIndex(_pushConstantsMTLResourceIndexes.stages[i].bufferIndex);
}
}
}

// A null cmdEncoder can be passed to perform a validation pass
Expand All @@ -85,12 +74,6 @@
auto& dsl = _descriptorSetLayouts[set];
dsl.pushDescriptorSet(cmdEncoder, descUpdateTemplate, pData, _dslMTLResourceIndexOffsets[set]);
setConfigurationResult(dsl.getConfigurationResult());

if (cmdEncoder) {
for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageMax; i++) {
cmdEncoder->getPushConstants(mvkVkShaderStageFlagBitsFromMVKShaderStage(MVKShaderStage(i)))->setMTLBufferIndex(_pushConstantsMTLResourceIndexes.stages[i].bufferIndex);
}
}
}

void MVKPipelineLayout::populateShaderConverterContext(SPIRVToMSLConversionConfiguration& context) {
Expand Down Expand Up @@ -168,6 +151,24 @@
}


#pragma mark -
#pragma mark MVKPipeline

void MVKPipeline::bindPushConstants(MVKCommandEncoder* cmdEncoder) {
if (cmdEncoder) {
for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageMax; i++) {
cmdEncoder->getPushConstants(mvkVkShaderStageFlagBitsFromMVKShaderStage(MVKShaderStage(i)))->setMTLBufferIndex(_pushConstantsMTLResourceIndexes.stages[i].bufferIndex);
}
}
}

MVKPipeline::MVKPipeline(MVKDevice* device, MVKPipelineCache* pipelineCache, MVKPipelineLayout* layout, MVKPipeline* parent) :
MVKVulkanAPIDeviceObject(device),
_pipelineCache(pipelineCache),
_pushConstantsMTLResourceIndexes(layout->getPushConstantBindings()),
_fullImageViewSwizzle(device->_pMVKConfig->fullImageViewSwizzle) {}


#pragma mark -
#pragma mark MVKGraphicsPipeline

Expand Down Expand Up @@ -285,7 +286,8 @@
MVKGraphicsPipeline::MVKGraphicsPipeline(MVKDevice* device,
MVKPipelineCache* pipelineCache,
MVKPipeline* parent,
const VkGraphicsPipelineCreateInfo* pCreateInfo) : MVKPipeline(device, pipelineCache, parent) {
const VkGraphicsPipelineCreateInfo* pCreateInfo) :
MVKPipeline(device, pipelineCache, (MVKPipelineLayout*)pCreateInfo->layout, parent) {

// Get the tessellation shaders, if present. Do this now, because we need to extract
// reflection data from them that informs everything else.
Expand Down Expand Up @@ -1275,7 +1277,9 @@ static VkFormat mvkFormatFromOutput(const SPIRVShaderOutput& output) {
MVKComputePipeline::MVKComputePipeline(MVKDevice* device,
MVKPipelineCache* pipelineCache,
MVKPipeline* parent,
const VkComputePipelineCreateInfo* pCreateInfo) : MVKPipeline(device, pipelineCache, parent) {
const VkComputePipelineCreateInfo* pCreateInfo) :
MVKPipeline(device, pipelineCache, (MVKPipelineLayout*)pCreateInfo->layout, parent) {

MVKMTLFunction shaderFunc = getMTLFunction(pCreateInfo);
_mtlThreadgroupSize = shaderFunc.threadGroupSize;
_mtlPipelineState = nil;
Expand Down

0 comments on commit 11c96c4

Please sign in to comment.