29#define DEBUG_LOG_SHADER_SRC_ON_ERROR 0
36#define SOURCES_INDEX_VERSION 0
37#define SOURCES_INDEX_SPECIALIZATION_CONSTANTS 1
52 std::unique_ptr<const shader::SpecializationConstants>
constants;
91 virtual void uniform_float(
int location,
int comp_len,
int array_size,
const float *
data) = 0;
92 virtual void uniform_int(
int location,
int comp_len,
int array_size,
const int *
data) = 0;
134 return reinterpret_cast<GPUShader *
>(vert);
138 return reinterpret_cast<Shader *
>(vert);
142 return reinterpret_cast<const Shader *
>(vert);
159 std::atomic<int> pending_compilations = 0;
160 std::atomic<bool> is_cancelled =
false;
162 bool is_specialization_batch()
170 return pending_compilations == 0;
185 std::condition_variable compilation_finished_notification_;
187 struct ParallelWork {
188 Batch *
batch =
nullptr;
189 int shader_index = 0;
192 struct CompilationQueue {
193 std::deque<ParallelWork> low_priority;
194 std::deque<ParallelWork> normal_priority;
195 std::deque<ParallelWork> high_priority;
201 low_priority.push_back(work);
204 normal_priority.push_back(work);
207 high_priority.push_back(work);
217 if (!high_priority.empty()) {
218 ParallelWork work = high_priority.front();
219 high_priority.pop_front();
222 if (!normal_priority.empty()) {
223 ParallelWork work = normal_priority.front();
224 normal_priority.pop_front();
227 if (!low_priority.empty()) {
228 ParallelWork work = low_priority.front();
229 low_priority.pop_front();
238 return low_priority.empty() && normal_priority.empty() && high_priority.empty();
241 void remove_batch(Batch *
batch)
243 auto remove = [](std::deque<ParallelWork> &queue, Batch *
batch) {
244 for (ParallelWork &work : queue) {
245 if (work.batch ==
batch) {
247 batch->pending_compilations--;
251 queue.erase(std::remove_if(queue.begin(),
253 [](
const ParallelWork &work) { return !work.batch; }),
257 remove(low_priority,
batch);
258 remove(normal_priority,
batch);
259 remove(high_priority,
batch);
262 CompilationQueue compilation_queue_;
264 std::unique_ptr<GPUWorker> compilation_worker_;
266 bool support_specializations_;
269 void do_work(
void *work_payload);
273 bool is_compiling_impl();
280 compilation_worker_.reset();
286 bool support_specializations =
false);
331 const char *log_line,
337 const char *error_msg,
338 const char *warning_msg,
339 const char *note_msg)
const;
341 const char *
skip_until(
const char *log_line,
char stop_char)
const;
342 bool at_number(
const char *log_line)
const;
344 int parse_number(
const char *log_line,
const char **r_new_position)
const;
#define BLI_assert_unreachable()
int64_t SpecializationBatchHandle
void GPU_shader_free(GPUShader *shader)
BMesh const char void * data
int parse_number(const char *log_line, const char **r_new_position) const
const char * skip_separators(const char *log_line, const StringRef separators) const
bool at_number(const char *log_line) const
bool at_any(const char *log_line, const StringRef chars) const
virtual const char * parse_line(const char *source_combined, const char *log_line, GPULogItem &log_item)=0
const char * skip_until(const char *log_line, char stop_char) const
MEM_CXX_CLASS_ALLOC_FUNCS("GPULogParser")
const char * skip_severity(const char *log_line, GPULogItem &log_item, const char *error_msg, const char *warning_msg, const char *note_msg) const
void batch_cancel(BatchHandle &handle)
BatchHandle batch_compile(Span< const shader::ShaderCreateInfo * > &infos, CompilationPriority priority)
bool specialization_batch_is_ready(SpecializationBatchHandle &handle)
Vector< Shader * > batch_finalize(BatchHandle &handle)
Shader * compile(const shader::ShaderCreateInfo &info, bool is_batch_compilation)
virtual void specialize_shader(ShaderSpecialization &)
bool batch_is_ready(BatchHandle handle)
ShaderCompiler(uint32_t threads_count=1, GPUWorker::ContextType context_type=GPUWorker::ContextType::PerThread, bool support_specializations=false)
void destruct_compilation_worker()
virtual ~ShaderCompiler()
SpecializationBatchHandle precompile_specializations(Span< ShaderSpecialization > specializations, CompilationPriority priority)
virtual Shader * compile_shader(const shader::ShaderCreateInfo &info)
uint16_t fragment_output_bits
virtual std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const =0
virtual void uniform_int(int location, int comp_len, int array_size, const int *data)=0
static void set_srgb_uniform(Context *ctx, GPUShader *shader)
std::string defines_declare(const shader::ShaderCreateInfo &info) const
virtual void compute_shader_from_glsl(MutableSpan< StringRefNull > sources)=0
virtual void init(const shader::ShaderCreateInfo &info, bool is_batch_compilation)=0
virtual void bind(const shader::SpecializationConstants *constants_state)=0
std::unique_ptr< const shader::SpecializationConstants > constants
virtual void vertex_shader_from_glsl(MutableSpan< StringRefNull > sources)=0
virtual std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const =0
Shader * parent_get() const
virtual void fragment_shader_from_glsl(MutableSpan< StringRefNull > sources)=0
virtual bool finalize(const shader::ShaderCreateInfo *info=nullptr)=0
StringRefNull name_get() const
virtual std::string resources_declare(const shader::ShaderCreateInfo &info) const =0
virtual std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const =0
void specialization_constants_init(const shader::ShaderCreateInfo &info)
virtual void geometry_shader_from_glsl(MutableSpan< StringRefNull > sources)=0
virtual void warm_cache(int limit)=0
void parent_set(Shader *parent)
virtual std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const =0
virtual void uniform_float(int location, int comp_len, int array_size, const float *data)=0
void print_log(Span< StringRefNull > sources, const char *log, const char *stage, bool error, GPULogParser *parser)
static void set_framebuffer_srgb_target(int use_srgb_to_linear)
virtual std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const =0
struct @242053044010324116347033273112253060004051364061::@051143074301336237271216303350234260141112266062 batch
GPUShader * immGetShader()
static void error(const char *str)
static Context * unwrap(GPUContext *ctx)
static GPUContext * wrap(Context *ctx)
void printf_begin(Context *ctx)
void printf_end(Context *ctx)
StringRef file_name_and_error_line
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...