Skip to content

Commit 5930639

Browse files
committed
gpu: ability to detect when pipeline creation is gonna be slow;
1 parent abf370d commit 5930639

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/core/gpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ typedef struct {
513513
const char* label;
514514
} gpu_compute_pipeline_info;
515515

516-
bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info);
516+
bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info, bool* slow);
517517
bool gpu_pipeline_init_compute(gpu_pipeline* pipeline, gpu_compute_pipeline_info* info);
518518
void gpu_pipeline_destroy(gpu_pipeline* pipeline);
519519
void gpu_pipeline_get_cache(void* data, size_t* size);

src/core/gpu_vk.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ typedef struct {
183183
bool dynamicRendering;
184184
bool scalarBlockLayout;
185185
bool foveation;
186+
bool pipelineCacheControl;
186187
} gpu_extensions;
187188

188189
// State
@@ -1344,7 +1345,7 @@ void gpu_bundle_write(gpu_bundle** bundles, gpu_bundle_info* infos, uint32_t cou
13441345

13451346
// Pipeline
13461347

1347-
bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info) {
1348+
bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info, bool* slow) {
13481349
static const VkPrimitiveTopology topologies[] = {
13491350
[GPU_DRAW_POINTS] = VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
13501351
[GPU_DRAW_LINES] = VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
@@ -1628,6 +1629,10 @@ bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info)
16281629
.layout = info->shader->pipelineLayout
16291630
};
16301631

1632+
if (state.extensions.pipelineCacheControl && slow) {
1633+
pipelineInfo.flags |= VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT;
1634+
}
1635+
16311636
if (state.extensions.dynamicRendering) {
16321637
pipelineInfo.pNext = &renderingInfo;
16331638
} else {
@@ -1699,16 +1704,19 @@ bool gpu_pipeline_init_graphics(gpu_pipeline* pipeline, gpu_pipeline_info* info)
16991704
condemn(pipelineInfo.renderPass, VK_OBJECT_TYPE_RENDER_PASS);
17001705
}
17011706

1702-
VK(vkCreateGraphicsPipelines(state.device, state.pipelineCache, 1, &pipelineInfo, NULL, &pipeline->handle), "vkCreateGraphicsPipelines") {
1703-
if (constants != stackConstants) state.config.fnFree(constants);
1704-
if (entries != stackEntries) state.config.fnFree(entries);
1705-
return false;
1706-
}
1707-
1708-
nickname(pipeline->handle, VK_OBJECT_TYPE_PIPELINE, info->label);
1707+
VkResult result = vkCreateGraphicsPipelines(state.device, state.pipelineCache, 1, &pipelineInfo, NULL, &pipeline->handle);
17091708
if (constants != stackConstants) state.config.fnFree(constants);
17101709
if (entries != stackEntries) state.config.fnFree(entries);
1711-
return true;
1710+
1711+
if (result < 0) {
1712+
return false;
1713+
} else if (result == VK_PIPELINE_COMPILE_REQUIRED_EXT) {
1714+
*slow = true;
1715+
return true;
1716+
} else {
1717+
if (slow) *slow = false;
1718+
return true;
1719+
}
17121720
}
17131721

17141722
bool gpu_pipeline_init_compute(gpu_pipeline* pipeline, gpu_compute_pipeline_info* info) {
@@ -2649,7 +2657,8 @@ bool gpu_init(gpu_config* config) {
26492657
{ "VK_KHR_synchronization2", true, &state.extensions.synchronization2 },
26502658
{ "VK_KHR_dynamic_rendering", true, &state.extensions.dynamicRendering },
26512659
{ "VK_EXT_scalar_block_layout", true, &state.extensions.scalarBlockLayout },
2652-
{ "VK_EXT_fragment_density_map", true, &state.extensions.foveation }
2660+
{ "VK_EXT_fragment_density_map", true, &state.extensions.foveation },
2661+
{ "VK_EXT_pipeline_creation_cache_control", true, &state.extensions.pipelineCacheControl }
26532662
};
26542663

26552664
uint32_t extensionCount = 0;
@@ -2741,6 +2750,7 @@ bool gpu_init(gpu_config* config) {
27412750
VkPhysicalDeviceDynamicRenderingFeaturesKHR dynamicRenderingFeatures = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES_KHR };
27422751
VkPhysicalDeviceScalarBlockLayoutFeaturesEXT scalarBlockLayoutFeatures = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT };
27432752
VkPhysicalDeviceFragmentDensityMapFeaturesEXT fragmentDensityMapFeatures = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_FEATURES_EXT };
2753+
VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT pipelineCreationCacheControlFeatures = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_CREATION_CACHE_CONTROL_FEATURES_EXT };
27442754

27452755
vkGetPhysicalDeviceFeatures2(state.adapter, &supported);
27462756

@@ -2790,6 +2800,11 @@ bool gpu_init(gpu_config* config) {
27902800
CHAIN(fragmentDensityMapFeatures);
27912801
}
27922802

2803+
if (state.extensions.pipelineCacheControl) {
2804+
pipelineCreationCacheControlFeatures.pipelineCreationCacheControl = true;
2805+
CHAIN(pipelineCreationCacheControlFeatures);
2806+
}
2807+
27932808
if (config->features) {
27942809
config->features->textureBC = enabled.features.textureCompressionBC;
27952810
config->features->textureASTC = enabled.features.textureCompressionASTC_LDR;

src/modules/graphics/graphics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ static bool recordRenderPass(Pass* pass, gpu_stream* stream) {
13681368
job->info = draw->pipelineInfo;
13691369
job->pipeline = getPipeline(index);
13701370

1371-
lovrAssert(gpu_pipeline_init_graphics(job->pipeline, job->info), "Failed to create GPU pipeline: %s", gpu_get_error());
1371+
lovrAssert(gpu_pipeline_init_graphics(job->pipeline, job->info, NULL), "Failed to create GPU pipeline: %s", gpu_get_error());
13721372

13731373
// Chain the new pipeline on to the list of new pipelines
13741374
job->next = atomic_load(&state.pipelineJobs);

0 commit comments

Comments
 (0)