Skip to content

Commit 3439b83

Browse files
committed
WOIRKING
1 parent d2b6462 commit 3439b83

8 files changed

Lines changed: 131 additions & 132 deletions

File tree

assets/core/scenes/scene-helmet.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"renderer": {
4646
"lighting": {
4747
"tFlags": [
48-
"_____PL_RENDERER_LIGHTING_FLAGS_IMAGE_BASED",
48+
"PL_RENDERER_LIGHTING_FLAGS_IMAGE_BASED",
4949
"PL_RENDERER_LIGHTING_FLAGS_NORMAL_MAPPING",
5050
"PL_RENDERER_LIGHTING_FLAGS_PUNCTUAL_LIGHTS"
5151
]
@@ -105,7 +105,7 @@
105105
},
106106
"probes": [
107107
{
108-
"active": false,
108+
"active": true,
109109
"tPosition": [0.0, 5.0, 0.0],
110110
"fRange": 30.0,
111111
"uResolution": 128,

extensions/pl_draw_ext.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4922,8 +4922,6 @@ pl__get_2d_pipeline(uint32_t uMSAASampleCount, const plRenderAttachmentFormatInf
49224922
.tAlphaOp = PL_BLEND_OP_ADD
49234923
}
49244924
},
4925-
.auColorAttachmentIndices = {0},
4926-
.uColorAttachmentCount = 1,
49274925
.atBindGroupLayouts = {
49284926
{
49294927
.atSamplerBindings = {
@@ -4979,8 +4977,6 @@ pl__get_2d_pipeline(uint32_t uMSAASampleCount, const plRenderAttachmentFormatInf
49794977
.tAlphaOp = PL_BLEND_OP_ADD
49804978
}
49814979
},
4982-
.auColorAttachmentIndices = {0},
4983-
.uColorAttachmentCount = 1,
49844980
.atBindGroupLayouts = {
49854981
{
49864982
.atSamplerBindings = {

extensions/pl_graphics_ext.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,6 @@ pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload)
966966
.set_roles = pl_graphics_set_roles,
967967
.reset_roles = pl_graphics_reset_roles,
968968
.change_texture_role = pl_graphics_change_texture_role,
969-
.set_attachment_mapping = pl_graphics_set_attachment_mapping,
970969
.end_render_pass = pl_graphics_end_render_pass,
971970
.begin_compute_pass = pl_graphics_begin_compute_pass,
972971
.end_compute_pass = pl_graphics_end_compute_pass,

extensions/pl_graphics_ext.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ typedef struct _plGraphicsI
612612
void (*set_roles) (plCommandBuffer*, const plPassResources*);
613613
void (*end_render_pass) (plCommandBuffer*);
614614
void (*change_texture_role)(plCommandBuffer*, plTextureHandle, plPassResourceRole, plPassResourceAccess, plPassResourceRole, plPassResourceAccess);
615-
void (*set_attachment_mapping)(plCommandBuffer*, uint32_t uCount, const uint32_t* puColorAttachmentIndices);
616615

617616
// render encoder: draw stream (preferred system)
618617
// Notes:
@@ -1114,7 +1113,6 @@ typedef struct _plRenderAttachmentFormatInfo
11141113

11151114
typedef struct _plShaderDesc
11161115
{
1117-
uint32_t uSubpassIndex;
11181116
plGraphicsState tGraphicsState;
11191117
plBlendState atBlendStates[PL_MAX_RENDER_TARGETS];
11201118
plVertexBufferLayout atVertexBufferLayouts[2];
@@ -1131,11 +1129,6 @@ typedef struct _plShaderDesc
11311129

11321130
// new
11331131
plRenderAttachmentFormatInfo tRenderAttachmentFormatInfo;
1134-
uint32_t uColorAttachmentCount;
1135-
uint32_t uColorInputAttachmentCount;
1136-
uint32_t auColorAttachmentIndices[PL_MAX_RENDER_TARGETS];
1137-
uint32_t auColorInputAttachmentIndices[PL_MAX_RENDER_TARGETS];
1138-
uint32_t uDepthInputAttachmentIndex;
11391132

11401133
// [INTERNAL]
11411134
uint32_t _uVertexConstantCount;
@@ -1161,6 +1154,7 @@ typedef struct _plRenderAttachment
11611154
plStoreOp tStoreOp;
11621155
plTextureUsage tUsage;
11631156
plTextureHandle tTexture;
1157+
plTextureHandle tResolveTexture;
11641158
plVec4 tClearColor;
11651159
float fClearZ;
11661160
uint32_t uClearStencil;

extensions/pl_graphics_vulkan.c

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ pl_graphics_create_texture_view(plDevice* ptDevice, const plTextureViewDesc* ptV
14921492
{
14931493
plTextureHandle tHandle = pl__get_new_texture_handle(ptDevice);
14941494
plTexture* ptOriginalTexture = pl_graphics_get_texture(ptDevice, ptViewDesc->tTexture);
1495-
plTexture* ptNewTexture = pl_graphics_get_texture(ptDevice, ptViewDesc->tTexture);
1495+
plTexture* ptNewTexture = pl_graphics_get_texture(ptDevice, tHandle);
14961496
ptNewTexture->tDesc = ptOriginalTexture->tDesc;
14971497
ptNewTexture->tDesc.tType = ptViewDesc->tType;
14981498
ptNewTexture->tDesc.pcDebugName = ptViewDesc->pcDebugName;
@@ -1531,6 +1531,7 @@ pl_graphics_create_texture_view(plDevice* ptDevice, const plTextureViewDesc* ptV
15311531
};
15321532
PL_VULKAN(vkCreateImageView(ptDevice->tLogicalDevice, &tViewInfo, gptGraphics->ptAllocationCallbacks, &ptNewVulkanTexture->tImageView));
15331533
ptNewVulkanTexture->bOriginalView = false;
1534+
ptNewVulkanTexture->tImage = ptOldVulkanTexture->tImage;
15341535
return tHandle;
15351536
}
15361537

@@ -1950,25 +1951,10 @@ pl_graphics_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription)
19501951
.pDynamicStates = tDynamicStateEnables
19511952
};
19521953

1953-
VkRenderingInputAttachmentIndexInfo tRenderingInputAttachmentIndexInfo = {
1954-
.sType = VK_STRUCTURE_TYPE_RENDERING_INPUT_ATTACHMENT_INDEX_INFO,
1955-
.colorAttachmentCount = ptDescription->uColorInputAttachmentCount,
1956-
.pColorAttachmentInputIndices = ptDescription->auColorInputAttachmentIndices,
1957-
.pDepthInputAttachmentIndex = &ptDescription->uDepthInputAttachmentIndex,
1958-
.pStencilInputAttachmentIndex = &ptDescription->uDepthInputAttachmentIndex,
1959-
};
1960-
1961-
VkRenderingAttachmentLocationInfo tRenderingAttachmentLocationInfo = {
1962-
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_LOCATION_INFO,
1963-
.colorAttachmentCount = ptDescription->uColorAttachmentCount,
1964-
.pColorAttachmentLocations = ptDescription->uColorAttachmentCount > 0 ? ptDescription->auColorAttachmentIndices : NULL,
1965-
.pNext = ptDescription->uColorInputAttachmentCount > 0 ? &tRenderingInputAttachmentIndexInfo : NULL
1966-
};
1967-
19681954
// New create info to define color, depth and stencil attachments at pipeline create time
19691955
VkPipelineRenderingCreateInfo tPipelineRenderingCreateInfo = {
19701956
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
1971-
.pNext = ptDescription->uColorAttachmentCount > 0 ? &tRenderingAttachmentLocationInfo : tRenderingAttachmentLocationInfo.pNext,
1957+
.pNext = NULL,
19721958
.colorAttachmentCount = ptDescription->tRenderAttachmentFormatInfo.uColorCount,
19731959
.pColorAttachmentFormats = atColorAttachmentFormats,
19741960
.depthAttachmentFormat = ptDescription->tRenderAttachmentFormatInfo.tDepthFormat == 0 ? 0 : pl__vulkan_format(ptDescription->tRenderAttachmentFormatInfo.tDepthFormat),
@@ -1987,7 +1973,7 @@ pl_graphics_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription)
19871973
.pColorBlendState = &tColorBlending,
19881974
.pDynamicState = &tDynamicState,
19891975
.layout = tVulkanShader.tPipelineLayout,
1990-
.subpass = ptShader->tDesc.uSubpassIndex,
1976+
.subpass = 0,
19911977
.basePipelineHandle = VK_NULL_HANDLE,
19921978
.pDepthStencilState = &tDepthStencil,
19931979
.pNext = &tPipelineRenderingCreateInfo
@@ -2071,17 +2057,6 @@ pl_graphics_begin_command_recording(plCommandBuffer* ptCommandBuffer)
20712057
PL_VULKAN(vkBeginCommandBuffer(ptCommandBuffer->tCmdBuffer, &tBeginInfo));
20722058
}
20732059

2074-
void
2075-
pl_graphics_set_attachment_mapping(plCommandBuffer* ptCmdBuffer, uint32_t uCount, const uint32_t* puColorAttachmentIndices)
2076-
{
2077-
VkRenderingAttachmentLocationInfo tVkRenderingInputAttachmentIndexInfo = {
2078-
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_LOCATION_INFO,
2079-
.colorAttachmentCount = uCount,
2080-
.pColorAttachmentLocations = puColorAttachmentIndices,
2081-
};
2082-
vkCmdSetRenderingAttachmentLocations(ptCmdBuffer->tCmdBuffer, &tVkRenderingInputAttachmentIndexInfo);
2083-
}
2084-
20852060
void
20862061
pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tTexture, plPassResourceRole tOldRole,
20872062
plPassResourceAccess tOldAccess, plPassResourceRole tNewRole, plPassResourceAccess tNewAccess)
@@ -2099,7 +2074,7 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
20992074
VkImageSubresourceRange tRange = {
21002075
.baseMipLevel = 0,
21012076
.levelCount = 1,
2102-
.baseArrayLayer = 0,
2077+
.baseArrayLayer = ptTexture->tView.uBaseLayer,
21032078
.layerCount = 1,
21042079
.aspectMask = tImageAspectFlags
21052080
};
@@ -2126,6 +2101,7 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
21262101
if(tOldRole == PL_PASS_RESOURCE_ROLE_NONE && tOldAccess == PL_PASS_RESOURCE_ACCESS_NONE)
21272102
{
21282103
tBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
2104+
tBarrier.srcStageMask |= VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
21292105
bPreviousConfigValid = true;
21302106
}
21312107

@@ -2187,6 +2163,22 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
21872163
bPreviousConfigValid = true;
21882164
}
21892165

2166+
if(tOldRole == PL_PASS_RESOURCE_ROLE_STORAGE && tOldAccess == PL_PASS_RESOURCE_ACCESS_WRITE)
2167+
{
2168+
2169+
if(bDepthStencil)
2170+
{
2171+
}
2172+
else
2173+
{
2174+
tBarrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
2175+
tBarrier.srcAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
2176+
tBarrier.srcStageMask |= VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
2177+
bPreviousConfigValid = true;
2178+
}
2179+
2180+
}
2181+
21902182
// new layout stuff
21912183
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
21922184

@@ -2262,6 +2254,40 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
22622254
bNextConfigValid = true;
22632255
}
22642256

2257+
if(tNewRole == PL_PASS_RESOURCE_ROLE_ATTACHMENT && tNewAccess == PL_PASS_RESOURCE_ACCESS_READ)
2258+
{
2259+
2260+
if(bDepthStencil)
2261+
{
2262+
tBarrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2263+
tBarrier.dstAccessMask |= VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
2264+
tBarrier.dstStageMask |= VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT;
2265+
}
2266+
else
2267+
{
2268+
tBarrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2269+
tBarrier.dstAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT;
2270+
tBarrier.dstStageMask |= VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
2271+
}
2272+
bNextConfigValid = true;
2273+
}
2274+
2275+
if(tNewRole == PL_PASS_RESOURCE_ROLE_STORAGE && tNewAccess == PL_PASS_RESOURCE_ACCESS_WRITE)
2276+
{
2277+
2278+
if(bDepthStencil)
2279+
{
2280+
}
2281+
else
2282+
{
2283+
tBarrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
2284+
tBarrier.dstAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
2285+
tBarrier.dstStageMask |= VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
2286+
bNextConfigValid = true;
2287+
}
2288+
2289+
}
2290+
22652291
PL_ASSERT(bPreviousConfigValid);
22662292
PL_ASSERT(bNextConfigValid);
22672293

@@ -2803,6 +2829,13 @@ pl_graphics_begin_render_pass(plCommandBuffer* ptCmdBuffer, plRenderInfo tInfo,
28032829
atColorAttachments[i].imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
28042830
if(tInfo.atColorAttachments[i].tUsage == PL_TEXTURE_USAGE_INPUT_ATTACHMENT)
28052831
atColorAttachments[i].imageLayout = VK_IMAGE_LAYOUT_RENDERING_LOCAL_READ;
2832+
2833+
if(tInfo.atColorAttachments[i].tResolveTexture.uIndex > 0)
2834+
{
2835+
atColorAttachments[i].resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
2836+
atColorAttachments[i].resolveImageView = ptDevice->sbtTexturesHot[tInfo.atColorAttachments[i].tResolveTexture.uIndex].tImageView;
2837+
atColorAttachments[i].resolveImageLayout = VK_IMAGE_LAYOUT_GENERAL;
2838+
}
28062839
uColorAttachmentCount++;
28072840
}
28082841

@@ -6311,7 +6344,7 @@ pl__garbage_collect(plDevice* ptDevice)
63116344
plVulkanTexture* ptVulkanResource = &ptDevice->sbtTexturesHot[iResourceIndex];
63126345
vkDestroyImageView(ptDevice->tLogicalDevice, ptDevice->sbtTexturesHot[iResourceIndex].tImageView, gptGraphics->ptAllocationCallbacks);
63136346
ptDevice->sbtTexturesHot[iResourceIndex].tImageView = VK_NULL_HANDLE;
6314-
if (ptDevice->sbtTexturesHot[iResourceIndex].bOriginalView)
6347+
if (ptDevice->sbtTexturesHot[iResourceIndex].bOriginalView && !ptDevice->sbtTexturesHot[iResourceIndex].bSwapchain)
63156348
{
63166349
vkDestroyImage(ptDevice->tLogicalDevice, ptVulkanResource->tImage, gptGraphics->ptAllocationCallbacks);
63176350
ptVulkanResource->tImage = VK_NULL_HANDLE;

extensions/pl_renderer_ext.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,13 +3078,6 @@ pl_renderer_prepare_scene(plScene* ptScene, const plCamera** atCameras, uint32_t
30783078
.tStoreOp = PL_STORE_OP_STORE,
30793079
.tUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT,
30803080
.fClearZ = 0.0f
3081-
},
3082-
.tStencilAttachment = {
3083-
.tTexture = ptScene->tShadowTexture,
3084-
.tLoadOp = PL_LOAD_OP_LOAD,
3085-
.tStoreOp = PL_STORE_OP_STORE,
3086-
.tUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT,
3087-
.uClearStencil = 0
30883081
}
30893082
};
30903083

@@ -3507,7 +3500,7 @@ pl_renderer_render_view(plView* ptView, const plRenderViewDesc* ptViewDesc)
35073500
.tLoadOp = PL_LOAD_OP_CLEAR,
35083501
.tStoreOp = PL_STORE_OP_STORE,
35093502
.tUsage = PL_TEXTURE_USAGE_INPUT_ATTACHMENT,
3510-
.fClearZ = 1.0f
3503+
.fClearZ = 0.0f
35113504
},
35123505
.tStencilAttachment = {
35133506
.tTexture = ptView->tDepthTexture,
@@ -3544,10 +3537,6 @@ pl_renderer_render_view(plView* ptView, const plRenderViewDesc* ptViewDesc)
35443537
// gptGfx->set_roles(ptSceneCmdBuffer, &tMainResources);
35453538
gptGfx->begin_render_pass(ptSceneCmdBuffer, tMainRenderInfo, NULL);
35463539

3547-
const uint32_t auColorAttachmentIndices[] = {UINT32_MAX, 0, 1, 2};
3548-
gptGfx->set_attachment_mapping(ptSceneCmdBuffer, PL_ARRAYSIZE(auColorAttachmentIndices), auColorAttachmentIndices);
3549-
3550-
35513540
const plVec2 tDimensions = ptView->tTargetSize;
35523541

35533542
plDrawArea tArea = {
@@ -3714,15 +3703,15 @@ pl_renderer_render_view(plView* ptView, const plRenderViewDesc* ptViewDesc)
37143703
.tLoadOp = PL_LOAD_OP_LOAD,
37153704
.tStoreOp = PL_STORE_OP_STORE,
37163705
.tUsage = PL_TEXTURE_USAGE_COLOR_ATTACHMENT,
3717-
.tClearColor = {0.0f, 0.0f, 0.0f, 1.0f}
3706+
.tClearColor = {0.0f, 0.0f, 0.0f, 0.0f}
37183707
}
37193708
},
37203709
.tDepthAttachment = {
37213710
.tTexture = ptView->tDepthTexture,
37223711
.tLoadOp = PL_LOAD_OP_LOAD,
37233712
.tStoreOp = PL_STORE_OP_STORE,
37243713
.tUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT,
3725-
.fClearZ = 1.0f
3714+
.fClearZ = 0.0f
37263715
},
37273716
.tStencilAttachment = {
37283717
.tTexture = ptView->tDepthTexture,

0 commit comments

Comments
 (0)