Skip to content

Commit caa5e67

Browse files
authored
Merge pull request #16683 from hrydgard/minor-fixes
Assorted fixes after looking at crash data
2 parents 25cf61f + 9ceffa2 commit caa5e67

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed

Common/GPU/Vulkan/VulkanContext.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ VkResult VulkanContext::CreateDevice() {
719719
allocatorInfo.physicalDevice = physical_devices_[physical_device_];
720720
allocatorInfo.device = device_;
721721
allocatorInfo.instance = instance_;
722-
vmaCreateAllocator(&allocatorInfo, &allocator_);
722+
VkResult result = vmaCreateAllocator(&allocatorInfo, &allocator_);
723+
_assert_(result == VK_SUCCESS);
724+
_assert_(allocator_ != VK_NULL_HANDLE);
723725

724726
// Examine the physical device to figure out super rough performance grade.
725727
// Basically all we want to do is to identify low performance mobile devices

Common/GPU/Vulkan/VulkanRenderManager.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,28 @@ bool VKRGraphicsPipeline::Create(VulkanContext *vulkan, VkRenderPass compatibleR
3737
}
3838
}
3939

40+
// Sanity check.
41+
// Seen in crash reports from PowerVR GE8320, presumably we failed creating some shader modules.
42+
if (!desc->vertexShader || !desc->fragmentShader) {
43+
ERROR_LOG(G3D, "Failed creating graphics pipeline - missing vs/fs shader module pointers!");
44+
pipeline[(size_t)rpType]->Post(VK_NULL_HANDLE);
45+
return false;
46+
}
47+
4048
// Fill in the last part of the desc since now it's time to block.
4149
VkShaderModule vs = desc->vertexShader->BlockUntilReady();
4250
VkShaderModule fs = desc->fragmentShader->BlockUntilReady();
4351
VkShaderModule gs = desc->geometryShader ? desc->geometryShader->BlockUntilReady() : VK_NULL_HANDLE;
4452

4553
if (!vs || !fs || (!gs && desc->geometryShader)) {
4654
ERROR_LOG(G3D, "Failed creating graphics pipeline - missing shader modules");
47-
// We're kinda screwed here?
55+
pipeline[(size_t)rpType]->Post(VK_NULL_HANDLE);
4856
return false;
4957
}
5058

5159
if (!compatibleRenderPass) {
52-
ERROR_LOG(G3D, "Failed creating graphics pipeline - compatible render pass was null");
53-
// We're kinda screwed here?
60+
ERROR_LOG(G3D, "Failed creating graphics pipeline - compatible render pass was nullptr");
61+
pipeline[(size_t)rpType]->Post(VK_NULL_HANDLE);
5462
return false;
5563
}
5664

@@ -527,8 +535,12 @@ VkCommandBuffer VulkanRenderManager::GetInitCmd() {
527535

528536
VKRGraphicsPipeline *VulkanRenderManager::CreateGraphicsPipeline(VKRGraphicsPipelineDesc *desc, PipelineFlags pipelineFlags, uint32_t variantBitmask, VkSampleCountFlagBits sampleCount, const char *tag) {
529537
VKRGraphicsPipeline *pipeline = new VKRGraphicsPipeline(pipelineFlags, tag);
530-
_dbg_assert_(desc->vertexShader);
531-
_dbg_assert_(desc->fragmentShader);
538+
539+
if (!desc->vertexShader || !desc->fragmentShader) {
540+
ERROR_LOG(G3D, "Can't create graphics pipeline with missing vs/ps: %p %p", desc->vertexShader, desc->fragmentShader);
541+
return nullptr;
542+
}
543+
532544
pipeline->desc = desc;
533545
pipeline->desc->AddRef();
534546
if (curRenderStep_) {
@@ -634,6 +646,10 @@ void VulkanRenderManager::EndCurRenderStep() {
634646
compileMutex_.lock();
635647
bool needsCompile = false;
636648
for (VKRGraphicsPipeline *pipeline : pipelinesToCheck_) {
649+
if (!pipeline) {
650+
// Not good, but let's try not to crash.
651+
continue;
652+
}
637653
if (!pipeline->pipeline[(size_t)rpType]) {
638654
pipeline->pipeline[(size_t)rpType] = Promise<VkPipeline>::CreateEmpty();
639655
_assert_(renderPass);

GPU/Vulkan/PipelineManagerVulkan.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,25 @@ static std::string CutFromMain(std::string str) {
180180
static VulkanPipeline *CreateVulkanPipeline(VulkanRenderManager *renderManager, VkPipelineCache pipelineCache,
181181
VkPipelineLayout layout, PipelineFlags pipelineFlags, VkSampleCountFlagBits sampleCount, const VulkanPipelineRasterStateKey &key,
182182
const DecVtxFormat *decFmt, VulkanVertexShader *vs, VulkanFragmentShader *fs, VulkanGeometryShader *gs, bool useHwTransform, u32 variantBitmask) {
183+
184+
if (!fs->GetModule()) {
185+
ERROR_LOG(G3D, "Fragment shader missing in CreateVulkanPipeline");
186+
return nullptr;
187+
}
188+
if (!vs->GetModule()) {
189+
ERROR_LOG(G3D, "Vertex shader missing in CreateVulkanPipeline");
190+
return nullptr;
191+
}
192+
183193
VulkanPipeline *vulkanPipeline = new VulkanPipeline();
184194
vulkanPipeline->desc = new VKRGraphicsPipelineDesc();
185195
VKRGraphicsPipelineDesc *desc = vulkanPipeline->desc;
186196
desc->pipelineCache = pipelineCache;
187197

198+
desc->fragmentShader = fs->GetModule();
199+
desc->vertexShader = vs->GetModule();
200+
desc->geometryShader = gs ? gs->GetModule() : nullptr;
201+
188202
PROFILE_THIS_SCOPE("pipelinebuild");
189203
bool useBlendConstant = false;
190204

@@ -257,9 +271,6 @@ static VulkanPipeline *CreateVulkanPipeline(VulkanRenderManager *renderManager,
257271
rs.polygonMode = VK_POLYGON_MODE_FILL;
258272
rs.depthClampEnable = key.depthClampEnable;
259273

260-
desc->fragmentShader = fs->GetModule();
261-
desc->vertexShader = vs->GetModule();
262-
desc->geometryShader = gs ? gs->GetModule() : nullptr;
263274
desc->fragmentShaderSource = fs->GetShaderString(SHADER_STRING_SOURCE_CODE);
264275
desc->vertexShaderSource = vs->GetShaderString(SHADER_STRING_SOURCE_CODE);
265276
if (gs) {
@@ -360,6 +371,8 @@ VulkanPipeline *PipelineManagerVulkan::GetOrCreatePipeline(VulkanRenderManager *
360371
VulkanPipeline *pipeline = CreateVulkanPipeline(
361372
renderManager, pipelineCache_, layout, pipelineFlags, sampleCount,
362373
rasterKey, decFmt, vs, fs, gs, useHwTransform, variantBitmask);
374+
375+
// If the above failed, we got a null pipeline. We still insert it to keep track.
363376
pipelines_.Insert(key, pipeline);
364377

365378
// Don't return placeholder null pipelines.

GPU/Vulkan/ShaderManagerVulkan.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id,
119119
VulkanFragmentShader::~VulkanFragmentShader() {
120120
if (module_) {
121121
VkShaderModule shaderModule = module_->BlockUntilReady();
122-
vulkan_->Delete().QueueDeleteShaderModule(shaderModule);
122+
if (shaderModule) {
123+
vulkan_->Delete().QueueDeleteShaderModule(shaderModule);
124+
}
123125
vulkan_->Delete().QueueCallback([](void *m) {
124126
auto module = (Promise<VkShaderModule> *)m;
125127
delete module;
@@ -152,7 +154,9 @@ VulkanVertexShader::VulkanVertexShader(VulkanContext *vulkan, VShaderID id, Vert
152154
VulkanVertexShader::~VulkanVertexShader() {
153155
if (module_) {
154156
VkShaderModule shaderModule = module_->BlockUntilReady();
155-
vulkan_->Delete().QueueDeleteShaderModule(shaderModule);
157+
if (shaderModule) {
158+
vulkan_->Delete().QueueDeleteShaderModule(shaderModule);
159+
}
156160
vulkan_->Delete().QueueCallback([](void *m) {
157161
auto module = (Promise<VkShaderModule> *)m;
158162
delete module;
@@ -185,7 +189,9 @@ VulkanGeometryShader::VulkanGeometryShader(VulkanContext *vulkan, GShaderID id,
185189
VulkanGeometryShader::~VulkanGeometryShader() {
186190
if (module_) {
187191
VkShaderModule shaderModule = module_->BlockUntilReady();
188-
vulkan_->Delete().QueueDeleteShaderModule(shaderModule);
192+
if (shaderModule) {
193+
vulkan_->Delete().QueueDeleteShaderModule(shaderModule);
194+
}
189195
vulkan_->Delete().QueueCallback([](void *m) {
190196
auto module = (Promise<VkShaderModule> *)m;
191197
delete module;

UI/NativeApp.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,9 @@ bool CreateGlobalPipelines() {
985985
void NativeShutdownGraphics() {
986986
INFO_LOG(SYSTEM, "NativeShutdownGraphics");
987987

988-
screenManager->deviceLost();
988+
if (screenManager) {
989+
screenManager->deviceLost();
990+
}
989991

990992
if (gpu)
991993
gpu->DeviceLost();

0 commit comments

Comments
 (0)