Skip to content

Commit 4216fc8

Browse files
feat: add 3D textures for gfx ext (v2.1.0)
1 parent ff9bbdd commit 4216fc8

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

docs/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ the API is complete. It just means we won't break what currently exists.
5959
* Draw v3.0.0 (pl_draw_ext.h)
6060
* DXT v2.0.0 (pl_dxt_ext.h)
6161
* GPU Allocators v1.1.1 (pl_gpu_allocators_ext.h)
62-
* Graphics v2.0.1 (pl_graphics_ext.h)
62+
* Graphics v2.1.0 (pl_graphics_ext.h)
6363
* Image v1.2.0 (pl_image_ext.h)
6464
* Job v2.3.0 (pl_job_ext.h)
6565
* Atomics v2.0.0 (pl_platform_ext.h)

extensions/pl_graphics_ext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ extern "C" {
121121
// [SECTION] apis
122122
//-----------------------------------------------------------------------------
123123

124-
#define plGraphicsI_version {2, 0, 1}
124+
#define plGraphicsI_version {2, 1, 0}
125125

126126
//-----------------------------------------------------------------------------
127127
// [SECTION] includes
@@ -1404,6 +1404,7 @@ enum _plTextureType
14041404
{
14051405
PL_TEXTURE_TYPE_UNSPECIFIED,
14061406
PL_TEXTURE_TYPE_2D,
1407+
PL_TEXTURE_TYPE_3D,
14071408
PL_TEXTURE_TYPE_CUBE,
14081409
PL_TEXTURE_TYPE_2D_ARRAY
14091410
};

extensions/pl_graphics_metal.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@
617617

618618
if(tDesc.eType == PL_TEXTURE_TYPE_2D)
619619
ptTextureDescriptor.textureType = MTLTextureType2D;
620+
else if(tDesc.eType == PL_TEXTURE_TYPE_3D)
621+
ptTextureDescriptor.textureType = MTLTextureType3D;
620622
else if(tDesc.eType == PL_TEXTURE_TYPE_CUBE)
621623
ptTextureDescriptor.textureType = MTLTextureTypeCube;
622624
else if(tDesc.eType == PL_TEXTURE_TYPE_2D_ARRAY)
@@ -942,6 +944,8 @@
942944

943945
if(ptNewTexture->tDesc.eType == PL_TEXTURE_TYPE_2D)
944946
tTextureType = MTLTextureType2D;
947+
else if(ptNewTexture->tDesc.eType == PL_TEXTURE_TYPE_3D)
948+
tTextureType = MTLTextureType3D;
945949
else if(ptNewTexture->tDesc.eType == PL_TEXTURE_TYPE_CUBE)
946950
tTextureType = MTLTextureTypeCube;
947951
else if(ptNewTexture->tDesc.eType == PL_TEXTURE_TYPE_2D_ARRAY)

extensions/pl_graphics_vulkan.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,8 @@ pl_graphics_create_texture(plDevice* ptDevice, const plTextureDesc* ptDesc, plTe
13271327
VkImageViewType tImageViewType = 0;
13281328
if (tDesc.eType == PL_TEXTURE_TYPE_CUBE)
13291329
tImageViewType = VK_IMAGE_VIEW_TYPE_CUBE;
1330+
else if (tDesc.eType == PL_TEXTURE_TYPE_3D)
1331+
tImageViewType = VK_IMAGE_VIEW_TYPE_3D;
13301332
else if (tDesc.eType == PL_TEXTURE_TYPE_2D)
13311333
tImageViewType = VK_IMAGE_VIEW_TYPE_2D;
13321334
else if (tDesc.eType == PL_TEXTURE_TYPE_2D_ARRAY)
@@ -1350,7 +1352,7 @@ pl_graphics_create_texture(plDevice* ptDevice, const plTextureDesc* ptDesc, plTe
13501352

13511353
const VkImageCreateInfo tImageInfo = {
13521354
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
1353-
.imageType = VK_IMAGE_TYPE_2D,
1355+
.imageType = tDesc.eType == PL_TEXTURE_TYPE_3D ? VK_IMAGE_TYPE_3D : VK_IMAGE_TYPE_2D,
13541356
.extent.width = (uint32_t)tDesc.tDimensions.x,
13551357
.extent.height = (uint32_t)tDesc.tDimensions.y,
13561358
.extent.depth = (uint32_t)tDesc.tDimensions.z,
@@ -1410,6 +1412,8 @@ pl_graphics_bind_texture_to_memory(plDevice* ptDevice, plTextureHandle tHandle,
14101412
tImageViewType = VK_IMAGE_VIEW_TYPE_2D;
14111413
else if (ptTexture->tDesc.eType == PL_TEXTURE_TYPE_2D_ARRAY)
14121414
tImageViewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
1415+
else if (ptTexture->tDesc.eType == PL_TEXTURE_TYPE_3D)
1416+
tImageViewType = VK_IMAGE_VIEW_TYPE_3D;
14131417
else
14141418
{
14151419
PL_ASSERT(false && "unsupported texture type");
@@ -1530,6 +1534,8 @@ pl_graphics_create_texture_view(plDevice* ptDevice, const plTextureViewDesc* ptV
15301534
tImageViewType = VK_IMAGE_VIEW_TYPE_CUBE;
15311535
else if (ptNewTexture->tDesc.eType == PL_TEXTURE_TYPE_2D)
15321536
tImageViewType = VK_IMAGE_VIEW_TYPE_2D;
1537+
else if (ptNewTexture->tDesc.eType == PL_TEXTURE_TYPE_3D)
1538+
tImageViewType = VK_IMAGE_VIEW_TYPE_3D;
15331539
else if (ptNewTexture->tDesc.eType == PL_TEXTURE_TYPE_2D_ARRAY)
15341540
tImageViewType = VK_IMAGE_VIEW_TYPE_2D; // VK_IMAGE_VIEW_TYPE_2D_ARRAY;
15351541
else
@@ -4274,7 +4280,7 @@ pl_graphics_begin_compute_pass(plCommandBuffer* ptCmdBuffer, const plPassResourc
42744280
}
42754281
if(ptTexture->tDesc.eUsage & PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT)
42764282
{
4277-
// tSrcStageFlags |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; // TODO: does depth go here?
4283+
tSrcStageFlags |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; // TODO: does depth go here?
42784284
tBarrier.srcAccessMask |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
42794285
}
42804286
}
@@ -4363,6 +4369,7 @@ pl_graphics_end_compute_pass(plCommandBuffer* ptCmdBuffer)
43634369
if(ptTexture->tDesc.eUsage & PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT)
43644370
{
43654371
// tDstStageFlags |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; // TODO: does depth go here?
4372+
tDstStageFlags |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
43664373
tBarrier.dstAccessMask |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
43674374
}
43684375
}

extensions/pl_renderer_internal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ pl__renderer_generate_cascaded_shadow_map(plCommandBuffer* ptCommandBuffer, plSc
12831283
const float fCenterZ = 0.5f * (fZMin + fZMax);
12841284

12851285
// optional z padding for off-frustum casters
1286-
const float fDepthPadding = 5000.0f; // TODO: make option
1286+
const float fDepthPadding = 500.0f; // TODO: make option
12871287
const float fNearZ = fZMin - fDepthPadding;
12881288
const float fFarZ = fZMax + fDepthPadding;
12891289

0 commit comments

Comments
 (0)