|
148 | 148 | plSamplerHandle atSamplerBindings[PL_MAX_TEXTURES_PER_BIND_GROUP]; |
149 | 149 | uint64_t uHeapUsageMask; |
150 | 150 | uint32_t uOffset; |
151 | | - plTextureHandle* sbtTextures; |
152 | 151 | } plMetalBindGroup; |
153 | 152 |
|
154 | 153 | typedef struct _plMetalShader |
|
549 | 548 | } |
550 | 549 | } |
551 | 550 |
|
| 551 | +void |
| 552 | +pl_copy_texture(plBlitEncoder* ptEncoder, plTextureHandle tSrcHandle, plTextureHandle tDstHandle, uint32_t uRegionCount, const plImageCopy* ptRegions) |
| 553 | +{ |
| 554 | + plCommandBuffer* ptCmdBuffer = ptEncoder->ptCommandBuffer; |
| 555 | + plDevice* ptDevice = ptCmdBuffer->ptDevice; |
| 556 | + const plMetalTexture* ptMetalSrcTexture = &ptDevice->sbtTexturesHot[tSrcHandle.uIndex]; |
| 557 | + const plMetalTexture* ptMetalDstTexture = &ptDevice->sbtTexturesHot[tDstHandle.uIndex]; |
| 558 | + |
| 559 | + for(uint32_t i = 0; i < uRegionCount; i++) |
| 560 | + { |
| 561 | + |
| 562 | + MTLOrigin tSrcOrigin; |
| 563 | + tSrcOrigin.x = ptRegions[i].iSourceOffsetX; |
| 564 | + tSrcOrigin.y = ptRegions[i].iSourceOffsetY; |
| 565 | + tSrcOrigin.z = ptRegions[i].iSourceOffsetZ; |
| 566 | + |
| 567 | + MTLOrigin tDestOrigin; |
| 568 | + tDestOrigin.x = ptRegions[i].iDestinationOffsetX; |
| 569 | + tDestOrigin.y = ptRegions[i].iDestinationOffsetY; |
| 570 | + tDestOrigin.z = ptRegions[i].iDestinationOffsetZ; |
| 571 | + |
| 572 | + MTLSize tSourceSize; |
| 573 | + tSourceSize.width = ptRegions[i].uSourceExtentX; |
| 574 | + tSourceSize.height = ptRegions[i].uSourceExtentY; |
| 575 | + tSourceSize.depth = ptRegions[i].uSourceExtentZ; |
| 576 | + |
| 577 | + [ptEncoder->tEncoder copyFromTexture:ptMetalSrcTexture->tTexture |
| 578 | + sourceSlice:ptRegions[i].uSourceBaseArrayLayer |
| 579 | + sourceLevel:ptRegions[i].uSourceMipLevel |
| 580 | + sourceOrigin:tSrcOrigin |
| 581 | + sourceSize:tSourceSize |
| 582 | + toTexture:ptMetalDstTexture->tTexture |
| 583 | + destinationSlice:ptRegions[i].uDestinationBaseArrayLayer |
| 584 | + destinationLevel:ptRegions[i].uDestinationMipLevel |
| 585 | + destinationOrigin:tDestOrigin]; |
| 586 | + } |
| 587 | +} |
| 588 | + |
552 | 589 | static void |
553 | 590 | pl_copy_texture_to_buffer(plBlitEncoder* ptEncoder, plTextureHandle tTextureHandle, plBufferHandle tBufferHandle, uint32_t uRegionCount, const plBufferImageCopy* ptRegions) |
554 | 591 | { |
|
900 | 937 | plBindGroup* ptBindGroup = pl__get_bind_group(ptDevice, tHandle); |
901 | 938 | const char* pcDescriptorStart = ptMetalBindGroup->tShaderArgumentBuffer.contents; |
902 | 939 |
|
| 940 | + pl_sb_reset(ptBindGroup->_sbtTextures); |
| 941 | + |
903 | 942 | uint64_t* pulDescriptorStart = (uint64_t*)&pcDescriptorStart[ptMetalBindGroup->uOffset]; |
904 | 943 |
|
905 | 944 | for(uint32_t i = 0; i < ptData->uBufferCount; i++) |
|
922 | 961 | int iCommonBits = ptTexture->tDesc.tUsage & (PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT | PL_TEXTURE_USAGE_COLOR_ATTACHMENT |PL_TEXTURE_USAGE_INPUT_ATTACHMENT | PL_TEXTURE_USAGE_STORAGE); |
923 | 962 | if(iCommonBits) |
924 | 963 | { |
925 | | - pl_sb_push(ptMetalBindGroup->sbtTextures, ptUpdate->tTexture); |
| 964 | + pl_sb_push(ptBindGroup->_sbtTextures, ptUpdate->tTexture); |
926 | 965 | } |
927 | 966 |
|
928 | 967 | ptMetalBindGroup->uHeapUsageMask |= (1ULL << ptMetalTexture->uHeap); |
|
2167 | 2206 |
|
2168 | 2207 | for(uint32_t i = 0; i < uCount; i++) |
2169 | 2208 | { |
2170 | | - plMetalBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsHot[atBindGroups[i].uIndex]; |
| 2209 | + plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[atBindGroups[i].uIndex]; |
| 2210 | + plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[atBindGroups[i].uIndex]; |
2171 | 2211 |
|
2172 | | - ptEncoder->uHeapUsageMask |= ptBindGroup->uHeapUsageMask; |
| 2212 | + ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask; |
2173 | 2213 |
|
2174 | 2214 | for(uint64_t k = 0; k < 64; k++) |
2175 | 2215 | { |
|
2179 | 2219 | } |
2180 | 2220 | } |
2181 | 2221 |
|
2182 | | - const uint32_t uTextureCount = pl_sb_size(ptBindGroup->sbtTextures); |
| 2222 | + const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures); |
2183 | 2223 | for(uint32_t k = 0; k < uTextureCount; k++) |
2184 | 2224 | { |
2185 | | - const plTextureHandle tTextureHandle = ptBindGroup->sbtTextures[k]; |
| 2225 | + const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k]; |
2186 | 2226 | plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle); |
2187 | 2227 | if(ptTexture->tDesc.tUsage & PL_TEXTURE_USAGE_STORAGE) |
2188 | 2228 | { |
|
2194 | 2234 | } |
2195 | 2235 | } |
2196 | 2236 |
|
2197 | | - [ptEncoder->tEncoder setBuffer:ptBindGroup->tShaderArgumentBuffer |
2198 | | - offset:ptBindGroup->uOffset |
| 2237 | + [ptEncoder->tEncoder setBuffer:ptMetalBindGroup->tShaderArgumentBuffer |
| 2238 | + offset:ptMetalBindGroup->uOffset |
2199 | 2239 | atIndex:uFirst + i]; |
2200 | 2240 | } |
2201 | 2241 | } |
|
2215 | 2255 |
|
2216 | 2256 | for(uint32_t i = 0; i < uCount; i++) |
2217 | 2257 | { |
2218 | | - plMetalBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsHot[atBindGroups[i].uIndex]; |
| 2258 | + plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[atBindGroups[i].uIndex]; |
| 2259 | + plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[atBindGroups[i].uIndex]; |
2219 | 2260 |
|
2220 | | - ptEncoder->uHeapUsageMask |= ptBindGroup->uHeapUsageMask; |
| 2261 | + ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask; |
2221 | 2262 |
|
2222 | 2263 | for(uint64_t k = 0; k < 64; k++) |
2223 | 2264 | { |
|
2227 | 2268 | } |
2228 | 2269 | } |
2229 | 2270 |
|
2230 | | - const uint32_t uTextureCount = pl_sb_size(ptBindGroup->sbtTextures); |
| 2271 | + const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures); |
2231 | 2272 | for(uint32_t k = 0; k < uTextureCount; k++) |
2232 | 2273 | { |
2233 | | - const plTextureHandle tTextureHandle = ptBindGroup->sbtTextures[k]; |
| 2274 | + const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k]; |
2234 | 2275 | plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle); |
2235 | 2276 | [ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment]; |
2236 | 2277 | } |
2237 | 2278 |
|
2238 | | - [ptEncoder->tEncoder setVertexBuffer:ptBindGroup->tShaderArgumentBuffer offset:ptBindGroup->uOffset atIndex:uFirst + i]; |
2239 | | - [ptEncoder->tEncoder setFragmentBuffer:ptBindGroup->tShaderArgumentBuffer offset:ptBindGroup->uOffset atIndex:uFirst + i]; |
| 2279 | + [ptEncoder->tEncoder setVertexBuffer:ptMetalBindGroup->tShaderArgumentBuffer offset:ptMetalBindGroup->uOffset atIndex:uFirst + i]; |
| 2280 | + [ptEncoder->tEncoder setFragmentBuffer:ptMetalBindGroup->tShaderArgumentBuffer offset:ptMetalBindGroup->uOffset atIndex:uFirst + i]; |
2240 | 2281 | } |
2241 | 2282 | } |
2242 | 2283 |
|
|
2438 | 2479 | if(uDirtyMask & PL_DRAW_STREAM_BIT_BINDGROUP_0) |
2439 | 2480 | { |
2440 | 2481 | const plBindGroupHandle tBindGroupHandle = {.uData = ptStream->_auStream[uCurrentStreamIndex] }; |
| 2482 | + plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[tBindGroupHandle.uIndex]; |
2441 | 2483 | plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[tBindGroupHandle.uIndex]; |
2442 | 2484 |
|
2443 | 2485 | ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask; |
|
2451 | 2493 | } |
2452 | 2494 | } |
2453 | 2495 |
|
2454 | | - const uint32_t uTextureCount = pl_sb_size(ptMetalBindGroup->sbtTextures); |
| 2496 | + const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures); |
2455 | 2497 | for(uint32_t k = 0; k < uTextureCount; k++) |
2456 | 2498 | { |
2457 | | - const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k]; |
| 2499 | + const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k]; |
2458 | 2500 | plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle); |
2459 | 2501 | [ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment]; |
2460 | 2502 | } |
|
2468 | 2510 | { |
2469 | 2511 | const plBindGroupHandle tBindGroupHandle = {.uData = ptStream->_auStream[uCurrentStreamIndex] }; |
2470 | 2512 | plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[tBindGroupHandle.uIndex]; |
| 2513 | + plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[tBindGroupHandle.uIndex]; |
2471 | 2514 |
|
2472 | 2515 | ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask; |
2473 | 2516 |
|
|
2480 | 2523 | } |
2481 | 2524 | } |
2482 | 2525 |
|
2483 | | - const uint32_t uTextureCount = pl_sb_size(ptMetalBindGroup->sbtTextures); |
| 2526 | + const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures); |
2484 | 2527 | for(uint32_t k = 0; k < uTextureCount; k++) |
2485 | 2528 | { |
2486 | | - const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k]; |
| 2529 | + const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k]; |
2487 | 2530 | plTexture* ptTexture = pl__get_texture(ptDevice, tTextureHandle); |
2488 | 2531 | [ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment]; |
2489 | 2532 | } |
|
2497 | 2540 | { |
2498 | 2541 | const plBindGroupHandle tBindGroupHandle = {.uData = ptStream->_auStream[uCurrentStreamIndex] }; |
2499 | 2542 | plMetalBindGroup* ptMetalBindGroup = &ptDevice->sbtBindGroupsHot[tBindGroupHandle.uIndex]; |
| 2543 | + plBindGroup* ptBindGroup = &ptDevice->sbtBindGroupsCold[tBindGroupHandle.uIndex]; |
2500 | 2544 |
|
2501 | 2545 | ptEncoder->uHeapUsageMask |= ptMetalBindGroup->uHeapUsageMask; |
2502 | 2546 |
|
|
2509 | 2553 | } |
2510 | 2554 | } |
2511 | 2555 |
|
2512 | | - const uint32_t uTextureCount = pl_sb_size(ptMetalBindGroup->sbtTextures); |
| 2556 | + const uint32_t uTextureCount = pl_sb_size(ptBindGroup->_sbtTextures); |
2513 | 2557 | for(uint32_t k = 0; k < uTextureCount; k++) |
2514 | 2558 | { |
2515 | | - const plTextureHandle tTextureHandle = ptMetalBindGroup->sbtTextures[k]; |
| 2559 | + const plTextureHandle tTextureHandle = ptBindGroup->_sbtTextures[k]; |
2516 | 2560 | [ptEncoder->tEncoder useResource:ptDevice->sbtTexturesHot[tTextureHandle.uIndex].tTexture usage:MTLResourceUsageRead stages:MTLRenderStageVertex | MTLRenderStageFragment]; |
2517 | 2561 | } |
2518 | 2562 |
|
|
3143 | 3187 | for(uint32_t i = 0; i < pl_sb_size(ptGarbage->sbtBindGroups); i++) |
3144 | 3188 | { |
3145 | 3189 | const uint16_t iBindGroupIndex = ptGarbage->sbtBindGroups[i].uIndex; |
| 3190 | + plBindGroup* ptResource = &ptDevice->sbtBindGroupsCold[iBindGroupIndex]; |
3146 | 3191 | plMetalBindGroup* ptMetalResource = &ptDevice->sbtBindGroupsHot[iBindGroupIndex]; |
3147 | | - pl_sb_reset(ptMetalResource->sbtTextures); |
| 3192 | + pl_sb_reset(ptResource->_sbtTextures); |
3148 | 3193 | [ptMetalResource->tShaderArgumentBuffer release]; |
3149 | 3194 | ptMetalResource->tShaderArgumentBuffer = nil; |
3150 | 3195 | pl_sb_push(ptDevice->sbtBindGroupFreeIndices, iBindGroupIndex); |
|
3319 | 3364 | pl_sb_push(ptDevice->sbtBindGroupFreeIndices, tHandle.uIndex); |
3320 | 3365 |
|
3321 | 3366 | plMetalBindGroup* ptMetalResource = &ptDevice->sbtBindGroupsHot[tHandle.uIndex]; |
| 3367 | + plBindGroup* ptResource = &ptDevice->sbtBindGroupsCold[tHandle.uIndex]; |
| 3368 | + pl_sb_free(ptResource->_sbtTextures); |
3322 | 3369 | [ptMetalResource->tShaderArgumentBuffer release]; |
3323 | 3370 | ptMetalResource->tShaderArgumentBuffer = nil; |
3324 | 3371 | } |
|
0 commit comments