|
23 | 23 | typedef enum { |
24 | 24 | RES_TYPE_GENERIC, |
25 | 25 | RES_TYPE_LDS, |
| 26 | + RES_TYPE_ATOMIC_BUFFER, |
26 | 27 | } IlcResourceType; |
27 | 28 |
|
28 | 29 | typedef enum { |
@@ -2494,6 +2495,70 @@ static void emitLdsStoreVec( |
2494 | 2495 | } |
2495 | 2496 | } |
2496 | 2497 |
|
| 2498 | +static void emitUavAppendBufAlloc( |
| 2499 | + IlcCompiler* compiler, |
| 2500 | + const Instruction* instr) |
| 2501 | +{ |
| 2502 | + uint8_t ilResourceId = GET_BITS(instr->control, 0, 14); |
| 2503 | + bool increment = instr->opcode == IL_OP_APPEND_BUF_ALLOC; |
| 2504 | + //ilResourceId is always 0 |
| 2505 | + const IlcResource* resource = findResource(compiler, RES_TYPE_ATOMIC_BUFFER, 0); |
| 2506 | + if (resource == NULL) { |
| 2507 | + IlcSpvId arrayId = ilcSpvPutRuntimeArrayType(compiler->module, compiler->uintId, true); |
| 2508 | + IlcSpvId structId = ilcSpvPutUniqueStructType(compiler->module, 1, &arrayId); |
| 2509 | + IlcSpvId pCounterId = ilcSpvPutPointerType(compiler->module, SpvStorageClassStorageBuffer, structId); |
| 2510 | + IlcSpvId resourceId = ilcSpvPutVariable(compiler->module, pCounterId, SpvStorageClassStorageBuffer); |
| 2511 | + |
| 2512 | + IlcSpvWord arrayStride = sizeof(unsigned); |
| 2513 | + IlcSpvWord memberOffset = 0; |
| 2514 | + ilcSpvPutDecoration(compiler->module, arrayId, SpvDecorationArrayStride, 1, &arrayStride); |
| 2515 | + ilcSpvPutDecoration(compiler->module, structId, SpvDecorationBlock, 0, NULL); |
| 2516 | + ilcSpvPutMemberDecoration(compiler->module, structId, 0, SpvDecorationOffset, 1, &memberOffset); |
| 2517 | + |
| 2518 | + const IlcResource resourceInfo = { |
| 2519 | + .resType = RES_TYPE_ATOMIC_BUFFER, |
| 2520 | + .id = resourceId, |
| 2521 | + .typeId = structId, |
| 2522 | + .texelTypeId = compiler->uintId, |
| 2523 | + .ilId = 0, |
| 2524 | + .ilType = IL_USAGE_PIXTEX_UNKNOWN, |
| 2525 | + .strideId = 0, |
| 2526 | + .structured = false, |
| 2527 | + }; |
| 2528 | + |
| 2529 | + emitBinding(compiler, resourceId, ILC_BASE_APPEND_COUNTER_RESOURCE_ID, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, |
| 2530 | + NO_STRIDE_INDEX); |
| 2531 | + |
| 2532 | + addResource(compiler, &resourceInfo); |
| 2533 | + resource = findResource(compiler, RES_TYPE_ATOMIC_BUFFER, 0); |
| 2534 | + if (resource == NULL) { |
| 2535 | + LOGE("failed to find counter resource after creation"); |
| 2536 | + return; |
| 2537 | + } |
| 2538 | + } |
| 2539 | + const Destination* dst = &instr->dsts[0]; |
| 2540 | + |
| 2541 | + IlcSpvId zeroId = ilcSpvPutConstant(compiler->module, compiler->uintId, ZERO_LITERAL); |
| 2542 | + IlcSpvId counterIndexId = ilcSpvPutConstant(compiler->module, compiler->uintId, ilResourceId); |
| 2543 | + IlcSpvId scopeId = ilcSpvPutConstant(compiler->module, compiler->intId, SpvScopeDevice); |
| 2544 | + |
| 2545 | + IlcSpvId ptrTypeId = ilcSpvPutPointerType(compiler->module, SpvStorageClassStorageBuffer, resource->texelTypeId); |
| 2546 | + |
| 2547 | + IlcSpvId indexIds[] = { zeroId, counterIndexId }; |
| 2548 | + IlcSpvId ptrId = ilcSpvPutAccessChain(compiler->module, ptrTypeId, resource->id, |
| 2549 | + 2, indexIds); |
| 2550 | + IlcSpvId semanticsId = ilcSpvPutConstant(compiler->module, compiler->intId, |
| 2551 | + SpvMemorySemanticsAcquireReleaseMask | |
| 2552 | + SpvMemorySemanticsUniformMemoryMask); |
| 2553 | + IlcSpvId readId = ilcSpvPutAtomicOpWithoutValue(compiler->module, increment ? SpvOpAtomicIIncrement : SpvOpAtomicIDecrement, |
| 2554 | + resource->texelTypeId, ptrId, scopeId, semanticsId); |
| 2555 | + |
| 2556 | + IlcSpvId constituents[4] = { readId, zeroId, zeroId, zeroId}; |
| 2557 | + IlcSpvId loadId = ilcSpvPutCompositeConstruct(compiler->module, compiler->uint4Id, |
| 2558 | + 4, constituents); |
| 2559 | + storeDestination(compiler, dst, loadId, compiler->uint4Id); |
| 2560 | +} |
| 2561 | + |
2497 | 2562 | static void emitUavLoad( |
2498 | 2563 | IlcCompiler* compiler, |
2499 | 2564 | const Instruction* instr) |
@@ -3135,6 +3200,10 @@ static void emitInstr( |
3135 | 3200 | case IL_OP_LDS_READ_UMAX: |
3136 | 3201 | emitLdsAtomicOp(compiler, instr); |
3137 | 3202 | break; |
| 3203 | + case IL_OP_APPEND_BUF_ALLOC: |
| 3204 | + case IL_OP_APPEND_BUF_CONSUME: |
| 3205 | + emitUavAppendBufAlloc(compiler, instr); |
| 3206 | + break; |
3138 | 3207 | case IL_OP_DCL_RAW_SRV: |
3139 | 3208 | case IL_OP_DCL_STRUCT_SRV: |
3140 | 3209 | emitSrv(compiler, instr); |
|
0 commit comments