Skip to content

Commit

Permalink
Vulkan: added descriptor index definitions
Browse files Browse the repository at this point in the history
Co-Authored-By: Eugene <[email protected]>
  • Loading branch information
JKSunny and ec- committed Feb 11, 2024
1 parent 82ffb3c commit fdf7bfb
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion codemp/rd-vulkan/vk_bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ qboolean vk_bloom( void )
// restore clobbered descriptor sets
for ( i = 0; i < VK_NUM_BLUR_PASSES; i++ ) {
if ( vk.cmd->descriptor_set.current[i] != VK_NULL_HANDLE ) {
if ( i == 0 || i == 1 )
if ( i == VK_DESC_STORAGE || i == VK_DESC_UNIFORM )
qvkCmdBindDescriptorSets (vk.cmd->command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk.pipeline_layout, i, 1, &vk.cmd->descriptor_set.current[i], 1, &vk.cmd->descriptor_set.offset[i] );
else
qvkCmdBindDescriptorSets( vk.cmd->command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk.pipeline_layout, i, 1, &vk.cmd->descriptor_set.current[i], 0, NULL );
Expand Down
5 changes: 3 additions & 2 deletions codemp/rd-vulkan/vk_dynamic_glow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ qboolean vk_begin_dglow_blur( void )
vk.cmd->depth_range = DEPTH_RANGE_COUNT;

// restore clobbered descriptor sets
for ( i = 0; i < ( ( vk.maxBoundDescriptorSets >= 6 ) ? 7 : 4 ); i++ ) {
//for ( i = 0; i < ( ( vk.maxBoundDescriptorSets >= 6 ) ? 7 : 4 ); i++ ) {
for ( i = 0; i < VK_DESC_COUNT; i++ ) {
if ( vk.cmd->descriptor_set.current[i] != VK_NULL_HANDLE ) {
if ( i == 0 || i == 1 )
if ( i == VK_DESC_STORAGE || i == VK_DESC_UNIFORM )
qvkCmdBindDescriptorSets( vk.cmd->command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk.pipeline_layout, i, 1, &vk.cmd->descriptor_set.current[i], 1, &vk.cmd->descriptor_set.offset[i] );
else
qvkCmdBindDescriptorSets( vk.cmd->command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk.pipeline_layout, i, 1, &vk.cmd->descriptor_set.current[i], 0, NULL );
Expand Down
14 changes: 7 additions & 7 deletions codemp/rd-vulkan/vk_flares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ static void RB_TestFlare( flare_t *f ) {
tess.vboIndex = 0;
#endif
// render test dot
vk_bind_pipeline(vk.std_pipeline.dot_pipeline);
vk_reset_descriptor(0);
vk_update_descriptor(0, vk.storage.descriptor);
vk_update_descriptor_offset(0, offset);

vk_bind_geometry(TESS_XYZ);
vk_draw_geometry(DEPTH_RANGE_NORMAL, qfalse);
vk_reset_descriptor( VK_DESC_STORAGE );
vk_update_descriptor( VK_DESC_STORAGE, vk.storage.descriptor );
vk_update_descriptor_offset( VK_DESC_STORAGE, offset );

vk_bind_pipeline( vk.std_pipeline.dot_pipeline );
vk_bind_geometry( TESS_XYZ );
vk_draw_geometry( DEPTH_RANGE_NORMAL, qfalse );

if (visible) {
if (!f->visible) {
Expand Down
8 changes: 4 additions & 4 deletions codemp/rd-vulkan/vk_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,10 +1178,10 @@ void vk_begin_frame( void )

Com_Memset(&vk.cmd->scissor_rect, 0, sizeof(vk.cmd->scissor_rect));

vk_update_descriptor(2, tr.whiteImage->descriptor_set);
vk_update_descriptor(3, tr.whiteImage->descriptor_set);
if (vk.maxBoundDescriptorSets >= 6) {
vk_update_descriptor(4, tr.whiteImage->descriptor_set);
vk_update_descriptor( VK_DESC_TEXTURE0, tr.whiteImage->descriptor_set );
vk_update_descriptor( VK_DESC_TEXTURE1, tr.whiteImage->descriptor_set );
if ( vk.maxBoundDescriptorSets >= VK_DESC_COUNT ) {
vk_update_descriptor( VK_DESC_TEXTURE2, tr.whiteImage->descriptor_set );
}

#ifdef USE_VK_STATS
Expand Down
15 changes: 13 additions & 2 deletions codemp/rd-vulkan/vk_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,18 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
// depth + msaa + msaa-resolve + screenmap.msaa + screenmap.resolve + screenmap.depth + (bloom_extract + blur pairs + dglow_extract + blur pairs) + dglow-msaa
#define MAX_ATTACHMENTS_IN_POOL ( 6 + ( ( 1 + VK_NUM_BLUR_PASSES * 2 ) * 2 ) + 1 )

#define VK_SAMPLER_LAYOUT_BEGIN 2
#define VK_DESC_STORAGE 0
#define VK_DESC_UNIFORM 1
#define VK_DESC_TEXTURE0 2
#define VK_DESC_TEXTURE1 3
#define VK_DESC_TEXTURE2 4
#define VK_DESC_FOG_COLLAPSE 5
#define VK_DESC_COUNT 6

#define VK_DESC_TEXTURE_BASE VK_DESC_TEXTURE0
#define VK_DESC_FOG_ONLY VK_DESC_TEXTURE1
#define VK_DESC_FOG_DLIGHT VK_DESC_TEXTURE1

//#define MIN_IMAGE_ALIGN ( 128 * 1024 )

#define VERTEX_BUFFER_SIZE ( 4 * 1024 * 1024 )
Expand Down Expand Up @@ -566,7 +577,7 @@ typedef struct vk_tess_s {

struct {
uint32_t start, end;
VkDescriptorSet current[7]; // 0:storage, 1:uniform, 2:color0, 3:color1, 4:color2, 5:fog
VkDescriptorSet current[6]; // 0:storage, 1:uniform, 2:color0, 3:color1, 4:color2, 5:fog
uint32_t offset[2]; // 0:storage, 1:uniform
} descriptor_set;

Expand Down
5 changes: 2 additions & 3 deletions codemp/rd-vulkan/vk_pipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void vk_create_descriptor_layout( void )
void vk_create_pipeline_layout( void )
{
// Pipeline layouts
VkDescriptorSetLayout set_layouts[7];
VkDescriptorSetLayout set_layouts[6];
VkPipelineLayoutCreateInfo desc;
VkPushConstantRange push_range;

Expand All @@ -107,12 +107,11 @@ void vk_create_pipeline_layout( void )
set_layouts[3] = vk.set_layout_sampler; // lightmap / fog-only
set_layouts[4] = vk.set_layout_sampler; // blend
set_layouts[5] = vk.set_layout_sampler; // collapsed fog texture
set_layouts[6] = vk.set_layout_sampler; // normalMap

desc.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
desc.pNext = NULL;
desc.flags = 0;
desc.setLayoutCount = (vk.maxBoundDescriptorSets >= 6) ? 7 : 4;
desc.setLayoutCount = (vk.maxBoundDescriptorSets >= VK_DESC_COUNT) ? VK_DESC_COUNT : 4;
desc.pSetLayouts = set_layouts;
desc.pushConstantRangeCount = 1;
desc.pPushConstantRanges = &push_range;
Expand Down
29 changes: 14 additions & 15 deletions codemp/rd-vulkan/vk_shade_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ void vk_bind_descriptor_sets( void )
end = vk.cmd->descriptor_set.end;

offset_count = 0;
if (start <= 1) { // uniform offset or storage offset
if ( start == VK_DESC_STORAGE || start == VK_DESC_UNIFORM ) { // uniform offset or storage offset
offsets[offset_count++] = vk.cmd->descriptor_set.offset[start];
}

Expand Down Expand Up @@ -984,10 +984,9 @@ static uint32_t vk_push_uniform( const vkUniform_t *uniform )
{
const uint32_t offset = vk_append_uniform( uniform, sizeof(*uniform), vk.uniform_item_size );

vk_reset_descriptor( 1 );
vk_update_descriptor( 1, vk.cmd->uniform_descriptor );

vk_update_descriptor_offset( 1, offset );
vk_reset_descriptor( VK_DESC_UNIFORM );
vk_update_descriptor( VK_DESC_UNIFORM, vk.cmd->uniform_descriptor );
vk_update_descriptor_offset( VK_DESC_UNIFORM, offset );

return offset;
}
Expand Down Expand Up @@ -1120,11 +1119,11 @@ static void RB_FogPass( void ) {
#ifdef USE_FOG_ONLY
int fog_stage;

vk_bind_pipeline(pipeline);
vk_set_fog_params(&uniform, &fog_stage);
vk_push_uniform(&uniform);
vk_update_descriptor(3, tr.fogImage->descriptor_set);
vk_draw_geometry(DEPTH_RANGE_NORMAL, qtrue);
vk_bind_pipeline( pipeline );
vk_set_fog_params( &uniform, &fog_stage );
vk_push_uniform( &uniform );
vk_update_descriptor( VK_DESC_FOG_ONLY, tr.fogImage->descriptor_set );
vk_draw_geometry( DEPTH_RANGE_NORMAL, qtrue );
#else
const fog_t *fog;
int i;
Expand Down Expand Up @@ -1153,7 +1152,7 @@ void vk_bind( image_t *image ) {

image->frameUsed = tr.frameCount;

vk_update_descriptor(vk.ctmu + VK_SAMPLER_LAYOUT_BEGIN, image->descriptor_set);
vk_update_descriptor( vk.ctmu + VK_DESC_TEXTURE_BASE, image->descriptor_set );
}

void R_BindAnimatedImage( const textureBundle_t *bundle ) {
Expand All @@ -1171,7 +1170,7 @@ void R_BindAnimatedImage( const textureBundle_t *bundle ) {
}
else {

vk_update_descriptor( vk.ctmu + VK_SAMPLER_LAYOUT_BEGIN, vk.screenMap.color_descriptor );
vk_update_descriptor( vk.ctmu + VK_DESC_TEXTURE_BASE, vk.screenMap.color_descriptor );
}
return;
}
Expand Down Expand Up @@ -1481,7 +1480,7 @@ void vk_lighting_pass( void )
abs_light = /* (pStage->stateBits & GLS_ATEST_BITS) && */ (cull == CT_TWO_SIDED) ? 1 : 0;

if (fog_stage)
vk_update_descriptor(3, tr.fogImage->descriptor_set);
vk_update_descriptor( VK_DESC_FOG_DLIGHT, tr.fogImage->descriptor_set );

if (tess.light->linear)
pipeline = vk.std_pipeline.dlight1_pipelines_x[cull][tess.shader->polygonOffset][fog_stage][abs_light];
Expand Down Expand Up @@ -1563,7 +1562,7 @@ void RB_StageIteratorGeneric( void )
if ( fogCollapse ) {
vk_set_fog_params( &uniform, &fog_stage );
VectorCopy( backEnd.ori.viewOrigin, uniform.eyePos );
vk_update_descriptor( 5, tr.fogImage->descriptor_set );
vk_update_descriptor( VK_DESC_FOG_COLLAPSE, tr.fogImage->descriptor_set );
push_uniform = qtrue;
}
else {
Expand Down Expand Up @@ -1708,7 +1707,7 @@ void RB_StageIteratorGeneric( void )
if ( is_refraction )
{
// bind extracted color image copy / blit
vk_update_descriptor( 2, vk.refraction_extract_descriptor );
vk_update_descriptor( VK_DESC_TEXTURE0, vk.refraction_extract_descriptor );

Com_Memset( &uniform.refraction, 0, sizeof(uniform.refraction) );

Expand Down

0 comments on commit fdf7bfb

Please sign in to comment.