Skip to content

Commit 41296ef

Browse files
Track spirv code and shader stage info for postprocessing
1 parent a678127 commit 41296ef

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

scripts/util.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def validate_funcs(lst):
158158
replay_post_calls = [ 'vkCreateInstance', 'vkDestroyInstance', 'vkQueuePresentKHR', 'vkAcquireNextImageKHR', 'vkAcquireNextImage2KHR',
159159
'vkGetBufferDeviceAddress', 'vkGetBufferDeviceAddressKHR', 'vkGetAccelerationStructureDeviceAddressKHR' ]
160160
validate_funcs(replay_post_calls)
161-
replay_postprocess_calls = [ 'vkCmdPushConstants', 'vkCmdPushConstants2KHR' ]
161+
replay_postprocess_calls = [ 'vkCmdPushConstants', 'vkCmdPushConstants2KHR', 'vkCreateRayTracingPipelinesKHR', 'vkCreateGraphicsPipelines',
162+
'vkCreateComputePipelines' ]
162163
validate_funcs(replay_postprocess_calls)
163164
trace_pre_calls = [ 'vkQueueSubmit', 'vkCreateInstance', 'vkCreateDevice', 'vkFreeMemory', 'vkQueueSubmit2', 'vkQueueSubmit2KHR' ]
164165
validate_funcs(trace_pre_calls)
@@ -1259,6 +1260,7 @@ def save_add_tracking(name):
12591260
z.do('add->cache = pipelineCache;')
12601261
if name == 'vkCreateGraphicsPipelines': z.do('add->type = VK_PIPELINE_BIND_POINT_GRAPHICS;')
12611262
elif name == 'vkCreateComputePipelines': z.do('add->type = VK_PIPELINE_BIND_POINT_COMPUTE;')
1263+
elif name == 'PFN_vkCreateRayTracingPipelinesKHR': z.do('add->type = VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR;')
12621264
elif type == 'VkSwapchainKHR':
12631265
z.do('add->info = pCreateInfos[i];')
12641266
z.do('DLOG2("insert %s into %s index %%u", (unsigned)add->index);' % (type, name))
@@ -1337,6 +1339,9 @@ def load_add_tracking(name):
13371339
z.do('data.format = pCreateInfo->format; // as above, might be missing in json')
13381340
elif type == 'VkDescriptorSet':
13391341
z.do('data.pool = pAllocateInfo->descriptorPool;')
1342+
elif type == 'VkShaderModule':
1343+
z.do('data.code.resize(pCreateInfo->codeSize);')
1344+
z.do('memcpy(data.code.data(), pCreateInfo->pCode, pCreateInfo->codeSize * sizeof(uint32_t));')
13401345
z.do('data.enter_created();')
13411346
else: # multiple
13421347
z.do('for (unsigned i = 0; i < %s; i++)' % count)

src/hardcode_read.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,63 @@ void replay_postprocess_vkCmdPushConstants2(lava_file_reader& reader, VkCommandB
10611061
replay_postprocess_vkCmdPushConstants2KHR(reader, commandBuffer, pPushConstantsInfo);
10621062
}
10631063

1064+
static void copy_shader_stage(shader_stage& stage, const VkPipelineShaderStageCreateInfo& info)
1065+
{
1066+
stage.flags = info.flags;
1067+
stage.module = info.module;
1068+
stage.name = info.pName;
1069+
if (info.pSpecializationInfo)
1070+
{
1071+
stage.specialization_constants.resize(info.pSpecializationInfo->mapEntryCount);
1072+
memcpy(stage.specialization_constants.data(), info.pSpecializationInfo->pMapEntries, info.pSpecializationInfo->mapEntryCount * sizeof(uint32_t));
1073+
stage.specialization_data.resize(info.pSpecializationInfo->dataSize);
1074+
memcpy(stage.specialization_data.data(), info.pSpecializationInfo->pData, info.pSpecializationInfo->dataSize);
1075+
}
1076+
}
1077+
1078+
void replay_postprocess_vkCreateComputePipelines(lava_file_reader& reader, VkResult result, VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1079+
const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
1080+
{
1081+
for (uint32_t i = 0; i < createInfoCount; i++)
1082+
{
1083+
const uint32_t pipeline_index = index_to_VkPipeline.index(pPipelines[i]);
1084+
trackedpipeline& pipeline_data = VkPipeline_index.at(pipeline_index);
1085+
pipeline_data.shader_stages.resize(1);
1086+
copy_shader_stage(pipeline_data.shader_stages[0], pCreateInfos[i].stage);
1087+
}
1088+
}
1089+
1090+
void replay_postprocess_vkCreateGraphicsPipelines(lava_file_reader& reader, VkResult result, VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1091+
const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
1092+
{
1093+
for (uint32_t i = 0; i < createInfoCount; i++)
1094+
{
1095+
const uint32_t pipeline_index = index_to_VkPipeline.index(pPipelines[i]);
1096+
trackedpipeline& pipeline_data = VkPipeline_index.at(pipeline_index);
1097+
pipeline_data.shader_stages.resize(pCreateInfos[i].stageCount);
1098+
for (uint32_t stage = 0; stage < pCreateInfos[i].stageCount; stage++)
1099+
{
1100+
copy_shader_stage(pipeline_data.shader_stages[0], pCreateInfos[i].pStages[stage]);
1101+
}
1102+
}
1103+
}
1104+
1105+
1106+
void replay_postprocess_vkCreateRayTracingPipelinesKHR(lava_file_reader& reader, VkResult result, VkDevice device, VkDeferredOperationKHR deferredOperation, VkPipelineCache pipelineCache,
1107+
uint32_t createInfoCount, const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines)
1108+
{
1109+
for (uint32_t i = 0; i < createInfoCount; i++)
1110+
{
1111+
const uint32_t pipeline_index = index_to_VkPipeline.index(pPipelines[i]);
1112+
trackedpipeline& pipeline_data = VkPipeline_index.at(pipeline_index);
1113+
pipeline_data.shader_stages.resize(pCreateInfos[i].stageCount);
1114+
for (uint32_t stage = 0; stage < pCreateInfos[i].stageCount; stage++)
1115+
{
1116+
copy_shader_stage(pipeline_data.shader_stages[0], pCreateInfos[i].pStages[stage]);
1117+
}
1118+
}
1119+
}
1120+
10641121
void replay_pre_vkCmdPushConstants2KHR(lava_file_reader& reader, VkCommandBuffer commandBuffer, const VkPushConstantsInfoKHR* pPushConstantsInfo)
10651122
{
10661123
assert(pPushConstantsInfo);

src/lavatube.h

+12
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ struct trackedshadermodule : trackable
197197
using trackable::trackable; // inherit constructor
198198
bool enables_device_address = false;
199199
size_t size = 0;
200+
std::vector<uint32_t> code; // only for replayer
200201
};
201202

202203
struct trackedmemoryobject : trackedobject
@@ -372,12 +373,23 @@ struct trackedfence : trackable
372373
int frame_delay = -1; // delay fuse uninitialized
373374
};
374375

376+
struct shader_stage
377+
{
378+
VkPipelineShaderStageCreateFlags flags;
379+
VkShaderStageFlagBits stage;
380+
VkShaderModule module;
381+
std::string name;
382+
std::vector<VkSpecializationMapEntry> specialization_constants;
383+
std::vector<char> specialization_data;
384+
};
385+
375386
struct trackedpipeline : trackable
376387
{
377388
using trackable::trackable; // inherit constructor
378389
VkPipelineBindPoint type = VK_PIPELINE_BIND_POINT_MAX_ENUM;
379390
VkPipelineCreateFlags flags = 0;
380391
VkPipelineCache cache = VK_NULL_HANDLE;
392+
std::vector<shader_stage> shader_stages; // only set for postprocessing
381393

382394
void self_test() const
383395
{

0 commit comments

Comments
 (0)