Skip to content

Commit f08a9f3

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 c9c04ae commit f08a9f3

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) {
250255
for (unsigned i = 0; i < slotCount; i++) {
251256
const GrSampler* grSampler = (GrSampler*)pSamplers[i];
@@ -304,6 +309,9 @@ GR_VOID GR_STDCALL grAttachSamplerDescriptors(
304309
STACK_ARRAY_FINISH(writeDescriptors);
305310
}
306311

312+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
313+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
314+
}
307315
}
308316

309317
GR_VOID GR_STDCALL grAttachImageViewDescriptors(
@@ -316,6 +324,10 @@ GR_VOID GR_STDCALL grAttachImageViewDescriptors(
316324
GrDescriptorSet* grDescriptorSet = (GrDescriptorSet*)descriptorSet;
317325
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
318326

327+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
328+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
329+
}
330+
319331
if (grDevice->descriptorBufferSupported) {
320332
for (unsigned i = 0; i < slotCount; i++) {
321333
const GR_IMAGE_VIEW_ATTACH_INFO* info = &pImageViews[i];
@@ -405,6 +417,10 @@ GR_VOID GR_STDCALL grAttachImageViewDescriptors(
405417
VKD.vkUpdateDescriptorSets(grDevice->device, descriptorWriteCount, writeDescriptors, 0, NULL);
406418
STACK_ARRAY_FINISH(writeDescriptors);
407419
}
420+
421+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
422+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
423+
}
408424
}
409425

410426
GR_VOID GR_STDCALL grAttachMemoryViewDescriptors(
@@ -418,6 +434,10 @@ GR_VOID GR_STDCALL grAttachMemoryViewDescriptors(
418434
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
419435
VkResult vkRes;
420436

437+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
438+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
439+
}
440+
421441
if (grDevice->descriptorBufferSupported) {
422442
for (unsigned i = 0; i < slotCount; i++) {
423443
DescriptorSetSlot* slot = &grDescriptorSet->slots[startSlot + i];
@@ -573,6 +593,10 @@ GR_VOID GR_STDCALL grAttachMemoryViewDescriptors(
573593
VKD.vkUpdateDescriptorSets(grDevice->device, descriptorWriteCount, writeDescriptors, 0, NULL);
574594
STACK_ARRAY_FINISH(writeDescriptors);
575595
}
596+
597+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
598+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
599+
}
576600
}
577601

578602
GR_VOID GR_STDCALL grAttachNestedDescriptors(
@@ -585,6 +609,10 @@ GR_VOID GR_STDCALL grAttachNestedDescriptors(
585609
GrDescriptorSet* grDescriptorSet = (GrDescriptorSet*)descriptorSet;
586610
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
587611

612+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
613+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
614+
}
615+
588616
for (unsigned i = 0; i < slotCount; i++) {
589617
DescriptorSetSlot* slot = &grDescriptorSet->slots[startSlot + i];
590618
const GR_DESCRIPTOR_SET_ATTACH_INFO* info = &pNestedDescriptorSets[i];
@@ -599,6 +627,9 @@ GR_VOID GR_STDCALL grAttachNestedDescriptors(
599627
},
600628
};
601629
}
630+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
631+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
632+
}
602633
}
603634

604635
GR_VOID GR_STDCALL grClearDescriptorSetSlots(
@@ -610,6 +641,10 @@ GR_VOID GR_STDCALL grClearDescriptorSetSlots(
610641
GrDescriptorSet* grDescriptorSet = (GrDescriptorSet*)descriptorSet;
611642
const GrDevice* grDevice = GET_OBJ_DEVICE(grDescriptorSet);
612643

644+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
645+
AcquireSRWLockExclusive(&grDescriptorSet->descriptorLock);
646+
}
647+
613648
if (grDevice->descriptorBufferSupported) {
614649
memset(grDescriptorSet->descriptorBufferPtr + (startSlot * DESCRIPTORS_PER_SLOT * grDevice->maxMutableDescriptorSize), 0, grDevice->maxMutableDescriptorSize * slotCount * DESCRIPTORS_PER_SLOT);
615650
memset(&grDescriptorSet->slots[startSlot], 0, sizeof(DescriptorSetSlot) * slotCount);
@@ -622,4 +657,8 @@ GR_VOID GR_STDCALL grClearDescriptorSetSlots(
622657
slot->type = SLOT_TYPE_NONE;
623658
}
624659
}
660+
661+
if (quirkHas(QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED)) {
662+
ReleaseSRWLockExclusive(&grDescriptorSet->descriptorLock);
663+
}
625664
}

src/mantle/mantle_object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ typedef struct _GrDescriptorSet {
236236
GrObject grObj;
237237
unsigned slotCount;
238238
DescriptorSetSlot* slots;
239+
SRWLOCK descriptorLock;
239240
VkDescriptorPool descriptorPool;
240241
VkDescriptorSet descriptorSet;
241242
void* descriptorBufferPtr;

src/mantle/quirk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ void quirkInit(
1313
QUIRK_INVALID_CMD_BUFFER_RESET |
1414
QUIRK_CUBEMAP_LAYER_DIV_6 |
1515
QUIRK_SILENCE_TRANSFER_ONLY_LINEAR_IMAGE_WARNINGS |
16-
QUIRK_DESCRIPTOR_SET_USE_DEDICATED_ALLOCATION;
16+
QUIRK_DESCRIPTOR_SET_USE_DEDICATED_ALLOCATION |
17+
QUIRK_DESCRIPTOR_SET_INTERNAL_SYNCHRONIZED;
1718
} else if (!strcmp(appInfo->pEngineName, "CivTech")) {
1819
mQuirks = QUIRK_NON_ZERO_MEM_REQ |
1920
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)