Skip to content

Commit

Permalink
Fix bug in vulkan init. Add some sanity checks to GL shader cache loa…
Browse files Browse the repository at this point in the history
…ding.
  • Loading branch information
hrydgard committed Aug 28, 2017
1 parent 6a0f657 commit 871fa71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
14 changes: 7 additions & 7 deletions Common/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ VkResult VulkanContext::CreateInstance(const char *app_name, int app_ver, uint32
// init_error_ = "Failed to validate instance layers";
// return;
}

GetDeviceLayerProperties();
if (!CheckLayers(device_layer_properties_, device_layer_names_)) {
WLOG("CheckLayers failed (2)");
// init_error_ = "Failed to validate device layers";
// return;
}
return VK_SUCCESS;
}

Expand Down Expand Up @@ -534,6 +527,13 @@ bool VulkanContext::CheckLayers(const std::vector<LayerProperties> &layer_props,
void VulkanContext::ChooseDevice(int physical_device) {
physical_device_ = physical_device;

GetDeviceLayerProperties();
if (!CheckLayers(device_layer_properties_, device_layer_names_)) {
WLOG("CheckLayers failed (2)");
// init_error_ = "Failed to validate device layers";
// return;
}

vkGetPhysicalDeviceQueueFamilyProperties(physical_devices_[physical_device_], &queue_count, nullptr);
assert(queue_count >= 1);

Expand Down
20 changes: 12 additions & 8 deletions GPU/GLES/ShaderManagerGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,21 +1009,25 @@ void ShaderManagerGLES::LoadAndPrecompile(const std::string &filename) {
time_update();
double start = time_now_d();

// Sanity check the file contents
if (header.numFragmentShaders > 1000 || header.numVertexShaders > 1000 || header.numLinkedPrograms > 1000)
return;

for (int i = 0; i < header.numVertexShaders; i++) {
ShaderID id;
if (!f.ReadArray(&id, 1)) {
ERROR_LOG(G3D, "Truncated shader cache file, aborting.");
return;
}
Shader *vs = CompileVertexShader(id);
if (vs->Failed()) {
// Give up on using the cache, just bail. We can't safely create the fallback shaders here
// without trying to deduce the vertType from the VSID.
ERROR_LOG(G3D, "Failed to compile a vertex shader loading from cache. Skipping rest of shader cache.");
delete vs;
return;
}
if (!vsCache_.Get(id)) {
Shader *vs = CompileVertexShader(id);
if (vs->Failed()) {
// Give up on using the cache, just bail. We can't safely create the fallback shaders here
// without trying to deduce the vertType from the VSID.
ERROR_LOG(G3D, "Failed to compile a vertex shader loading from cache. Skipping rest of shader cache.");
delete vs;
return;
}
vsCache_.Insert(id, vs);
} else {
WARN_LOG(G3D, "Duplicate vertex shader found in GL shader cache, ignoring");
Expand Down

0 comments on commit 871fa71

Please sign in to comment.