Skip to content

Commit fb034cc

Browse files
committed
mantle: added quirk for internal synchronization of descriptor set access
Star Swarm doesn't care about synchronizing access to descriptor sets, so sometimes it crashes with normal descriptor sets and crashes almost immediately with descriptor buffers.
1 parent 6093661 commit fb034cc

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/mantle/mantle_descriptor_set.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ GR_RESULT GR_STDCALL grCreateDescriptorSet(
195195
.grObj = { GR_OBJ_TYPE_DESCRIPTOR_SET, grDevice },
196196
.slotCount = pCreateInfo->slots,
197197
.slots = calloc(pCreateInfo->slots, sizeof(DescriptorSetSlot)),
198+
.descriptorLock = SRWLOCK_INIT,
198199
.descriptorPool = descriptorPool,
199200
.descriptorSet = descriptorSet,
200201
.descriptorBufferPtr = descriptorBufferPtr,
@@ -246,6 +247,10 @@ GR_VOID GR_STDCALL grAttachSamplerDescriptors(
246247
GrDescriptorSet* grDescriptorSet = (GrDescriptorSet*)descriptorSet;
247248
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
248249

250+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
251+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
252+
}
253+
249254
if (grDevice->descriptorBufferSupported && grDevice->descriptorBufferAllowPreparedSampler) {
250255
for (unsigned i = 0; i < slotCount; i++) {
251256
const GrSampler* grSampler = (GrSampler*)pSamplers[i];
@@ -311,6 +316,9 @@ GR_VOID GR_STDCALL grAttachSamplerDescriptors(
311316
STACK_ARRAY_FINISH(writeDescriptors);
312317
}
313318

319+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
320+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
321+
}
314322
}
315323

316324
GR_VOID GR_STDCALL grAttachImageViewDescriptors(
@@ -323,6 +331,10 @@ GR_VOID GR_STDCALL grAttachImageViewDescriptors(
323331
GrDescriptorSet* grDescriptorSet = (GrDescriptorSet*)descriptorSet;
324332
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
325333

334+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
335+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
336+
}
337+
326338
if (grDevice->descriptorBufferSupported && grDevice->descriptorBufferAllowPreparedImageView) {
327339
for (unsigned i = 0; i < slotCount; i++) {
328340
const GR_IMAGE_VIEW_ATTACH_INFO* info = &pImageViews[i];
@@ -428,6 +440,10 @@ GR_VOID GR_STDCALL grAttachImageViewDescriptors(
428440
VKD.vkUpdateDescriptorSets(grDevice->device, descriptorWriteCount, writeDescriptors, 0, NULL);
429441
STACK_ARRAY_FINISH(writeDescriptors);
430442
}
443+
444+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
445+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
446+
}
431447
}
432448

433449
GR_VOID GR_STDCALL grAttachMemoryViewDescriptors(
@@ -441,6 +457,10 @@ GR_VOID GR_STDCALL grAttachMemoryViewDescriptors(
441457
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
442458
VkResult vkRes;
443459

460+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
461+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
462+
}
463+
444464
if (grDevice->descriptorBufferSupported) {
445465
for (unsigned i = 0; i < slotCount; i++) {
446466
DescriptorSetSlot* slot = &grDescriptorSet->slots[startSlot + i];
@@ -596,6 +616,10 @@ GR_VOID GR_STDCALL grAttachMemoryViewDescriptors(
596616
VKD.vkUpdateDescriptorSets(grDevice->device, descriptorWriteCount, writeDescriptors, 0, NULL);
597617
STACK_ARRAY_FINISH(writeDescriptors);
598618
}
619+
620+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
621+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
622+
}
599623
}
600624

601625
GR_VOID GR_STDCALL grAttachNestedDescriptors(
@@ -608,6 +632,10 @@ GR_VOID GR_STDCALL grAttachNestedDescriptors(
608632
GrDescriptorSet* grDescriptorSet = (GrDescriptorSet*)descriptorSet;
609633
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
610634

635+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
636+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
637+
}
638+
611639
for (unsigned i = 0; i < slotCount; i++) {
612640
DescriptorSetSlot* slot = &grDescriptorSet->slots[startSlot + i];
613641
const GR_DESCRIPTOR_SET_ATTACH_INFO* info = &pNestedDescriptorSets[i];
@@ -622,6 +650,9 @@ GR_VOID GR_STDCALL grAttachNestedDescriptors(
622650
},
623651
};
624652
}
653+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
654+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
655+
}
625656
}
626657

627658
GR_VOID GR_STDCALL grClearDescriptorSetSlots(
@@ -633,6 +664,10 @@ GR_VOID GR_STDCALL grClearDescriptorSetSlots(
633664
GrDescriptorSet* grDescriptorSet = (GrDescriptorSet*)descriptorSet;
634665
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
635666

667+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
668+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
669+
}
670+
636671
if (grDevice->descriptorBufferSupported) {
637672
memset(grDescriptorSet->descriptorBufferPtr + (startSlot * DESCRIPTORS_PER_SLOT * grDevice->maxMutableDescriptorSize), 0, grDevice->maxMutableDescriptorSize * slotCount * DESCRIPTORS_PER_SLOT);
638673
memset(&grDescriptorSet->slots[startSlot], 0, sizeof(DescriptorSetSlot) * slotCount);
@@ -645,4 +680,8 @@ GR_VOID GR_STDCALL grClearDescriptorSetSlots(
645680
slot->type = SLOT_TYPE_NONE;
646681
}
647682
}
683+
684+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
685+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
686+
}
648687
}

src/mantle/mantle_object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ typedef struct _GrDescriptorSet {
233233
GrObject grObj;
234234
unsigned slotCount;
235235
DescriptorSetSlot* slots;
236+
SRWLOCK descriptorLock;
236237
VkDescriptorPool descriptorPool;
237238
VkDescriptorSet descriptorSet;
238239
void* descriptorBufferPtr;

src/mantle/quirk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ void quirkInit(
1717
QUIRK_INVALID_CMD_BUFFER_RESET |
1818
QUIRK_CUBEMAP_LAYER_DIV_6 |
1919
QUIRK_SILENCE_TRANSFER_ONLY_LINEAR_IMAGE_WARNINGS |
20-
QUIRK_DESCRIPTOR_SET_USE_DEDICATED_ALLOCATION;
20+
QUIRK_DESCRIPTOR_SET_USE_DEDICATED_ALLOCATION |
21+
QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED;
2122
} else if (!strcmp(appInfo->pEngineName, "CivTech")) {
2223
mQuirks = QUIRK_NON_ZERO_MEM_REQ |
2324
QUIRK_READ_ONLY_IMAGE_STATE_MISMATCH |

src/mantle/quirk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ typedef enum {
3131

3232
// Star Swarm uses completely incompatible memory types for descriptor buffers
3333
QUIRK_DESCRIPTOR_SET_USE_DEDICATED_ALLOCATION = 1 << 8,
34+
35+
// Star Swarm also doesn't care about external sync
36+
QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED = 1 << 9,
3437
} QUIRK_FLAGS;
3538

3639
void quirkInit(

0 commit comments

Comments
 (0)