Skip to content

Commit

Permalink
Propagate subgroup size properly when recreating graphics pipelines
Browse files Browse the repository at this point in the history
* Also add an additional indicator in the pipeline state view.
  • Loading branch information
baldurk committed Jan 10, 2024
1 parent 6862b62 commit 6fdea16
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,9 @@ void VulkanPipelineStateViewer::setShaderState(const VKPipe::Shader &stage,
shText += lit(" - ") + QFileInfo(dbg.files[entryFile].filename).fileName();
}

if(stage.requiredSubgroupSize != 0)
shText += tr(" (Subgroup size %1)").arg(stage.requiredSubgroupSize);

shader->setText(shText);

int vs = 0;
Expand Down
3 changes: 3 additions & 0 deletions renderdoc/api/replay/vk_pipestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ struct Shader
DOCUMENT("The number of bytes in the push constant data that is visible to this shader.");
uint32_t pushConstantRangeByteSize = 0;

DOCUMENT("The required subgroup size specified for this shader at pipeline creation time.");
uint32_t requiredSubgroupSize = 0;

DOCUMENT(R"(The provided specialization constant data. Shader constants store the byte offset into
this buffer as their byteOffset. This data includes the applied specialization constants over the
top of the default values, so it is safe to read any constant from here and get the correct current
Expand Down
14 changes: 14 additions & 0 deletions renderdoc/driver/vulkan/vk_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,13 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan,

Shader &shad = shaders[stageIndex];

VkPipelineShaderStageRequiredSubgroupSizeCreateInfo *subgroupSize =
(VkPipelineShaderStageRequiredSubgroupSizeCreateInfo *)FindNextStruct(
&pCreateInfo->pStages[i],
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO);
if(subgroupSize)
shad.requiredSubgroupSize = subgroupSize->requiredSubgroupSize;

shad.module = shadid;
shad.entryPoint = pCreateInfo->pStages[i].pName;
shad.stage = ShaderStage(stageIndex);
Expand Down Expand Up @@ -1470,6 +1477,13 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, Vulk
ResourceId shadid = GetResID(pCreateInfo->stage.module);
Shader &shad = shaders[5]; // 5 is the compute shader's index (VS, TCS, TES, GS, FS, CS)

VkPipelineShaderStageRequiredSubgroupSizeCreateInfo *subgroupSize =
(VkPipelineShaderStageRequiredSubgroupSizeCreateInfo *)FindNextStruct(
&pCreateInfo->stage,
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO);
if(subgroupSize)
shad.requiredSubgroupSize = subgroupSize->requiredSubgroupSize;

shad.module = shadid;
shad.entryPoint = pCreateInfo->stage.pName;

Expand Down
12 changes: 7 additions & 5 deletions renderdoc/driver/vulkan/vk_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,17 @@ struct VulkanCreationInfo
// VkPipelineShaderStageCreateInfo
struct Shader
{
Shader() : refl(NULL), mapping(NULL), patchData(NULL) {}
ResourceId module;
ShaderStage stage;
ShaderStage stage = ShaderStage::Count;
rdcstr entryPoint;
ShaderReflection *refl;
ShaderBindpointMapping *mapping;
SPIRVPatchData *patchData;
ShaderReflection *refl = NULL;
ShaderBindpointMapping *mapping = NULL;
SPIRVPatchData *patchData = NULL;

rdcarray<SpecConstant> specialization;

// VkPipelineShaderStageRequiredSubgroupSizeCreateInfo
uint32_t requiredSubgroupSize = 0;
};
Shader shaders[NumShaderStages];

Expand Down
4 changes: 4 additions & 0 deletions renderdoc/driver/vulkan/vk_replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,8 @@ void VulkanReplay::SavePipelineState(uint32_t eventId)
}
}

stage.requiredSubgroupSize = p.shaders[i].requiredSubgroupSize;

stage.specializationData.clear();

// set up the defaults
Expand Down Expand Up @@ -1256,6 +1258,8 @@ void VulkanReplay::SavePipelineState(uint32_t eventId)

stages[i]->specializationData.clear();

stages[i]->requiredSubgroupSize = p.shaders[i].requiredSubgroupSize;

// set up the defaults
if(p.shaders[i].mapping && p.shaders[i].refl)
{
Expand Down
20 changes: 20 additions & 0 deletions renderdoc/driver/vulkan/vk_shader_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ void VulkanShaderCache::MakeGraphicsPipelineInfo(VkGraphicsPipelineCreateInfo &p
uint32_t stageCount = 0;
uint32_t dataOffset = 0;

static VkPipelineShaderStageRequiredSubgroupSizeCreateInfo reqSubgroupSize[NumShaderStages] = {};

// reserve space for spec constants
for(uint32_t i = 0; i < NumShaderStages; i++)
{
Expand All @@ -581,6 +583,14 @@ void VulkanShaderCache::MakeGraphicsPipelineInfo(VkGraphicsPipelineCreateInfo &p
stages[stageCount].pNext = NULL;
stages[stageCount].pSpecializationInfo = NULL;

if(pipeInfo.shaders[i].requiredSubgroupSize != 0)
{
reqSubgroupSize[i].sType =
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO;
reqSubgroupSize[i].requiredSubgroupSize = pipeInfo.shaders[i].requiredSubgroupSize;
stages[stageCount].pNext = &reqSubgroupSize[i];
}

if(!pipeInfo.shaders[i].specialization.empty())
{
stages[stageCount].pSpecializationInfo = &specInfo[i];
Expand Down Expand Up @@ -1069,6 +1079,16 @@ void VulkanShaderCache::MakeComputePipelineInfo(VkComputePipelineCreateInfo &pip
specInfo.pData = specdata.data();
}

static VkPipelineShaderStageRequiredSubgroupSizeCreateInfo reqSubgroupSize = {
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO,
};

if(pipeInfo.shaders[i].requiredSubgroupSize != 0)
{
reqSubgroupSize.requiredSubgroupSize = pipeInfo.shaders[i].requiredSubgroupSize;
stage.pNext = &reqSubgroupSize;
}

VkComputePipelineCreateInfo ret = {
VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
NULL,
Expand Down

0 comments on commit 6fdea16

Please sign in to comment.