mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 23:01:50 +00:00
- improve shader error handling and attempt to remove some bogus declarations
This commit is contained in:
parent
d63513ec14
commit
47f056e882
6 changed files with 15 additions and 11 deletions
|
@ -300,7 +300,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
||||||
i_data += "uniform sampler2D texture6;\n";
|
i_data += "uniform sampler2D texture6;\n";
|
||||||
|
|
||||||
// timer data
|
// 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
|
// material types
|
||||||
i_data += "#if defined(SPECULAR)\n";
|
i_data += "#if defined(SPECULAR)\n";
|
||||||
|
|
|
@ -69,6 +69,10 @@ static bool isShaderType(const char *name)
|
||||||
FString RemoveLegacyUserUniforms(FString code)
|
FString RemoveLegacyUserUniforms(FString code)
|
||||||
{
|
{
|
||||||
// User shaders must declare their uniforms via the GLDEFS file.
|
// 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.
|
// The following code searches for legacy uniform declarations in the shader itself and replaces them with whitespace.
|
||||||
|
|
||||||
long len = (long)code.Len();
|
long len = (long)code.Len();
|
||||||
|
|
|
@ -394,12 +394,12 @@ VkPPShader::VkPPShader(PPShader *shader)
|
||||||
|
|
||||||
ShaderBuilder vertbuilder;
|
ShaderBuilder vertbuilder;
|
||||||
vertbuilder.setVertexShader(LoadShaderCode(shader->VertexShader, "", shader->Version));
|
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());
|
VertexShader->SetDebugName(shader->VertexShader.GetChars());
|
||||||
|
|
||||||
ShaderBuilder fragbuilder;
|
ShaderBuilder fragbuilder;
|
||||||
fragbuilder.setFragmentShader(LoadShaderCode(shader->FragmentShader, prolog, shader->Version));
|
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());
|
FragmentShader->SetDebugName(shader->FragmentShader.GetChars());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
|
||||||
|
|
||||||
ShaderBuilder builder;
|
ShaderBuilder builder;
|
||||||
builder.setVertexShader(code);
|
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)
|
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;
|
ShaderBuilder builder;
|
||||||
builder.setFragmentShader(code);
|
builder.setFragmentShader(code);
|
||||||
return builder.create(device);
|
return builder.create(shadername.GetChars(), device);
|
||||||
}
|
}
|
||||||
|
|
||||||
FString VkShaderManager::GetTargetGlslVersion()
|
FString VkShaderManager::GetTargetGlslVersion()
|
||||||
|
|
|
@ -128,7 +128,7 @@ void ShaderBuilder::setFragmentShader(const FString &c)
|
||||||
stage = EShLanguage::EShLangFragment;
|
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;
|
EShLanguage stage = (EShLanguage)this->stage;
|
||||||
const char *sources[] = { code.GetChars() };
|
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);
|
bool compileSuccess = shader.parse(&resources, 110, false, EShMsgVulkanRules);
|
||||||
if (!compileSuccess)
|
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;
|
glslang::TProgram program;
|
||||||
|
@ -151,13 +151,13 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
|
||||||
bool linkSuccess = program.link(EShMsgDefault);
|
bool linkSuccess = program.link(EShMsgDefault);
|
||||||
if (!linkSuccess)
|
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);
|
glslang::TIntermediate *intermediate = program.getIntermediate(stage);
|
||||||
if (!intermediate)
|
if (!intermediate)
|
||||||
{
|
{
|
||||||
I_FatalError("Internal shader compiler error");
|
I_FatalError("Internal shader compiler error while processing '%s'\n", shadername);
|
||||||
}
|
}
|
||||||
|
|
||||||
glslang::SpvOptions spvOptions;
|
glslang::SpvOptions spvOptions;
|
||||||
|
@ -177,7 +177,7 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(VulkanDevice *device)
|
||||||
VkShaderModule shaderModule;
|
VkShaderModule shaderModule;
|
||||||
VkResult result = vkCreateShaderModule(device->device, &createInfo, nullptr, &shaderModule);
|
VkResult result = vkCreateShaderModule(device->device, &createInfo, nullptr, &shaderModule);
|
||||||
if (result != VK_SUCCESS)
|
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);
|
return std::make_unique<VulkanShader>(device, shaderModule);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ public:
|
||||||
void setVertexShader(const FString &code);
|
void setVertexShader(const FString &code);
|
||||||
void setFragmentShader(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:
|
private:
|
||||||
FString code;
|
FString code;
|
||||||
|
|
Loading…
Reference in a new issue