Fix #139191: GPU: Blender crashes on startup with addons that use pyGPU shader
This was caused by missing `shader->constants`. Creating an empty `SpecializationConstants` fixes the issue.
This commit is contained in:
@@ -132,6 +132,10 @@ GPUShader *GPU_shader_create_ex(const std::optional<StringRefNull> vertcode,
|
||||
computecode.has_value()));
|
||||
|
||||
Shader *shader = GPUBackend::get()->shader_alloc(shname.c_str());
|
||||
/* Needs to be called before init as GL uses the default specialization constants state to insert
|
||||
* default shader inside a map. */
|
||||
shader->constants = std::make_unique<const shader::SpecializationConstants>();
|
||||
shader->init();
|
||||
|
||||
if (vertcode) {
|
||||
Vector<StringRefNull> sources;
|
||||
|
||||
@@ -71,6 +71,8 @@ class Shader {
|
||||
|
||||
/* TODO: Remove `is_batch_compilation`. */
|
||||
virtual void init(const shader::ShaderCreateInfo &info, bool is_batch_compilation) = 0;
|
||||
/* Variant for legacy python shaders. To be removed, not supported in Vulkan or Metal. */
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual void vertex_shader_from_glsl(MutableSpan<StringRefNull> sources) = 0;
|
||||
virtual void geometry_shader_from_glsl(MutableSpan<StringRefNull> sources) = 0;
|
||||
|
||||
@@ -234,6 +234,7 @@ class MTLShader : public Shader {
|
||||
~MTLShader();
|
||||
|
||||
void init(const shader::ShaderCreateInfo & /*info*/, bool is_batch_compilation) override;
|
||||
void init() override {}
|
||||
|
||||
/* Assign GLSL source. */
|
||||
void vertex_shader_from_glsl(MutableSpan<StringRefNull> sources) override;
|
||||
|
||||
@@ -82,6 +82,15 @@ void GLShader::init(const shader::ShaderCreateInfo &info, bool is_batch_compilat
|
||||
}
|
||||
}
|
||||
|
||||
void GLShader::init()
|
||||
{
|
||||
main_program_ = &program_cache_.lookup_or_add_default(constants->values);
|
||||
if (!main_program_->program_id) {
|
||||
main_program_->program_id = glCreateProgram();
|
||||
debug::object_label(GL_PROGRAM, main_program_->program_id, name);
|
||||
}
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
@@ -145,6 +145,7 @@ class GLShader : public Shader {
|
||||
~GLShader();
|
||||
|
||||
void init(const shader::ShaderCreateInfo &info, bool is_batch_compilation) override;
|
||||
void init() override;
|
||||
|
||||
/** Return true on success. */
|
||||
void vertex_shader_from_glsl(MutableSpan<StringRefNull> sources) override;
|
||||
|
||||
@@ -58,6 +58,7 @@ class VKShader : public Shader {
|
||||
virtual ~VKShader();
|
||||
|
||||
void init(const shader::ShaderCreateInfo &info, bool is_batch_compilation) override;
|
||||
void init() override {}
|
||||
|
||||
void vertex_shader_from_glsl(MutableSpan<StringRefNull> sources) override;
|
||||
void geometry_shader_from_glsl(MutableSpan<StringRefNull> sources) override;
|
||||
|
||||
Reference in New Issue
Block a user