Skip to content

Commit 26c7b69

Browse files
authored
Merge pull request #288 from billhollings/master
Update glslang version and What's New document.
2 parents dc0da2c + cded63b commit 26c7b69

15 files changed

+152
-38
lines changed

Docs/Whats_New.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ Copyright (c) 2014-2018 [The Brenwill Workshop Ltd.](http://www.brenwill.com)
1212
For best results, use a Markdown reader.*
1313

1414

15+
MoltenVK 1.0.23
16+
---------------
17+
18+
Released 2018/09/28
19+
20+
- Add support for features:
21+
- shaderStorageImageMultisample
22+
- shaderStorageImageReadWithoutFormat
23+
- shaderStorageImageWriteWithoutFormat
24+
- shaderUniformBufferArrayDynamicIndexing
25+
- shaderSampledImageArrayDynamicIndexing
26+
- shaderStorageBufferArrayDynamicIndexing
27+
- shaderStorageImageArrayDynamicIndexing
28+
- Support reduced render area
29+
- Support rasterization to missing attachment
30+
- Allocate MVKCommandBuffers from a pool within MVKCommandPool.
31+
- Update glslang version
32+
- Update to latest SPIRV-Cross version:
33+
- MSL: Improve coordinate handling for buffer reads.
34+
- MSL: Expand arrays of buffers passed as input.
35+
36+
1537
MoltenVK 1.0.22
1638
---------------
1739

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a8453d4bc00998049db0d448764784a6a0767539
1+
91ac4290bcf2cb930b4fb0981f09c00c0b6797e1

MoltenVK/MoltenVK/Commands/MVKCommand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class MVKCommand : public MVKConfigurableObject {
7777

7878
/**
7979
* Instances of this class can participate in a linked list or pool. When so participating,
80-
* this is a reference to the next command in the linked list. This value should only be
80+
* this is a reference to the next instance in the linked list. This value should only be
8181
* managed and set by the linked list.
8282
*/
8383
MVKCommand* _next = nullptr;

MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "MVKDevice.h"
2222
#include "MVKCommand.h"
2323
#include "MVKCommandEncoderState.h"
24+
#include "MVKMTLBufferAllocation.h"
2425
#include "MVKCmdPipeline.h"
2526
#include <vector>
2627
#include <unordered_map>
@@ -90,15 +91,15 @@ class MVKCommandBuffer : public MVKDispatchableDeviceObject {
9091

9192
/**
9293
* Instances of this class can participate in a linked list or pool. When so participating,
93-
* this is a reference to the next command in the linked list. This value should only be
94+
* this is a reference to the next instance in the linked list. This value should only be
9495
* managed and set by the linked list.
9596
*/
9697
MVKCommandBuffer* _next;
9798

9899

99100
#pragma mark Construction
100-
101-
MVKCommandBuffer(MVKDevice* device, const VkCommandBufferAllocateInfo* pAllocateInfo);
101+
102+
MVKCommandBuffer(MVKDevice* device) : MVKDispatchableDeviceObject(device) {}
102103

103104
~MVKCommandBuffer() override;
104105

@@ -118,7 +119,9 @@ class MVKCommandBuffer : public MVKDispatchableDeviceObject {
118119

119120
protected:
120121
friend class MVKCommandEncoder;
122+
friend class MVKCommandPool;
121123

124+
void init(const VkCommandBufferAllocateInfo* pAllocateInfo);
122125
bool canExecute();
123126
bool canPrefill();
124127
void prefill();
@@ -140,6 +143,33 @@ class MVKCommandBuffer : public MVKDispatchableDeviceObject {
140143
};
141144

142145

146+
#pragma mark -
147+
#pragma mark MVKCommandBufferPool
148+
149+
/**
150+
* A pool of MVKCommandBuffer instances.
151+
*
152+
* To return a MVKCommandBuffer retrieved from this pool, back to this pool,
153+
* call the returnToPool() function on the MVKCommandBuffer instance.
154+
*/
155+
class MVKCommandBufferPool : public MVKObjectPool<MVKCommandBuffer> {
156+
157+
public:
158+
159+
/** Returns a new command instance. */
160+
MVKCommandBuffer* newObject() override { return new MVKCommandBuffer(_device); }
161+
162+
/**
163+
* Configures this instance to either use pooling, or not, depending on the
164+
* value of isPooling, which defaults to true if not indicated explicitly.
165+
*/
166+
MVKCommandBufferPool(MVKDevice* device, bool isPooling = true) : MVKObjectPool<MVKCommandBuffer>(isPooling), _device(device) {}
167+
168+
protected:
169+
MVKDevice* _device;
170+
};
171+
172+
143173
#pragma mark -
144174
#pragma mark MVKCommandEncoder
145175

MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,9 @@
175175

176176
#pragma mark Construction
177177

178-
MVKCommandBuffer::MVKCommandBuffer(MVKDevice* device,
179-
const VkCommandBufferAllocateInfo* pAllocateInfo) : MVKDispatchableDeviceObject(device) {
180-
178+
// Initializes this instance after it has been created retrieved from a pool.
179+
void MVKCommandBuffer::init(const VkCommandBufferAllocateInfo* pAllocateInfo) {
181180
_commandPool = (MVKCommandPool*)pAllocateInfo->commandPool;
182-
_commandPool->addCommandBuffer(this);
183181
_isSecondary = (pAllocateInfo->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY);
184182
_head = nullptr;
185183
_tail = nullptr;
@@ -190,7 +188,6 @@
190188

191189
MVKCommandBuffer::~MVKCommandBuffer() {
192190
reset(0);
193-
_commandPool->removeCommandBuffer(this);
194191
}
195192

196193

MoltenVK/MoltenVK/Commands/MVKCommandEncoderState.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
#pragma once
2020

21-
#include "MVKCommandPool.h"
21+
#include "MVKMTLResourceBindings.h"
22+
#include "MVKCommandResourceFactory.h"
2223
#include <vector>
2324

2425
class MVKCommandEncoder;

MoltenVK/MoltenVK/Commands/MVKCommandEncodingPool.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class MVKCommandEncodingPool : public MVKBaseDeviceObject {
9797
/** Returns a MTLComputePipelineState for filling a buffer. */
9898
id<MTLComputePipelineState> getCmdFillBufferMTLComputePipelineState();
9999

100+
/** Deletes all the internal resources. */
101+
void clear();
102+
100103
#pragma mark Construction
101104

102105
MVKCommandEncodingPool(MVKDevice* device);

MoltenVK/MoltenVK/Commands/MVKCommandEncodingPool.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
MVK_ENC_REZ_ACCESS(_mtlFillBufferComputePipelineState, newCmdFillBufferMTLComputePipelineState());
106106
}
107107

108+
void MVKCommandEncodingPool::clear() {
109+
lock_guard<mutex> lock(_lock);
110+
destroyMetalResources();
111+
}
112+
113+
108114
#pragma mark Construction
109115

110116
MVKCommandEncodingPool::MVKCommandEncodingPool(MVKDevice* device) : MVKBaseDeviceObject(device),

MoltenVK/MoltenVK/Commands/MVKCommandPool.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#pragma once
2020

2121
#include "MVKDevice.h"
22+
#include "MVKCommandBuffer.h"
2223
#include "MVKCommandResourceFactory.h"
2324
#include "MVKCommandEncodingPool.h"
2425
#include "MVKCommand.h"
@@ -169,12 +170,10 @@ class MVKCommandPool : public MVKBaseDeviceObject {
169170

170171
~MVKCommandPool() override;
171172

172-
private:
173-
friend class MVKCommandBuffer;
174-
175-
void addCommandBuffer(MVKCommandBuffer* cmdBuffer);
176-
void removeCommandBuffer(MVKCommandBuffer* cmdBuffer);
173+
protected:
174+
void freeCommandBuffer(MVKCommandBuffer* mvkCmdBuff);
177175

176+
MVKCommandBufferPool _commandBufferPool;
178177
std::unordered_set<MVKCommandBuffer*> _commandBuffers;
179178
MVKCommandEncodingPool _commandEncodingPool;
180179
uint32_t _queueFamilyIndex;

MoltenVK/MoltenVK/Commands/MVKCommandPool.mm

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@
3333

3434
// Reset all of the command buffers
3535
VkResult MVKCommandPool::reset(VkCommandPoolResetFlags flags) {
36-
for (auto& cb : _commandBuffers) {
37-
cb->reset(VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
38-
}
36+
bool releaseRez = mvkAreFlagsEnabled(flags, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT);
37+
38+
VkCommandBufferResetFlags cmdBuffFlags = releaseRez ? VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT : 0;
39+
40+
for (auto& cb : _commandBuffers) { cb->reset(cmdBuffFlags); }
41+
42+
if (releaseRez) { trim(); }
43+
3944
return VK_SUCCESS;
4045
}
4146

@@ -47,7 +52,9 @@
4752
VkResult rslt = VK_SUCCESS;
4853
uint32_t cbCnt = pAllocateInfo->commandBufferCount;
4954
for (uint32_t cbIdx = 0; cbIdx < cbCnt; cbIdx++) {
50-
MVKCommandBuffer* mvkCmdBuff = new MVKCommandBuffer(_device, pAllocateInfo);
55+
MVKCommandBuffer* mvkCmdBuff = _commandBufferPool.acquireObject();
56+
mvkCmdBuff->init(pAllocateInfo);
57+
_commandBuffers.insert(mvkCmdBuff);
5158
pCmdBuffer[cbIdx] = mvkCmdBuff->getVkCommandBuffer();
5259
if (rslt == VK_SUCCESS) { rslt = mvkCmdBuff->getConfigurationResult(); }
5360
}
@@ -57,32 +64,74 @@
5764
void MVKCommandPool::freeCommandBuffers(uint32_t commandBufferCount,
5865
const VkCommandBuffer* pCommandBuffers) {
5966
for (uint32_t cbIdx = 0; cbIdx < commandBufferCount; cbIdx++) {
60-
VkCommandBuffer cmdBuff = pCommandBuffers[cbIdx];
61-
if (cmdBuff) { MVKCommandBuffer::getMVKCommandBuffer(cmdBuff)->destroy(); }
67+
freeCommandBuffer(MVKCommandBuffer::getMVKCommandBuffer(pCommandBuffers[cbIdx]));
6268
}
6369
}
6470

65-
id<MTLCommandBuffer> MVKCommandPool::newMTLCommandBuffer(uint32_t queueIndex) {
66-
return [[_device->getQueue(_queueFamilyIndex, queueIndex)->getMTLCommandQueue() commandBuffer] retain];
67-
}
71+
void MVKCommandPool::freeCommandBuffer(MVKCommandBuffer* mvkCmdBuff) {
72+
if ( !mvkCmdBuff ) { return; }
6873

69-
void MVKCommandPool::trim() {
70-
// TODO: Implement.
74+
mvkCmdBuff->reset(VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
75+
_commandBuffers.erase(mvkCmdBuff);
76+
_commandBufferPool.returnObject(mvkCmdBuff);
7177
}
7278

73-
void MVKCommandPool::addCommandBuffer(MVKCommandBuffer* cmdBuffer) {
74-
_commandBuffers.insert(cmdBuffer);
79+
id<MTLCommandBuffer> MVKCommandPool::newMTLCommandBuffer(uint32_t queueIndex) {
80+
return [[_device->getQueue(_queueFamilyIndex, queueIndex)->getMTLCommandQueue() commandBuffer] retain];
7581
}
7682

77-
void MVKCommandPool::removeCommandBuffer(MVKCommandBuffer* cmdBuffer) {
78-
_commandBuffers.erase(cmdBuffer);
83+
void MVKCommandPool::trim() {
84+
_commandBufferPool.clear();
85+
_commandEncodingPool.clear();
86+
_cmdPipelineBarrierPool.clear();
87+
_cmdBindPipelinePool.clear();
88+
_cmdBeginRenderPassPool.clear();
89+
_cmdNextSubpassPool.clear();
90+
_cmdExecuteCommandsPool.clear();
91+
_cmdEndRenderPassPool.clear();
92+
_cmdBindDescriptorSetsPool.clear();
93+
_cmdSetViewportPool.clear();
94+
_cmdSetScissorPool.clear();
95+
_cmdSetLineWidthPool.clear();
96+
_cmdSetDepthBiasPool.clear();
97+
_cmdSetBlendConstantsPool.clear();
98+
_cmdSetDepthBoundsPool.clear();
99+
_cmdSetStencilCompareMaskPool.clear();
100+
_cmdSetStencilWriteMaskPool.clear();
101+
_cmdSetStencilReferencePool.clear();
102+
_cmdBindVertexBuffersPool.clear();
103+
_cmdBindIndexBufferPool.clear();
104+
_cmdDrawPool.clear();
105+
_cmdDrawIndexedPool.clear();
106+
_cmdDrawIndirectPool.clear();
107+
_cmdDrawIndexedIndirectPool.clear();
108+
_cmdCopyImagePool.clear();
109+
_cmdBlitImagePool.clear();
110+
_cmdResolveImagePool.clear();
111+
_cmdFillBufferPool.clear();
112+
_cmdUpdateBufferPool.clear();
113+
_cmdCopyBufferPool.clear();
114+
_cmdBufferImageCopyPool.clear();
115+
_cmdClearAttachmentsPool.clear();
116+
_cmdClearImagePool.clear();
117+
_cmdBeginQueryPool.clear();
118+
_cmdEndQueryPool.clear();
119+
_cmdWriteTimestampPool.clear();
120+
_cmdResetQueryPoolPool.clear();
121+
_cmdCopyQueryPoolResultsPool.clear();
122+
_cmdPushConstantsPool.clear();
123+
_cmdDispatchPool.clear();
124+
_cmdDispatchIndirectPool.clear();
125+
_cmdPushDescriptorSetPool.clear();
126+
_cmdPushSetWithTemplatePool.clear();
79127
}
80128

81129

82130
#pragma mark Construction
83131

84132
MVKCommandPool::MVKCommandPool(MVKDevice* device,
85133
const VkCommandPoolCreateInfo* pCreateInfo) : MVKBaseDeviceObject(device),
134+
_commandBufferPool(device),
86135
_commandEncodingPool(device),
87136
_queueFamilyIndex(pCreateInfo->queueFamilyIndex),
88137
_cmdPipelineBarrierPool(this, true),
@@ -128,7 +177,8 @@
128177
_cmdPushSetWithTemplatePool(this, true)
129178
{}
130179

131-
// TODO: Destroying a command pool implicitly destroys all command buffers and commands created from it.
132-
133-
MVKCommandPool::~MVKCommandPool() {}
180+
MVKCommandPool::~MVKCommandPool() {
181+
auto cmdBuffs = _commandBuffers;
182+
for (auto& cb : cmdBuffs) { freeCommandBuffer(cb); }
183+
}
134184

0 commit comments

Comments
 (0)