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;
136 void init()
override;
143 bool finalize(
const shader::ShaderCreateInfo *info =
nullptr)
override;
144 bool post_finalize(
const shader::ShaderCreateInfo *info =
nullptr);
158 void uniform_float(
int location,
int comp_len,
int array_size,
const float *
data)
override;
159 void uniform_int(
int location,
int comp_len,
int array_size,
const int *
data)
override;
163 if (!vertex_sources_.is_empty()) {
166 if (!compute_sources_.is_empty()) {
169 return main_program_->compute_shader != 0;
177 bool has_specialization_constants()
const
179 return constants->types.is_empty() ==
false;
183 GLuint create_shader_stage(GLenum gl_stage,
185 GLSources &gl_sources,
186 const shader::SpecializationConstants &constants_state);
192 std::string workaround_geometry_shader_source_create(
const shader::ShaderCreateInfo &info);
194 bool do_geometry_shader_injection(
const shader::ShaderCreateInfo *info)
const;
196 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<eState> 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);
246 std::mutex workers_mutex_;
248 GLCompilerWorker *get_compiler_worker();
250 GLShader::GLProgram *specialization_program_get(ShaderSpecialization &specialization);
253 GLSubprocessShaderCompiler()
255 virtual ~GLSubprocessShaderCompiler()
override;
269 const char *
parse_line(
const char *source_combined,
270 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...