- improve shader error handling and attempt to remove some bogus declarations

This commit is contained in:
Magnus Norddahl 2019-04-18 01:20:28 +02:00
parent d63513ec14
commit 47f056e882
6 changed files with 15 additions and 11 deletions

View file

@ -300,7 +300,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
i_data += "uniform sampler2D texture6;\n";
// timer data
i_data += "uniform float timer;\n"; // To do: we must search user shaders for this declaration and remove it
i_data += "uniform float timer;\n";
// material types
i_data += "#if defined(SPECULAR)\n";

View file

@ -69,6 +69,10 @@ static bool isShaderType(const char *name)
FString RemoveLegacyUserUniforms(FString code)
{
// User shaders must declare their uniforms via the GLDEFS file.
code.Substitute("uniform sampler2D tex;", " ");
code.Substitute("uniform float timer;", " ");
// The following code searches for legacy uniform declarations in the shader itself and replaces them with whitespace.
long len = (long)code.Len();

View file

@ -394,12 +394,12 @@ VkPPShader::VkPPShader(PPShader *shader)
ShaderBuilder vertbuilder;
vertbuilder.setVertexShader(LoadShaderCode(shader->VertexShader, "", shader->Version));
VertexShader = vertbuilder.create(fb->device);
VertexShader = vertbuilder.create(shader->VertexShader.GetChars(), fb->device);
VertexShader->SetDebugName(shader->VertexShader.GetChars());
ShaderBuilder fragbuilder;
fragbuilder.setFragmentShader(LoadShaderCode(shader->FragmentShader, prolog, shader->Version));
FragmentShader = fragbuilder.create(fb->device);
FragmentShader = fragbuilder.create(shader->FragmentShader.GetChars(), fb->device);
FragmentShader->SetDebugName(shader->FragmentShader.GetChars());
}

View file

@ -226,7 +226,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
ShaderBuilder builder;
builder.setVertexShader(code);
return builder.create(device);
return builder.create(shadername.GetChars(), device);
}
std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername, const char *frag_lump, const char *material_lump, const char *light_lump, const char *defines, bool alphatest, bool gbufferpass)
@ -293,7 +293,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
ShaderBuilder builder;
builder.setFragmentShader(code);
return builder.create(device);
return builder.create(shadername.GetChars(), device);
}
FString VkShaderManager::GetTargetGlslVersion()

View file

@ -128,7 +128,7 @@ void ShaderBuilder::setFragmentShader(const FString &c)
stage = EShLanguage::EShLangFragment;
}
std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
std::unique_ptr<VulkanShader> ShaderBuilder::create(const char *shadername, VulkanDevice *device)
{
EShLanguage stage = (EShLanguage)this->stage;
const char *sources[] = { code.GetChars() };
@ -143,7 +143,7 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
bool compileSuccess = shader.parse(&resources, 110, false, EShMsgVulkanRules);
if (!compileSuccess)
{
I_FatalError("Shader compile failed: %s\n", shader.getInfoLog());
I_FatalError("Shader '%s' could not be compiled:\n%s\n", shadername, shader.getInfoLog());
}
glslang::TProgram program;
@ -151,13 +151,13 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
bool linkSuccess = program.link(EShMsgDefault);
if (!linkSuccess)
{
I_FatalError("Shader link failed: %s\n", program.getInfoLog());
I_FatalError("Shader '%s' could not be linked:\n%s\n", shadername, program.getInfoLog());
}
glslang::TIntermediate *intermediate = program.getIntermediate(stage);
if (!intermediate)
{
I_FatalError("Internal shader compiler error");
I_FatalError("Internal shader compiler error while processing '%s'\n", shadername);
}
glslang::SpvOptions spvOptions;
@ -177,7 +177,7 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
VkShaderModule shaderModule;
VkResult result = vkCreateShaderModule(device->device, &createInfo, nullptr, &shaderModule);
if (result != VK_SUCCESS)
I_FatalError("Could not create vulkan shader module");
I_FatalError("Could not create vulkan shader module for '%s'", shadername);
return std::make_unique<VulkanShader>(device, shaderModule);
}

View file

@ -108,7 +108,7 @@ public:
void setVertexShader(const FString &code);
void setFragmentShader(const FString &code);
std::unique_ptr<VulkanShader> create(VulkanDevice *device);
std::unique_ptr<VulkanShader> create(const char *shadername, VulkanDevice *device);
private:
FString code;