MVKArrayRef cleanup
Make everything constexpr, remove direct access to members
This commit is contained in:
parent
89195dc725
commit
4ba3f335b4
@ -472,8 +472,8 @@ void MVKCommandEncoder::beginRenderpass(MVKCommand* passCmd,
|
|||||||
_attachments.assign(attachments.begin(), attachments.end());
|
_attachments.assign(attachments.begin(), attachments.end());
|
||||||
|
|
||||||
// Copy the sample positions array of arrays, one array of sample positions for each subpass index.
|
// Copy the sample positions array of arrays, one array of sample positions for each subpass index.
|
||||||
_subpassSamplePositions.resize(subpassSamplePositions.size);
|
_subpassSamplePositions.resize(subpassSamplePositions.size());
|
||||||
for (uint32_t spSPIdx = 0; spSPIdx < subpassSamplePositions.size; spSPIdx++) {
|
for (uint32_t spSPIdx = 0; spSPIdx < subpassSamplePositions.size(); spSPIdx++) {
|
||||||
_subpassSamplePositions[spSPIdx].assign(subpassSamplePositions[spSPIdx].begin(),
|
_subpassSamplePositions[spSPIdx].assign(subpassSamplePositions[spSPIdx].begin(),
|
||||||
subpassSamplePositions[spSPIdx].end());
|
subpassSamplePositions[spSPIdx].end());
|
||||||
}
|
}
|
||||||
@ -593,7 +593,7 @@ void MVKCommandEncoder::beginMetalRenderPass(MVKCommandUse cmdUse) {
|
|||||||
// and Metal will default to using default sample postions.
|
// and Metal will default to using default sample postions.
|
||||||
if (_pDeviceMetalFeatures->programmableSamplePositions) {
|
if (_pDeviceMetalFeatures->programmableSamplePositions) {
|
||||||
auto cstmSampPosns = getCustomSamplePositions();
|
auto cstmSampPosns = getCustomSamplePositions();
|
||||||
[mtlRPDesc setSamplePositions: cstmSampPosns.data count: cstmSampPosns.size];
|
[mtlRPDesc setSamplePositions: cstmSampPosns.data() count: cstmSampPosns.size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
_mtlRenderEncoder = [_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPDesc];
|
_mtlRenderEncoder = [_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPDesc];
|
||||||
|
@ -58,7 +58,7 @@ void MVKViewportCommandEncoderState::setViewports(const MVKArrayRef<VkViewport>
|
|||||||
uint32_t firstViewport,
|
uint32_t firstViewport,
|
||||||
bool isSettingDynamically) {
|
bool isSettingDynamically) {
|
||||||
|
|
||||||
size_t vpCnt = viewports.size;
|
size_t vpCnt = viewports.size();
|
||||||
uint32_t maxViewports = getDevice()->_pProperties->limits.maxViewports;
|
uint32_t maxViewports = getDevice()->_pProperties->limits.maxViewports;
|
||||||
if ((firstViewport + vpCnt > maxViewports) ||
|
if ((firstViewport + vpCnt > maxViewports) ||
|
||||||
(firstViewport >= maxViewports) ||
|
(firstViewport >= maxViewports) ||
|
||||||
@ -111,7 +111,7 @@ void MVKScissorCommandEncoderState::setScissors(const MVKArrayRef<VkRect2D> scis
|
|||||||
uint32_t firstScissor,
|
uint32_t firstScissor,
|
||||||
bool isSettingDynamically) {
|
bool isSettingDynamically) {
|
||||||
|
|
||||||
size_t sCnt = scissors.size;
|
size_t sCnt = scissors.size();
|
||||||
uint32_t maxScissors = getDevice()->_pProperties->limits.maxViewports;
|
uint32_t maxScissors = getDevice()->_pProperties->limits.maxViewports;
|
||||||
if ((firstScissor + sCnt > maxScissors) ||
|
if ((firstScissor + sCnt > maxScissors) ||
|
||||||
(firstScissor >= maxScissors) ||
|
(firstScissor >= maxScissors) ||
|
||||||
@ -165,7 +165,7 @@ void MVKPushConstantsCommandEncoderState:: setPushConstants(uint32_t offset, MVK
|
|||||||
// Typically any MSL struct that contains a float4 will also have a size that is rounded up to a multiple of a float4 size.
|
// Typically any MSL struct that contains a float4 will also have a size that is rounded up to a multiple of a float4 size.
|
||||||
// Ensure that we pass along enough content to cover this extra space even if it is never actually accessed by the shader.
|
// Ensure that we pass along enough content to cover this extra space even if it is never actually accessed by the shader.
|
||||||
size_t pcSizeAlign = getDevice()->_pMetalFeatures->pushConstantSizeAlignment;
|
size_t pcSizeAlign = getDevice()->_pMetalFeatures->pushConstantSizeAlignment;
|
||||||
size_t pcSize = pushConstants.size;
|
size_t pcSize = pushConstants.size();
|
||||||
size_t pcBuffSize = mvkAlignByteCount(offset + pcSize, pcSizeAlign);
|
size_t pcBuffSize = mvkAlignByteCount(offset + pcSize, pcSizeAlign);
|
||||||
mvkEnsureSize(_pushConstants, pcBuffSize);
|
mvkEnsureSize(_pushConstants, pcBuffSize);
|
||||||
copy(pushConstants.begin(), pushConstants.end(), _pushConstants.begin() + offset);
|
copy(pushConstants.begin(), pushConstants.end(), _pushConstants.begin() + offset);
|
||||||
@ -488,7 +488,7 @@ void MVKResourcesCommandEncoderState::bindDescriptorSet(uint32_t descSetIndex,
|
|||||||
// Update dynamic buffer offsets
|
// Update dynamic buffer offsets
|
||||||
uint32_t baseDynOfstIdx = dslMTLRezIdxOffsets.getMetalResourceIndexes().dynamicOffsetBufferIndex;
|
uint32_t baseDynOfstIdx = dslMTLRezIdxOffsets.getMetalResourceIndexes().dynamicOffsetBufferIndex;
|
||||||
uint32_t doCnt = descSet->getDynamicOffsetDescriptorCount();
|
uint32_t doCnt = descSet->getDynamicOffsetDescriptorCount();
|
||||||
for (uint32_t doIdx = 0; doIdx < doCnt && dynamicOffsetIndex < dynamicOffsets.size; doIdx++) {
|
for (uint32_t doIdx = 0; doIdx < doCnt && dynamicOffsetIndex < dynamicOffsets.size(); doIdx++) {
|
||||||
updateImplicitBuffer(_dynamicOffsets, baseDynOfstIdx + doIdx, dynamicOffsets[dynamicOffsetIndex++]);
|
updateImplicitBuffer(_dynamicOffsets, baseDynOfstIdx + doIdx, dynamicOffsets[dynamicOffsetIndex++]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -797,8 +797,8 @@ void MVKGraphicsResourcesCommandEncoderState::encodeImpl(uint32_t stage) {
|
|||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
||||||
cmdEncoder->setComputeBytes(cmdEncoder->getMTLComputeEncoder(kMVKCommandUseTessellationVertexTessCtl),
|
cmdEncoder->setComputeBytes(cmdEncoder->getMTLComputeEncoder(kMVKCommandUseTessellationVertexTessCtl),
|
||||||
s.data,
|
s.data(),
|
||||||
s.size * sizeof(uint32_t),
|
s.byteSize(),
|
||||||
b.index);
|
b.index);
|
||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
||||||
@ -848,8 +848,8 @@ void MVKGraphicsResourcesCommandEncoderState::encodeImpl(uint32_t stage) {
|
|||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
||||||
cmdEncoder->setVertexBytes(cmdEncoder->_mtlRenderEncoder,
|
cmdEncoder->setVertexBytes(cmdEncoder->_mtlRenderEncoder,
|
||||||
s.data,
|
s.data(),
|
||||||
s.size * sizeof(uint32_t),
|
s.byteSize(),
|
||||||
b.index);
|
b.index);
|
||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
||||||
@ -881,8 +881,8 @@ void MVKGraphicsResourcesCommandEncoderState::encodeImpl(uint32_t stage) {
|
|||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
||||||
cmdEncoder->setComputeBytes(cmdEncoder->getMTLComputeEncoder(kMVKCommandUseTessellationVertexTessCtl),
|
cmdEncoder->setComputeBytes(cmdEncoder->getMTLComputeEncoder(kMVKCommandUseTessellationVertexTessCtl),
|
||||||
s.data,
|
s.data(),
|
||||||
s.size * sizeof(uint32_t),
|
s.byteSize(),
|
||||||
b.index);
|
b.index);
|
||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
||||||
@ -914,8 +914,8 @@ void MVKGraphicsResourcesCommandEncoderState::encodeImpl(uint32_t stage) {
|
|||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
||||||
cmdEncoder->setVertexBytes(cmdEncoder->_mtlRenderEncoder,
|
cmdEncoder->setVertexBytes(cmdEncoder->_mtlRenderEncoder,
|
||||||
s.data,
|
s.data(),
|
||||||
s.size * sizeof(uint32_t),
|
s.byteSize(),
|
||||||
b.index);
|
b.index);
|
||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
||||||
@ -947,8 +947,8 @@ void MVKGraphicsResourcesCommandEncoderState::encodeImpl(uint32_t stage) {
|
|||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLBufferBinding& b, const MVKArrayRef<uint32_t> s)->void {
|
||||||
cmdEncoder->setFragmentBytes(cmdEncoder->_mtlRenderEncoder,
|
cmdEncoder->setFragmentBytes(cmdEncoder->_mtlRenderEncoder,
|
||||||
s.data,
|
s.data(),
|
||||||
s.size * sizeof(uint32_t),
|
s.byteSize(),
|
||||||
b.index);
|
b.index);
|
||||||
},
|
},
|
||||||
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
[](MVKCommandEncoder* cmdEncoder, MVKMTLTextureBinding& b)->void {
|
||||||
|
@ -729,7 +729,7 @@ void MVKBufferDescriptor::bind(MVKCommandEncoder* cmdEncoder,
|
|||||||
MVKArrayRef<uint32_t> dynamicOffsets,
|
MVKArrayRef<uint32_t> dynamicOffsets,
|
||||||
uint32_t& dynamicOffsetIndex) {
|
uint32_t& dynamicOffsetIndex) {
|
||||||
MVKMTLBufferBinding bb;
|
MVKMTLBufferBinding bb;
|
||||||
NSUInteger bufferDynamicOffset = (usesDynamicBufferOffsets() && dynamicOffsets.size > dynamicOffsetIndex
|
NSUInteger bufferDynamicOffset = (usesDynamicBufferOffsets() && dynamicOffsets.size() > dynamicOffsetIndex
|
||||||
? dynamicOffsets[dynamicOffsetIndex++] : 0);
|
? dynamicOffsets[dynamicOffsetIndex++] : 0);
|
||||||
if (_mvkBuffer) {
|
if (_mvkBuffer) {
|
||||||
bb.mtlBuffer = _mvkBuffer->getMTLBuffer();
|
bb.mtlBuffer = _mvkBuffer->getMTLBuffer();
|
||||||
|
@ -1530,7 +1530,7 @@ MVKArrayRef<MVKQueueFamily*> MVKPhysicalDevice::getQueueFamilies() {
|
|||||||
VkResult MVKPhysicalDevice::getQueueFamilyProperties(uint32_t* pCount,
|
VkResult MVKPhysicalDevice::getQueueFamilyProperties(uint32_t* pCount,
|
||||||
VkQueueFamilyProperties* pQueueFamilyProperties) {
|
VkQueueFamilyProperties* pQueueFamilyProperties) {
|
||||||
auto qFams = getQueueFamilies();
|
auto qFams = getQueueFamilies();
|
||||||
uint32_t qfCnt = uint32_t(qFams.size);
|
uint32_t qfCnt = uint32_t(qFams.size());
|
||||||
|
|
||||||
// If properties aren't actually being requested yet, simply update the returned count
|
// If properties aren't actually being requested yet, simply update the returned count
|
||||||
if ( !pQueueFamilyProperties ) {
|
if ( !pQueueFamilyProperties ) {
|
||||||
|
@ -49,7 +49,7 @@ void MVKPipelineLayout::bindDescriptorSets(MVKCommandEncoder* cmdEncoder,
|
|||||||
MVKArrayRef<uint32_t> dynamicOffsets) {
|
MVKArrayRef<uint32_t> dynamicOffsets) {
|
||||||
if (!cmdEncoder) { clearConfigurationResult(); }
|
if (!cmdEncoder) { clearConfigurationResult(); }
|
||||||
uint32_t dynamicOffsetIndex = 0;
|
uint32_t dynamicOffsetIndex = 0;
|
||||||
size_t dsCnt = descriptorSets.size;
|
size_t dsCnt = descriptorSets.size();
|
||||||
for (uint32_t dsIdx = 0; dsIdx < dsCnt; dsIdx++) {
|
for (uint32_t dsIdx = 0; dsIdx < dsCnt; dsIdx++) {
|
||||||
MVKDescriptorSet* descSet = descriptorSets[dsIdx];
|
MVKDescriptorSet* descSet = descriptorSets[dsIdx];
|
||||||
uint32_t dslIdx = firstSet + dsIdx;
|
uint32_t dslIdx = firstSet + dsIdx;
|
||||||
|
@ -478,20 +478,23 @@ std::size_t mvkHash(const N* pVals, std::size_t count = 1, std::size_t seed = 53
|
|||||||
*/
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
struct MVKArrayRef {
|
struct MVKArrayRef {
|
||||||
Type* data;
|
public:
|
||||||
const size_t size;
|
constexpr const Type* begin() const { return _data; }
|
||||||
|
constexpr const Type* end() const { return &_data[_size]; }
|
||||||
|
constexpr const Type* data() const { return _data; }
|
||||||
|
constexpr Type* begin() { return _data; }
|
||||||
|
constexpr Type* end() { return &_data[_size]; }
|
||||||
|
constexpr Type* data() { return _data; }
|
||||||
|
constexpr const size_t size() const { return _size; }
|
||||||
|
constexpr const size_t byteSize() const { return _size * sizeof(Type); }
|
||||||
|
constexpr const Type& operator[]( const size_t i ) const { return _data[i]; }
|
||||||
|
constexpr Type& operator[]( const size_t i ) { return _data[i]; }
|
||||||
|
constexpr MVKArrayRef() : MVKArrayRef(nullptr, 0) {}
|
||||||
|
constexpr MVKArrayRef(Type* d, size_t s) : _data(d), _size(s) {}
|
||||||
|
|
||||||
const Type* begin() const { return data; }
|
protected:
|
||||||
const Type* end() const { return &data[size]; }
|
Type* _data;
|
||||||
const Type& operator[]( const size_t i ) const { return data[i]; }
|
size_t _size;
|
||||||
Type& operator[]( const size_t i ) { return data[i]; }
|
|
||||||
MVKArrayRef<Type>& operator=(const MVKArrayRef<Type>& other) {
|
|
||||||
data = other.data;
|
|
||||||
*(size_t*)&size = other.size;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
MVKArrayRef() : MVKArrayRef(nullptr, 0) {}
|
|
||||||
MVKArrayRef(Type* d, size_t s) : data(d), size(s) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Ensures the size of the specified container is at least the specified size. */
|
/** Ensures the size of the specified container is at least the specified size. */
|
||||||
|
@ -1964,7 +1964,7 @@ static void mvkCmdBeginRenderPass(
|
|||||||
|
|
||||||
MVKAddCmdFrom5Thresholds(BeginRenderPass,
|
MVKAddCmdFrom5Thresholds(BeginRenderPass,
|
||||||
pRenderPassBegin->clearValueCount, 1, 2,
|
pRenderPassBegin->clearValueCount, 1, 2,
|
||||||
attachments.size, 0, 1, 2,
|
attachments.size(), 0, 1, 2,
|
||||||
commandBuffer,
|
commandBuffer,
|
||||||
pRenderPassBegin,
|
pRenderPassBegin,
|
||||||
pSubpassBeginInfo,
|
pSubpassBeginInfo,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user