35#define SHADER_SOURCE(filename_underscore, filename, filepath) \
36 extern char datatoc_##filename_underscore[];
37#include "glsl_compositor_source_list.h"
38#include "glsl_draw_source_list.h"
39#include "glsl_gpu_source_list.h"
40#include "glsl_ocio_source_list.h"
42# include "glsl_osd_source_list.h"
106#if GPU_SHADER_PRINTF_ENABLE
187 if (format_map->
contains(format_hash)) {
201 format = std::regex_replace(
format, std::regex(R
"(\\n)"), "\n");
202 format = std::regex_replace(
format, std::regex(R
"(\\v)"), "\v");
203 format = std::regex_replace(
format, std::regex(R
"(\\t)"), "\t");
204 format = std::regex_replace(
format, std::regex(R
"(\\')"), "\'");
205 format = std::regex_replace(
format, std::regex(R
"(\\")"), "\"");
206 format = std::regex_replace(
format, std::regex(R
"(\\\\)"), "\\");
211 while ((end =
format.find_first_of(
'%', start + 1)) != -1) {
216 switch (
format[end + 1]) {
236 format_map->
add(format_hash, fmt);
244 GPUFunction *func = MEM_new<GPUFunction>(__func__);
246 func->
source =
reinterpret_cast<void *
>(
this);
248 for (
auto arg : arguments) {
263 if (other_source !=
this) {
264 const char *msg =
"Function redefinition or overload in two different files ...";
268 "... previous definition was here");
283 int64_t char_number = offset - line_start + 1;
287 std::cerr <<
fullpath <<
":" << line_number <<
":" << char_number;
289 std::cerr <<
" error: " << message <<
"\n";
290 std::cerr << std::setw(5) << line_number <<
" | "
291 <<
input.substr(line_start, line_end - line_start) <<
"\n";
293 for (
int64_t i = 0;
i < char_number - 1;
i++) {
303 if (this->dependencies_init) {
306 this->dependencies_init =
true;
319 if (dependency_source ==
nullptr) {
320 std::string
error = std::string(
"Dependency not found : ") + dependency_name;
344 result.append(dep->source);
353 out_builtins |= dep->builtins;
360 return (
filename.startswith(
"gpu_shader_material_") ||
361 filename.startswith(
"gpu_shader_common_") ||
362 filename.startswith(
"gpu_shader_compositor_")) &&
369#include "glsl_compositor_metadata_list.hh"
370#include "glsl_draw_metadata_list.hh"
371#include "glsl_gpu_metadata_list.hh"
372#include "glsl_ocio_metadata_list.hh"
373#ifdef WITH_OPENSUBDIV
374# include "glsl_osd_metadata_list.hh"
394#define SHADER_SOURCE(filename_underscore, filename, filepath) \
395 g_sources->add_new(filename, \
396 new GPUSource(filepath, \
398 datatoc_##filename_underscore, \
401 blender::gpu::shader::metadata_##filename_underscore));
403#include "glsl_compositor_source_list.h"
404#include "glsl_draw_source_list.h"
405#include "glsl_gpu_source_list.h"
406#include "glsl_ocio_source_list.h"
407#ifdef WITH_OPENSUBDIV
408# include "glsl_osd_source_list.h"
411#ifdef WITH_OPENSUBDIV
414 "osd_patch_basis.glsl",
416 "osd_patch_basis.glsl",
417 patch_basis_source.
c_str(),
424 for (
auto *value :
g_sources->values()) {
427 BLI_assert_msg(errors == 0,
"Dependency errors detected: Aborting");
430#if GPU_SHADER_PRINTF_ENABLE
434 for (
auto *value :
g_sources->values()) {
436 if (value->filename.startswith(
"gpu_shader_material_")) {
445 if (
GCaps.line_directive_workaround) {
446 for (
auto *value :
g_sources->values()) {
447 value->patched_source = value->source;
448 value->source = value->patched_source.c_str();
449 size_t start_pos = 0;
450 while ((start_pos = value->patched_source.find(
"#line ", start_pos)) != std::string::npos) {
451 value->patched_source[start_pos] =
'/';
452 value->patched_source[start_pos + 1] =
'/';
460 for (
auto *value :
g_sources->values()) {
477 BLI_assert_msg(function !=
nullptr,
"Requested function not in the function library");
504 if (shader_source_name.
is_empty()) {
507 if (
g_sources->contains(shader_source_name) ==
false) {
508 std::cerr <<
"Error: Could not find \"" << shader_source_name
509 <<
"\" in the list of registered source.\n";
522 if (src ==
nullptr) {
523 std::cerr <<
"Error source not found : " << shader_source_name << std::endl;
532 if (src ==
nullptr) {
533 std::cerr <<
"Error source not found : " << shader_source_name << std::endl;
540 for (
auto &source :
g_sources->values()) {
541 if (source->source == source_string) {
542 return source->filename;
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
bool BLI_gset_add(GSet *gs, void *key)
void BLI_kdtree_nd_ insert(KDTree *tree, int index, const float co[KD_DIMS]) ATTR_NONNULL(1
#define UNUSED_VARS_NDEBUG(...)
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
Value lookup_default(const Key &key, const Value &default_value) const
bool contains(const Key &key) const
constexpr int64_t find(char c, int64_t pos=0) const
constexpr const char * begin() const
constexpr const char * end() const
constexpr bool is_empty() const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
constexpr const char * c_str() const
const char * openSubdiv_getGLSLPatchBasisSource()
GPUFunction * gpu_material_library_use_function(GSet *used_libraries, const char *name)
static bool force_printf_injection
void gpu_shader_dependency_init()
void gpu_shader_dependency_exit()
static GPUFunctionDictionnary * g_functions
static GPUPrintFormatMap * g_formats
static GPUSourceDictionnary * g_sources
static void error(const char *str)
const PrintfFormat & gpu_shader_dependency_get_printf_format(uint32_t format_hash)
Vector< StringRefNull > gpu_shader_dependency_get_resolved_source(const StringRefNull shader_source_name)
BuiltinBits gpu_shader_dependency_get_builtins(const StringRefNull shader_source_name)
bool gpu_shader_dependency_has_printf()
bool gpu_shader_dependency_force_gpu_print_injection()
StringRefNull gpu_shader_dependency_get_filename_from_source_string(const StringRef source_string)
Find the name of the file from which the given string was generated.
StringRefNull gpu_shader_dependency_get_source(const StringRefNull shader_source_name)
Map< StringRef, GPUFunction * > GPUFunctionDictionnary
Map< uint32_t, shader::PrintfFormat > GPUPrintFormatMap
Map< StringRef, struct GPUSource * > GPUSourceDictionnary
eGPUType paramtype[MAX_PARAMETER]
char name[MAX_FUNCTION_NAME]
GPUFunctionQual paramqual[MAX_PARAMETER]
Vector< GPUSource * > dependencies
bool is_from_material_library() const
int init_dependencies(const GPUSourceDictionnary &dict, const GPUFunctionDictionnary &g_functions)
eGPUType convert_type(shader::metadata::Type type)
void build(Vector< StringRefNull > &result) const
shader::BuiltinBits builtins_get() const
shader::BuiltinBits convert_builtin_bit(shader::metadata::Builtin builtin)
void add_dependency(StringRef line)
GPUSource(const char *path, const char *file, const char *datatoc, GPUFunctionDictionnary *g_functions, GPUPrintFormatMap *g_formats, std::function< void(GPUSource &, GPUFunctionDictionnary *, GPUPrintFormatMap *)> metadata_fn)
Vector< StringRef > dependencies_names
GPUFunctionQual convert_qualifier(shader::metadata::Qualifier qualifier)
void add_builtin(shader::metadata::Builtin builtin)
std::string patched_source
shader::BuiltinBits builtins
void add_printf_format(uint32_t format_hash, std::string format, GPUPrintFormatMap *format_map)
void print_error(const StringRef &input, int64_t offset, const StringRef message)
void add_function(StringRefNull name, Span< shader::metadata::ArgumentFormat > arguments, GPUFunctionDictionnary *g_functions)