Skip to content

Commit 610ea05

Browse files
cursoragenttimfox
andcommitted
Vulkan: extract in-pass clears to vk_clear_attachments.c
Move vk_clear_color, vk_clear_depth, and vk_set_color_write_mask out of vk.c. Wire MSVC and document in ARCHITECTURE.md. Co-authored-by: Tim Fox <timfox@outlook.com>
1 parent 3348895 commit 610ea05

5 files changed

Lines changed: 89 additions & 73 deletions

File tree

docs/ARCHITECTURE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ src/
5858
│ │ ├── vk_volumetric_pass_compute.c Local volumetric shadows, froxel compute, composite, SMAA (split from vk.c)
5959
│ │ ├── vk_shutdown.c vk_shutdown, wait-idle, release_resources (split from vk.c)
6060
│ │ ├── vk_postfx_passes.c Bloom, SSAO/HBAO, OIT, SSR passes (split from vk.c)
61+
│ │ ├── vk_clear_attachments.c In-pass color/depth clear + dynamic color write mask (split from vk.c)
6162
│ │ ├── vk_fluidsim.c/h Fluid simulation module
6263
│ │ ├── vk_postfx.c/h PostFX (SSR, atmosphere, wind)
6364
│ │ ├── vk_flashlight.c/h Projected texture system

src/platform/win32/msvc2017/vulkan.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@
276276
<ClCompile Include="..\..\..\renderers\vulkan\vk_volumetric_pass_compute.c" />
277277
<ClCompile Include="..\..\..\renderers\vulkan\vk_shutdown.c" />
278278
<ClCompile Include="..\..\..\renderers\vulkan\vk_postfx_passes.c" />
279+
<ClCompile Include="..\..\..\renderers\vulkan\vk_clear_attachments.c" />
279280
<ClCompile Include="..\..\..\renderers\vulkan\vk_device.c" />
280281
<ClCompile Include="..\..\..\renderers\vulkan\vk_flashlight.c" />
281282
<ClCompile Include="..\..\..\renderers\vulkan\vk_flares.c" />

src/platform/win32/msvc2017/vulkan.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@
151151
<ClCompile Include="..\..\renderers\vulkan\vk_postfx_passes.c">
152152
<Filter>Source Files</Filter>
153153
</ClCompile>
154+
<ClCompile Include="..\..\renderers\vulkan\vk_clear_attachments.c">
155+
<Filter>Source Files</Filter>
156+
</ClCompile>
154157
<ClCompile Include="..\..\renderers\vulkan\vk_attachments.c">
155158
<Filter>Source Files</Filter>
156159
</ClCompile>

src/renderers/vulkan/vk.c

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,79 +1535,7 @@ static void record_buffer_memory_barrier(VkCommandBuffer cb, VkBuffer buffer, Vk
15351535

15361536

15371537
/* vk_occlusion_* / vk_reset_occlusion_visibility: vk_occlusion.c */
1538-
1539-
void vk_clear_color( const vec4_t color ) {
1540-
1541-
VkClearAttachment attachment;
1542-
VkClearRect clear_rect;
1543-
1544-
if ( !vk.active )
1545-
return;
1546-
if ( !vk.cmd || vk.cmd->command_buffer == VK_NULL_HANDLE || !vk.inRenderPass )
1547-
return;
1548-
1549-
attachment.colorAttachment = 0;
1550-
attachment.clearValue.color.float32[0] = color[0];
1551-
attachment.clearValue.color.float32[1] = color[1];
1552-
attachment.clearValue.color.float32[2] = color[2];
1553-
attachment.clearValue.color.float32[3] = color[3];
1554-
attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1555-
1556-
vk_get_scissor_rect( &clear_rect.rect );
1557-
clear_rect.baseArrayLayer = 0;
1558-
clear_rect.layerCount = 1;
1559-
1560-
qvkCmdClearAttachments( vk.cmd->command_buffer, 1, &attachment, 1, &clear_rect );
1561-
}
1562-
1563-
void vk_set_color_write_mask( qboolean r, qboolean g, qboolean b, qboolean a )
1564-
{
1565-
VkColorComponentFlags mask;
1566-
1567-
if ( !vk.active || !vk.colorWriteMaskDynamic || !qvkCmdSetColorWriteMaskEXT )
1568-
return;
1569-
1570-
mask = 0;
1571-
if ( r ) mask |= VK_COLOR_COMPONENT_R_BIT;
1572-
if ( g ) mask |= VK_COLOR_COMPONENT_G_BIT;
1573-
if ( b ) mask |= VK_COLOR_COMPONENT_B_BIT;
1574-
if ( a ) mask |= VK_COLOR_COMPONENT_A_BIT;
1575-
1576-
qvkCmdSetColorWriteMaskEXT( vk.cmd->command_buffer, 0, 1, &mask );
1577-
}
1578-
1579-
void vk_clear_depth( qboolean clear_stencil ) {
1580-
1581-
VkClearAttachment attachment;
1582-
VkClearRect clear_rect[1];
1583-
1584-
if ( !vk.active )
1585-
return;
1586-
if ( !vk.cmd || vk.cmd->command_buffer == VK_NULL_HANDLE || !vk.inRenderPass )
1587-
return;
1588-
1589-
if ( vk_world.dirty_depth_attachment == 0 )
1590-
return;
1591-
1592-
attachment.colorAttachment = 0;
1593-
#ifdef USE_REVERSED_DEPTH
1594-
attachment.clearValue.depthStencil.depth = 0.0f;
1595-
#else
1596-
attachment.clearValue.depthStencil.depth = 1.0f;
1597-
#endif
1598-
attachment.clearValue.depthStencil.stencil = 0;
1599-
if ( clear_stencil && glConfig.stencilBits > 0 ) {
1600-
attachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
1601-
} else {
1602-
attachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1603-
}
1604-
1605-
vk_get_scissor_rect( &clear_rect[0].rect );
1606-
clear_rect[0].baseArrayLayer = 0;
1607-
clear_rect[0].layerCount = 1;
1608-
1609-
qvkCmdClearAttachments( vk.cmd->command_buffer, 1, &attachment, 1, clear_rect );
1610-
}
1538+
/* vk_clear_color, vk_clear_depth, vk_set_color_write_mask: vk_clear_attachments.c */
16111539

16121540
/* vk_bind_*, vk_alloc_storage, vk_tess_index, vk_*descriptor*, vk_draw_*: vk_draw_state.c */
16131541

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
===========================================================================
3+
Copyright (C) 2026 Gopex LLC. All rights reserved.
4+
5+
In-render-pass color/depth clears and dynamic color write mask.
6+
Split from vk.c.
7+
===========================================================================
8+
*/
9+
10+
#include "tr_local.h"
11+
12+
void vk_clear_color( const vec4_t color )
13+
{
14+
VkClearAttachment attachment;
15+
VkClearRect clear_rect;
16+
17+
if ( !vk.active )
18+
return;
19+
if ( !vk.cmd || vk.cmd->command_buffer == VK_NULL_HANDLE || !vk.inRenderPass )
20+
return;
21+
22+
attachment.colorAttachment = 0;
23+
attachment.clearValue.color.float32[0] = color[0];
24+
attachment.clearValue.color.float32[1] = color[1];
25+
attachment.clearValue.color.float32[2] = color[2];
26+
attachment.clearValue.color.float32[3] = color[3];
27+
attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
28+
29+
vk_get_scissor_rect( &clear_rect.rect );
30+
clear_rect.baseArrayLayer = 0;
31+
clear_rect.layerCount = 1;
32+
33+
qvkCmdClearAttachments( vk.cmd->command_buffer, 1, &attachment, 1, &clear_rect );
34+
}
35+
36+
void vk_set_color_write_mask( qboolean r, qboolean g, qboolean b, qboolean a )
37+
{
38+
VkColorComponentFlags mask;
39+
40+
if ( !vk.active || !vk.colorWriteMaskDynamic || !qvkCmdSetColorWriteMaskEXT )
41+
return;
42+
43+
mask = 0;
44+
if ( r ) mask |= VK_COLOR_COMPONENT_R_BIT;
45+
if ( g ) mask |= VK_COLOR_COMPONENT_G_BIT;
46+
if ( b ) mask |= VK_COLOR_COMPONENT_B_BIT;
47+
if ( a ) mask |= VK_COLOR_COMPONENT_A_BIT;
48+
49+
qvkCmdSetColorWriteMaskEXT( vk.cmd->command_buffer, 0, 1, &mask );
50+
}
51+
52+
void vk_clear_depth( qboolean clear_stencil )
53+
{
54+
VkClearAttachment attachment;
55+
VkClearRect clear_rect[1];
56+
57+
if ( !vk.active )
58+
return;
59+
if ( !vk.cmd || vk.cmd->command_buffer == VK_NULL_HANDLE || !vk.inRenderPass )
60+
return;
61+
62+
if ( vk_world.dirty_depth_attachment == 0 )
63+
return;
64+
65+
attachment.colorAttachment = 0;
66+
#ifdef USE_REVERSED_DEPTH
67+
attachment.clearValue.depthStencil.depth = 0.0f;
68+
#else
69+
attachment.clearValue.depthStencil.depth = 1.0f;
70+
#endif
71+
attachment.clearValue.depthStencil.stencil = 0;
72+
if ( clear_stencil && glConfig.stencilBits > 0 ) {
73+
attachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
74+
} else {
75+
attachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
76+
}
77+
78+
vk_get_scissor_rect( &clear_rect[0].rect );
79+
clear_rect[0].baseArrayLayer = 0;
80+
clear_rect[0].layerCount = 1;
81+
82+
qvkCmdClearAttachments( vk.cmd->command_buffer, 1, &attachment, 1, clear_rect );
83+
}

0 commit comments

Comments
 (0)