78 GLuint program_id = 0;
80 GLuint vert_shader = 0;
81 GLuint geom_shader = 0;
82 GLuint frag_shader = 0;
83 GLuint compute_shader = 0;
85 std::mutex compilation_mutex;
97 std::mutex program_cache_mutex_;
100 GLProgram *main_program_ =
nullptr;
104 bool async_compilation_ =
false;
111 GLSources vertex_sources_;
112 GLSources geometry_sources_;
113 GLSources fragment_sources_;
114 GLSources compute_sources_;
124 GLShader::GLProgram &program_get(
const shader::SpecializationConstants *constants_state);
127 bool compilation_failed_ =
false;
129 std::string debug_source;
135 void init(
const shader::ShaderCreateInfo &info,
bool is_batch_compilation)
override;
142 bool finalize(
const shader::ShaderCreateInfo *info =
nullptr)
override;
143 bool post_finalize(
const shader::ShaderCreateInfo *info =
nullptr);
157 void uniform_float(
int location,
int comp_len,
int array_size,
const float *
data)
override;
158 void uniform_int(
int location,
int comp_len,
int array_size,
const int *
data)
override;
162 if (!vertex_sources_.is_empty()) {
165 if (!compute_sources_.is_empty()) {
168 return main_program_->compute_shader != 0;
176 bool has_specialization_constants()
const
178 return constants->types.is_empty() ==
false;
182 GLuint create_shader_stage(GLenum gl_stage,
184 GLSources &gl_sources,
185 const shader::SpecializationConstants &constants_state);
191 std::string workaround_geometry_shader_source_create(
const shader::ShaderCreateInfo &info);
193 bool do_geometry_shader_injection(
const shader::ShaderCreateInfo *info)
const;
195 MEM_CXX_CLASS_ALLOC_FUNCS(
"GLShader");
207#if BLI_SUBPROCESS_SUPPORT
209class GLCompilerWorker {
210 friend class GLSubprocessShaderCompiler;
213 BlenderSubprocess subprocess_;
214 std::unique_ptr<SharedMemory> shared_mem_;
215 std::unique_ptr<SharedSemaphore> start_semaphore_;
216 std::unique_ptr<SharedSemaphore> end_semaphore_;
217 std::unique_ptr<SharedSemaphore> close_semaphore_;
220 COMPILATION_REQUESTED,
224 COMPILATION_FINISHED,
228 std::atomic<State> state_ = AVAILABLE;
229 double compilation_start = 0;
234 void compile(
const GLSourcesBaked &sources);
235 bool block_until_ready();
236 bool load_program_binary(GLint program);
245 Vector<GLCompilerWorker *> workers_;
246 std::mutex workers_mutex_;
248 GLCompilerWorker *get_compiler_worker();
250 GLShader::GLProgram *specialization_program_get(ShaderSpecialization &specialization);
253 GLSubprocessShaderCompiler()
256 virtual ~GLSubprocessShaderCompiler()
override;
270 const char *
parse_line(
const char *source_combined,
271 const char *log_line,
int GPU_max_parallel_compilations()
Read Guarded memory(de)allocation.
BMesh const char void * data
NonCopyable(const NonCopyable &other)=delete
const char * parse_line(const char *source_combined, const char *log_line, GPULogItem &log_item) override
const char * skip_severity_prefix(const char *log_line, GPULogItem &log_item)
const char * skip_severity_keyword(const char *log_line, GPULogItem &log_item)
MEM_CXX_CLASS_ALLOC_FUNCS("GLLogParser")
virtual void specialize_shader(ShaderSpecialization &specialization) override
std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const override
std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const override
void fragment_shader_from_glsl(MutableSpan< StringRefNull > sources) override
std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const override
void geometry_shader_from_glsl(MutableSpan< StringRefNull > sources) override
void compute_shader_from_glsl(MutableSpan< StringRefNull > sources) override
void uniform_float(int location, int comp_len, int array_size, const float *data) override
bool post_finalize(const shader::ShaderCreateInfo *info=nullptr)
GLShader(const char *name)
GLSourcesBaked get_sources()
std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const override
std::string constants_declare(const shader::SpecializationConstants &constants_state) const
std::string resources_declare(const shader::ShaderCreateInfo &info) const override
friend class GLShaderCompiler
friend class GLSubprocessShaderCompiler
void uniform_int(int location, int comp_len, int array_size, const int *data) override
std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const override
bool finalize(const shader::ShaderCreateInfo *info=nullptr) override
void warm_cache(int) override
void bind(const shader::SpecializationConstants *constants_state) override
void vertex_shader_from_glsl(MutableSpan< StringRefNull > sources) override
GLSources & operator=(Span< StringRefNull > other)
std::string to_string() const
Vector< StringRefNull > sources_get() const
virtual void specialize_shader(ShaderSpecialization &)
ShaderCompiler(uint32_t threads_count=1, GPUWorker::ContextType context_type=GPUWorker::ContextType::PerThread, bool support_specializations=false)
virtual Shader * compile_shader(const shader::ShaderCreateInfo &info)
std::unique_ptr< const shader::SpecializationConstants > constants
std::optional< StringRefNull > source_ref
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...