25 #define SHADER_SOURCE(datatoc, filename, filepath) extern char datatoc[];
26 #include "glsl_draw_source_list.h"
27 #include "glsl_gpu_source_list.h"
29 # include "glsl_ocio_source_list.h"
72 if (
source.
find(
"gl_LocalInvocationIndex", 0)) {
118 template<
bool check_whole_word = true,
bool reversed = false,
typename T>
122 if constexpr (reversed) {
129 if constexpr (check_whole_word) {
132 if (!(
ELEM(previous_char,
'\n',
'\t',
' ',
':',
'(',
','))) {
133 offset += (reversed) ? -1 : 1;
139 offset += (reversed) ? -1 : 1;
147 #define find_keyword find_str<true, false>
148 #define rfind_keyword find_str<true, true>
149 #define find_token find_str<false, false>
150 #define rfind_token find_str<false, true>
162 std::cout <<
fullpath <<
":" << line_number <<
":" << char_number;
164 std::cout <<
" error: " << message <<
"\n";
165 std::cout << std::setw(5) << line_number <<
" | "
166 <<
input.substr(line_start, line_end - line_start) <<
"\n";
168 for (
int64_t i = 0; i < char_number - 1; i++) {
174 #define CHECK(test_value, str, ofs, msg) \
175 if ((test_value) == -1) { \
176 print_error(str, ofs, msg); \
265 if (cursor >= 8 &&
input.substr(cursor - 8, 8) ==
"typedef ") {
269 output +=
input.substr(last_pos, cursor - last_pos);
275 CHECK(values_start,
input, cursor,
"Malformed enum class. Expected \'{\' after typename.");
277 StringRef enum_name =
input.substr(name_start, values_start - name_start);
280 CHECK(name_end,
input, name_start,
"Expected \':\' after C++ enum name.");
283 CHECK(underlying_type,
input, name_start,
"C++ enums needs uint32_t underlying type.");
285 enum_name =
input.substr(name_start, name_end);
288 output +=
"#define " + enum_name +
" uint\n";
292 CHECK(values_end,
input, cursor,
"Malformed enum class. Expected \'}\' after values.");
297 StringRef enum_values =
input.substr(values_start, values_end - values_start);
301 int64_t not_found = (token == -1) ? 0 : -1;
302 CHECK(not_found,
input, values_start + token,
"Unexpected \'{\' token inside enum values.");
307 if (last_comma > last_equal) {
308 enum_values =
input.substr(values_start, last_comma);
311 output +=
"const uint " + enum_values;
313 int64_t semicolon_found = (
input[values_end + 1] ==
';') ? 0 : -1;
314 CHECK(semicolon_found,
input, values_end + 1,
"Expected \';\' after enum type declaration.");
317 cursor = last_pos = values_end + 1;
336 const char whitespace_chars[] =
" \r\n\t";
348 if (arg_start == -1) {
357 if (body_start != -1 && next_semicolon != -1 && body_start > next_semicolon) {
359 BLI_assert_msg(
false,
"No prototypes allowed in node GLSL libraries.");
361 int64_t name_start =
input.find_first_not_of(whitespace_chars,
input.find(
' ', cursor));
362 if (name_start == -1) {
365 int64_t name_end =
input.find_last_not_of(whitespace_chars, arg_start);
366 if (name_end == -1) {
370 out_return_type =
"void";
371 out_name =
input.substr(name_start, name_end - name_start);
372 out_args =
input.substr(arg_start + 1, arg_end - (arg_start + 1));
377 int64_t keyword_start =
str.find_first_not_of(whitespace_chars, cursor);
378 if (keyword_start == -1) {
380 return str.substr(0, 0);
382 int64_t keyword_end =
str.find_first_of(whitespace_chars, keyword_start);
383 if (keyword_end == -1) {
385 keyword_end =
str.size();
387 cursor = keyword_end + 1;
388 return str.substr(keyword_start, keyword_end - keyword_start);
396 int64_t arg_start = cursor + 1;
397 if (arg_start >=
str.size()) {
405 const StringRef arg =
str.substr(arg_start, cursor - arg_start);
408 out_qualifier = keyword_parse(arg, keyword_cursor);
409 out_type = keyword_parse(arg, keyword_cursor);
410 out_name = keyword_parse(arg, keyword_cursor);
411 if (out_name.is_empty()) {
414 out_type = out_qualifier;
415 out_qualifier = arg.
substr(0, 0);
421 StringRef func_return_type, func_name, func_args;
422 while (function_parse(
input, cursor, func_return_type, func_name, func_args)) {
423 GPUFunction *func = MEM_new<GPUFunction>(__func__);
425 func->
source =
reinterpret_cast<void *
>(
this);
434 if (other_source !=
this) {
437 "Function redefinition or overload in two different files ...");
439 input, other_source->
source.
find(func_name),
"... previous definition was here");
448 if (func_return_type !=
"void") {
454 StringRef arg_qualifier, arg_type, arg_name;
455 while (arg_parse(func_args, args_cursor, arg_qualifier, arg_type, arg_name)) {
463 if (qualifier ==
"out") {
466 if (qualifier ==
"inout") {
473 if (
type ==
"float") {
476 if (
type ==
"vec2") {
479 if (
type ==
"vec3") {
482 if (
type ==
"vec4") {
485 if (
type ==
"mat3") {
488 if (
type ==
"mat4") {
491 if (
type ==
"sampler1DArray") {
494 if (
type ==
"sampler2DArray") {
497 if (
type ==
"sampler2D") {
500 if (
type ==
"sampler3D") {
503 if (
type ==
"Closure") {
513 std::string
err =
"Unknown parameter type \"" + arg_type +
"\"";
534 if (this->dependencies_init) {
537 this->dependencies_init =
true;
555 dependency_source = dict.
lookup_default(dependency_name,
nullptr);
556 if (dependency_source ==
nullptr) {
579 result.append(dep->source.c_str());
588 out_builtins |= dep->builtins;
613 #define SHADER_SOURCE(datatoc, filename, filepath) \
614 g_sources->add_new(filename, new GPUSource(filepath, filename, datatoc, g_functions));
615 #include "glsl_draw_source_list.h"
616 #include "glsl_gpu_source_list.h"
618 # include "glsl_ocio_source_list.h"
626 BLI_assert_msg(errors == 0,
"Dependency errors detected: Aborting");
645 BLI_assert_msg(
function !=
nullptr,
"Requested function not in the function library");
655 if (shader_source_name.
is_empty()) {
659 std::cout <<
"Error: Could not find \"" << shader_source_name
660 <<
"\" in the list of registered source.\n";
673 if (
src ==
nullptr) {
674 std::cout <<
"Error source not found : " << shader_source_name << std::endl;
683 if (
src ==
nullptr) {
684 std::cout <<
"Error source not found : " << shader_source_name << std::endl;
693 if (source->source.c_str() == source_string.
c_str()) {
694 return source->filename;
#define BLI_assert_msg(a, msg)
bool BLI_gset_add(GSet *gs, void *key)
#define UNUSED_VARS_NDEBUG(...)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
bool add(const Key &key, const Value &value)
Value lookup_default(const Key &key, const Value &default_value) const
ValueIterator values() const
const Value & lookup(const Key &key) const
bool contains(const Key &key) const
void copy(char *dst, int64_t dst_size) 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
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr bool startswith(StringRef prefix) const
constexpr bool endswith(StringRef suffix) const
constexpr int64_t find_first_of(StringRef chars, int64_t pos=0) const
constexpr const char * c_str() const
SyclQueue void void * src
void gpu_shader_dependency_init()
GPUFunction * gpu_material_library_use_function(GSet *used_libraries, const char *name)
void gpu_shader_dependency_exit()
static GPUFunctionDictionnary * g_functions
#define CHECK(test_value, str, ofs, msg)
static GPUSourceDictionnary * g_sources
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_global KernelShaderEvalInput * input
Insertion insert(const float3 &point_prev, const float3 &handle_prev, const float3 &handle_next, const float3 &point_next, float parameter)
StringRefNull gpu_shader_dependency_get_filename_from_source_string(const StringRefNull source_string)
BuiltinBits gpu_shader_dependency_get_builtins(const StringRefNull shader_source_name)
StringRefNull gpu_shader_dependency_get_source(const StringRefNull shader_source_name)
Vector< const char * > gpu_shader_dependency_get_resolved_source(const StringRefNull shader_source_name)
Map< StringRef, struct GPUSource * > GPUSourceDictionnary
Map< StringRef, struct GPUFunction * > GPUFunctionDictionnary
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)
void material_functions_parse(GPUFunctionDictionnary *g_functions)
void build(Vector< const char * > &result) const
shader::BuiltinBits builtins_get() const
static int64_t find_str(const StringRef &input, const T keyword, int64_t offset=0)
std::string processed_source
shader::BuiltinBits builtins
GPUSource(const char *path, const char *file, const char *datatoc, GPUFunctionDictionnary *g_functions)
static bool is_in_comment(const StringRef &input, int64_t offset)
void print_error(const StringRef &input, int64_t offset, const StringRef message)