Replaced _mtlBuffer by a malloc of _buffer and _length.
Added comments about why the third parameter of read() and write() is different.
This commit is contained in:
parent
4a09c7aa20
commit
82a07ed468
@ -115,6 +115,7 @@ public:
|
|||||||
~MVKDescriptorSetLayoutBinding() override;
|
~MVKDescriptorSetLayoutBinding() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
friend class MVKInlineUniformBlockDescriptor;
|
||||||
void initMetalResourceIndexOffsets(MVKShaderStageResourceBinding* pBindingIndexes,
|
void initMetalResourceIndexOffsets(MVKShaderStageResourceBinding* pBindingIndexes,
|
||||||
MVKShaderStageResourceBinding* pDescSetCounts,
|
MVKShaderStageResourceBinding* pDescSetCounts,
|
||||||
const VkDescriptorSetLayoutBinding* pBinding);
|
const VkDescriptorSetLayoutBinding* pBinding);
|
||||||
@ -152,11 +153,12 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the internal binding from the specified content. The format of the content depends
|
* Updates the internal binding from the specified content. The format of the content depends
|
||||||
* on the descriptor type, and is extracted from pData at the location given by srcIndex * stride.
|
* on the descriptor type, and is extracted from pData at the location given by index * stride.
|
||||||
|
* MVKInlineUniformBlockDescriptor uses the index as byte offset to write to.
|
||||||
*/
|
*/
|
||||||
virtual void write(MVKDescriptorSet* mvkDescSet,
|
virtual void write(MVKDescriptorSet* mvkDescSet,
|
||||||
VkDescriptorType descriptorType,
|
VkDescriptorType descriptorType,
|
||||||
uint32_t srcIndex,
|
uint32_t index,
|
||||||
size_t stride,
|
size_t stride,
|
||||||
const void* pData) = 0;
|
const void* pData) = 0;
|
||||||
|
|
||||||
@ -167,12 +169,13 @@ public:
|
|||||||
* specified pImageInfo, pBufferInfo, or pTexelBufferView arrays, and the other
|
* specified pImageInfo, pBufferInfo, or pTexelBufferView arrays, and the other
|
||||||
* arrays are ignored (and may be a null pointer).
|
* arrays are ignored (and may be a null pointer).
|
||||||
*
|
*
|
||||||
* The dstIndex parameter indicates the index of the initial descriptor element
|
* The index parameter indicates the index of the initial descriptor element
|
||||||
* at which to start writing.
|
* at which to start writing.
|
||||||
|
* MVKInlineUniformBlockDescriptor uses the index as byte offset to read from.
|
||||||
*/
|
*/
|
||||||
virtual void read(MVKDescriptorSet* mvkDescSet,
|
virtual void read(MVKDescriptorSet* mvkDescSet,
|
||||||
VkDescriptorType descriptorType,
|
VkDescriptorType descriptorType,
|
||||||
uint32_t dstIndex,
|
uint32_t index,
|
||||||
VkDescriptorImageInfo* pImageInfo,
|
VkDescriptorImageInfo* pImageInfo,
|
||||||
VkDescriptorBufferInfo* pBufferInfo,
|
VkDescriptorBufferInfo* pBufferInfo,
|
||||||
VkBufferView* pTexelBufferView,
|
VkBufferView* pTexelBufferView,
|
||||||
@ -284,13 +287,13 @@ public:
|
|||||||
|
|
||||||
void write(MVKDescriptorSet* mvkDescSet,
|
void write(MVKDescriptorSet* mvkDescSet,
|
||||||
VkDescriptorType descriptorType,
|
VkDescriptorType descriptorType,
|
||||||
uint32_t dstIndex,
|
uint32_t dstOffset, // For inline buffers we are using this parameter as dst offset not as src descIdx
|
||||||
size_t stride,
|
size_t stride,
|
||||||
const void* pData) override;
|
const void* pData) override;
|
||||||
|
|
||||||
void read(MVKDescriptorSet* mvkDescSet,
|
void read(MVKDescriptorSet* mvkDescSet,
|
||||||
VkDescriptorType descriptorType,
|
VkDescriptorType descriptorType,
|
||||||
uint32_t srcIndex,
|
uint32_t srcOffset, // For inline buffers we are using this parameter as src offset not as dst descIdx
|
||||||
VkDescriptorImageInfo* pImageInfo,
|
VkDescriptorImageInfo* pImageInfo,
|
||||||
VkDescriptorBufferInfo* pBufferInfo,
|
VkDescriptorBufferInfo* pBufferInfo,
|
||||||
VkBufferView* pTexelBufferView,
|
VkBufferView* pTexelBufferView,
|
||||||
@ -303,7 +306,8 @@ public:
|
|||||||
~MVKInlineUniformBlockDescriptor() { reset(); }
|
~MVKInlineUniformBlockDescriptor() { reset(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
id<MTLBuffer> _mtlBuffer = nil;
|
uint8_t* _buffer = nullptr;
|
||||||
|
uint32_t _length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,18 +89,12 @@ uint32_t MVKDescriptorSetLayoutBinding::bind(MVKCommandEncoder* cmdEncoder,
|
|||||||
// Establish the resource indices to use, by combining the offsets of the DSL and this DSL binding.
|
// Establish the resource indices to use, by combining the offsets of the DSL and this DSL binding.
|
||||||
MVKShaderResourceBinding mtlIdxs = _mtlResourceIndexOffsets + dslMTLRezIdxOffsets;
|
MVKShaderResourceBinding mtlIdxs = _mtlResourceIndexOffsets + dslMTLRezIdxOffsets;
|
||||||
|
|
||||||
if (_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
uint32_t descCnt = getDescriptorCount();
|
||||||
MVKDescriptor* mvkDesc = descSet->getDescriptor(descStartIndex);
|
for (uint32_t descIdx = 0; descIdx < descCnt; descIdx++) {
|
||||||
mvkDesc->bind(cmdEncoder, _info.descriptorType, 0, _applyToStage, mtlIdxs, dynamicOffsets, pDynamicOffsetIndex);
|
MVKDescriptor* mvkDesc = descSet->getDescriptor(descStartIndex + descIdx);
|
||||||
return 1;
|
mvkDesc->bind(cmdEncoder, _info.descriptorType, descIdx, _applyToStage, mtlIdxs, dynamicOffsets, pDynamicOffsetIndex);
|
||||||
} else {
|
|
||||||
uint32_t descCnt = _info.descriptorCount;
|
|
||||||
for (uint32_t descIdx = 0; descIdx < descCnt; descIdx++) {
|
|
||||||
MVKDescriptor* mvkDesc = descSet->getDescriptor(descStartIndex + descIdx);
|
|
||||||
mvkDesc->bind(cmdEncoder, _info.descriptorType, descIdx, _applyToStage, mtlIdxs, dynamicOffsets, pDynamicOffsetIndex);
|
|
||||||
}
|
|
||||||
return descCnt;
|
|
||||||
}
|
}
|
||||||
|
return descCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -611,11 +605,10 @@ void MVKInlineUniformBlockDescriptor::bind(MVKCommandEncoder* cmdEncoder,
|
|||||||
MVKArrayRef<uint32_t> dynamicOffsets,
|
MVKArrayRef<uint32_t> dynamicOffsets,
|
||||||
uint32_t* pDynamicOffsetIndex) {
|
uint32_t* pDynamicOffsetIndex) {
|
||||||
MVKMTLBufferBinding bb;
|
MVKMTLBufferBinding bb;
|
||||||
|
|
||||||
switch (descriptorType) {
|
switch (descriptorType) {
|
||||||
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: {
|
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: {
|
||||||
bb.mtlBytes = _mtlBuffer.contents;
|
bb.mtlBytes = _buffer;
|
||||||
bb.size = (uint32_t)_mtlBuffer.length;
|
bb.size = _length;
|
||||||
bb.isInline = true;
|
bb.isInline = true;
|
||||||
for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageMax; i++) {
|
for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageMax; i++) {
|
||||||
if (stages[i]) {
|
if (stages[i]) {
|
||||||
@ -637,16 +630,14 @@ void MVKInlineUniformBlockDescriptor::bind(MVKCommandEncoder* cmdEncoder,
|
|||||||
|
|
||||||
void MVKInlineUniformBlockDescriptor::write(MVKDescriptorSet* mvkDescSet,
|
void MVKInlineUniformBlockDescriptor::write(MVKDescriptorSet* mvkDescSet,
|
||||||
VkDescriptorType descriptorType,
|
VkDescriptorType descriptorType,
|
||||||
uint32_t dstIndex,
|
uint32_t dstOffset,
|
||||||
size_t stride,
|
size_t stride,
|
||||||
const void* pData) {
|
const void* pData) {
|
||||||
switch (descriptorType) {
|
switch (descriptorType) {
|
||||||
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: {
|
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: {
|
||||||
const auto& pInlineUniformBlock = *(VkWriteDescriptorSetInlineUniformBlockEXT*)pData;
|
const auto& pInlineUniformBlock = *(VkWriteDescriptorSetInlineUniformBlockEXT*)pData;
|
||||||
uint8_t* pDstData = (uint8_t*)_mtlBuffer.contents;
|
if (pInlineUniformBlock.pData && _buffer) {
|
||||||
uint8_t* pSrcData = (uint8_t*)pInlineUniformBlock.pData;
|
memcpy(_buffer + dstOffset, pInlineUniformBlock.pData, pInlineUniformBlock.dataSize);
|
||||||
if (pSrcData && pDstData) {
|
|
||||||
memcpy(pDstData + dstIndex, pSrcData, pInlineUniformBlock.dataSize);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -658,17 +649,15 @@ void MVKInlineUniformBlockDescriptor::write(MVKDescriptorSet* mvkDescSet,
|
|||||||
|
|
||||||
void MVKInlineUniformBlockDescriptor::read(MVKDescriptorSet* mvkDescSet,
|
void MVKInlineUniformBlockDescriptor::read(MVKDescriptorSet* mvkDescSet,
|
||||||
VkDescriptorType descriptorType,
|
VkDescriptorType descriptorType,
|
||||||
uint32_t srcIndex,
|
uint32_t srcOffset,
|
||||||
VkDescriptorImageInfo* pImageInfo,
|
VkDescriptorImageInfo* pImageInfo,
|
||||||
VkDescriptorBufferInfo* pBufferInfo,
|
VkDescriptorBufferInfo* pBufferInfo,
|
||||||
VkBufferView* pTexelBufferView,
|
VkBufferView* pTexelBufferView,
|
||||||
VkWriteDescriptorSetInlineUniformBlockEXT* pInlineUniformBlock) {
|
VkWriteDescriptorSetInlineUniformBlockEXT* pInlineUniformBlock) {
|
||||||
switch (descriptorType) {
|
switch (descriptorType) {
|
||||||
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: {
|
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: {
|
||||||
uint8_t* pDstData = (uint8_t*)pInlineUniformBlock->pData;
|
if (_buffer && pInlineUniformBlock->pData) {
|
||||||
uint8_t* pSrcData = (uint8_t*)_mtlBuffer.contents;
|
memcpy((void*)pInlineUniformBlock->pData, _buffer + srcOffset, pInlineUniformBlock->dataSize);
|
||||||
if (pSrcData && pDstData) {
|
|
||||||
memcpy(pDstData, pSrcData + srcIndex, pInlineUniformBlock->dataSize);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -679,13 +668,14 @@ void MVKInlineUniformBlockDescriptor::read(MVKDescriptorSet* mvkDescSet,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MVKInlineUniformBlockDescriptor::setLayout(MVKDescriptorSetLayoutBinding* dslBinding, uint32_t index) {
|
void MVKInlineUniformBlockDescriptor::setLayout(MVKDescriptorSetLayoutBinding* dslBinding, uint32_t index) {
|
||||||
_mtlBuffer = [dslBinding->getMTLDevice() newBufferWithLength: dslBinding->getDescriptorCount()
|
_length = dslBinding->_info.descriptorCount;
|
||||||
options: MTLResourceStorageModeShared | MTLResourceCPUCacheModeDefaultCache]; // retained
|
_buffer = (uint8_t*)malloc(_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MVKInlineUniformBlockDescriptor::reset() {
|
void MVKInlineUniformBlockDescriptor::reset() {
|
||||||
[_mtlBuffer release];
|
free(_buffer);
|
||||||
_mtlBuffer = nil;
|
_buffer = nullptr;
|
||||||
|
_length = 0;
|
||||||
MVKDescriptor::reset();
|
MVKDescriptor::reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +212,7 @@ void MVKDescriptorSet::write(const DescriptorAction* pDescriptorAction,
|
|||||||
uint32_t descCnt = pDescriptorAction->descriptorCount;
|
uint32_t descCnt = pDescriptorAction->descriptorCount;
|
||||||
if (descType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
if (descType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
||||||
uint32_t dstStartIdx = _layout->getDescriptorIndex(pDescriptorAction->dstBinding, 0);
|
uint32_t dstStartIdx = _layout->getDescriptorIndex(pDescriptorAction->dstBinding, 0);
|
||||||
|
// For inline buffers we are using the index argument as dst offset not as src descIdx
|
||||||
_descriptors[dstStartIdx]->write(this, descType, pDescriptorAction->dstArrayElement, stride, pData);
|
_descriptors[dstStartIdx]->write(this, descType, pDescriptorAction->dstArrayElement, stride, pData);
|
||||||
} else {
|
} else {
|
||||||
uint32_t dstStartIdx = _layout->getDescriptorIndex(pDescriptorAction->dstBinding,
|
uint32_t dstStartIdx = _layout->getDescriptorIndex(pDescriptorAction->dstBinding,
|
||||||
@ -241,6 +242,7 @@ void MVKDescriptorSet::read(const VkCopyDescriptorSet* pDescriptorCopy,
|
|||||||
if (descType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
if (descType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
||||||
pInlineUniformBlock->dataSize = pDescriptorCopy->descriptorCount;
|
pInlineUniformBlock->dataSize = pDescriptorCopy->descriptorCount;
|
||||||
uint32_t srcStartIdx = _layout->getDescriptorIndex(pDescriptorCopy->srcBinding, 0);
|
uint32_t srcStartIdx = _layout->getDescriptorIndex(pDescriptorCopy->srcBinding, 0);
|
||||||
|
// For inline buffers we are using the index argument as src offset not as dst descIdx
|
||||||
_descriptors[srcStartIdx]->read(this, descType, pDescriptorCopy->srcArrayElement, pImageInfo, pBufferInfo, pTexelBufferView, pInlineUniformBlock);
|
_descriptors[srcStartIdx]->read(this, descType, pDescriptorCopy->srcArrayElement, pImageInfo, pBufferInfo, pTexelBufferView, pInlineUniformBlock);
|
||||||
} else {
|
} else {
|
||||||
uint32_t srcStartIdx = _layout->getDescriptorIndex(pDescriptorCopy->srcBinding,
|
uint32_t srcStartIdx = _layout->getDescriptorIndex(pDescriptorCopy->srcBinding,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user