23 #undef GPU_SHADER_INTERFACE_INFO
24 #undef GPU_SHADER_CREATE_INFO
79 std::cout <<
name_ <<
": Validation failed while merging " << info.
name_ <<
" : ";
80 std::cout <<
error << std::endl;
86 assert_no_overlap(
false,
"additional info already merged via another info");
114 int images = 0, samplers = 0, ubos = 0, ssbos = 0;
116 auto set_resource_slot = [&](
Resource &res) {
117 switch (res.bind_type) {
118 case Resource::BindType::UNIFORM_BUFFER:
121 case Resource::BindType::STORAGE_BUFFER:
124 case Resource::BindType::SAMPLER:
125 res.slot = samplers++;
127 case Resource::BindType::IMAGE:
134 set_resource_slot(res);
137 set_resource_slot(res);
149 error +=
"Missing vertex shader in " + this->
name_ +
".\n";
152 error +=
"Missing fragment shader in " + this->
name_ +
".\n";
157 error +=
"Compute shader has vertex_source_ shader attached in " + this->
name_ +
".\n";
160 error +=
"Compute shader has geometry_source_ shader attached in " + this->
name_ +
".\n";
163 error +=
"Compute shader has fragment_source_ shader attached in " + this->
name_ +
".\n";
174 Set<int> images, samplers, ubos, ssbos;
176 auto register_resource = [&](
const Resource &res) ->
bool {
177 switch (res.bind_type) {
178 case Resource::BindType::UNIFORM_BUFFER:
179 return images.
add(res.slot);
180 case Resource::BindType::STORAGE_BUFFER:
181 return samplers.
add(res.slot);
182 case Resource::BindType::SAMPLER:
183 return ubos.
add(res.slot);
184 case Resource::BindType::IMAGE:
185 return ssbos.
add(res.slot);
191 auto print_error_msg = [&](
const Resource &res) {
192 std::cout <<
name_ <<
": Validation failed : Overlapping ";
194 switch (res.bind_type) {
195 case Resource::BindType::UNIFORM_BUFFER:
196 std::cout <<
"Uniform Buffer " << res.uniformbuf.name;
198 case Resource::BindType::STORAGE_BUFFER:
199 std::cout <<
"Storage Buffer " << res.storagebuf.name;
201 case Resource::BindType::SAMPLER:
202 std::cout <<
"Sampler " << res.sampler.name;
204 case Resource::BindType::IMAGE:
205 std::cout <<
"Image " << res.image.name;
208 std::cout <<
"Unknown Type";
211 std::cout <<
" (" << res.slot <<
") while merging " << other_info.
name_ << std::endl;
215 if (register_resource(res) ==
false) {
216 print_error_msg(res);
221 if (register_resource(res) ==
false) {
222 print_error_msg(res);
232 if (attr.index >= 16 || attr.index < 0) {
233 std::cout <<
name_ <<
": \"" << attr.name
234 <<
"\" : Type::MAT3 unsupported as vertex attribute." << std::endl;
237 if (attr.index >= 16 || attr.index < 0) {
238 std::cout <<
name_ <<
": Invalid index for attribute \"" << attr.name <<
"\"" << std::endl;
243 for (
int i = 0; i < 4; i++) {
244 attr_new |= 1 << (attr.index + i);
248 attr_new |= 1 << attr.index;
251 if ((attr_bits & attr_new) != 0) {
252 std::cout <<
name_ <<
": Attribute \"" << attr.name
253 <<
"\" overlap one or more index from another attribute."
254 " Note that mat4 takes up 4 indices.";
256 std::cout <<
" While merging " << other_info->
name_ << std::endl;
258 std::cout << std::endl;
261 attr_bits |= attr_new;
274 #define GPU_SHADER_INTERFACE_INFO(_interface, _inst_name) \
275 auto *ptr_##_interface = new StageInterfaceInfo(#_interface, _inst_name); \
276 auto &_interface = *ptr_##_interface; \
277 g_interfaces->add_new(#_interface, ptr_##_interface); \
280 #define GPU_SHADER_CREATE_INFO(_info) \
281 auto *ptr_##_info = new ShaderCreateInfo(#_info); \
282 auto &_info = *ptr_##_info; \
283 g_create_infos->add_new(#_info, ptr_##_info); \
287 #include "gpu_shader_create_info_list.hh"
293 # include "gpu_shader_baked.hh"
304 if (info->do_static_compilation_) {
337 if (info->do_static_compilation_) {
347 if (shader ==
nullptr) {
348 printf(
"Compilation %s Failed\n", info->name_.c_str());
359 all_resources.
extend(info->pass_resources_);
360 all_resources.extend(info->batch_resources_);
366 switch (res.bind_type) {
367 case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
368 input = interface->ubo_get(res.slot);
369 name = res.uniformbuf.name;
371 case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
372 input = interface->ssbo_get(res.slot);
373 name = res.storagebuf.name;
375 case ShaderCreateInfo::Resource::BindType::SAMPLER:
376 input = interface->texture_get(res.slot);
377 name = res.sampler.name;
379 case ShaderCreateInfo::Resource::BindType::IMAGE:
380 input = interface->texture_get(res.slot);
381 name = res.image.name;
385 if (
input ==
nullptr) {
386 std::cout <<
"Error: " << info->name_;
387 std::cout <<
": Resource « " << name <<
" » not found in the shader interface\n";
389 else if (
input->location == -1) {
390 std::cout <<
"Warning: " << info->name_;
391 std::cout <<
": Resource « " << name <<
" » is optimized out\n";
399 printf(
"Shader Test compilation result: %d / %d passed", success, total);
401 printf(
" (skipped %d for compatibility reasons)", skipped);
404 return success == total;
411 printf(
"Error: Cannot find shader create info named \"%s\"\n", info_name);
bool GPU_shader_image_load_store_support(void)
bool GPU_compute_shader_support(void)
bool GPU_crappy_amd_driver(void)
bool GPU_shader_storage_buffer_objects_support(void)
struct GPUShader GPUShader
struct GPUShaderCreateInfo GPUShaderCreateInfo
void GPU_shader_free(GPUShader *shader)
GPUShader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
ValueIterator values() const
const Value & lookup(const Key &key) const
bool contains(const Key &key) const
constexpr bool is_empty() const
void extend(Span< T > array)
void gpu_shader_create_info_exit()
const GPUShaderCreateInfo * gpu_shader_create_info_get(const char *info_name)
void gpu_shader_create_info_init()
bool gpu_shader_create_info_compile_all()
ccl_global KernelShaderEvalInput * input
static void error(const char *str)
Map< StringRef, StageInterfaceInfo * > InterfaceDictionnary
BuiltinBits gpu_shader_dependency_get_builtins(const StringRefNull shader_source_name)
static InterfaceDictionnary * g_interfaces
Map< StringRef, ShaderCreateInfo * > CreateInfoDictionnary
static CreateInfoDictionnary * g_create_infos
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
StringRefNull vertex_source_
Vector< StageInterfaceInfo * > vertex_out_interfaces_
StringRefNull compute_source_
Vector< std::array< StringRefNull, 2 > > defines_
void validate_vertex_attributes(const ShaderCreateInfo *other_info=nullptr)
std::string check_error() const
Vector< VertIn > vertex_inputs_
bool early_fragment_test_
bool auto_resource_location_
Vector< Resource > batch_resources_
size_t interface_names_size_
Vector< StringRefNull > additional_infos_
StringRefNull geometry_source_
Vector< StageInterfaceInfo * > geometry_out_interfaces_
Vector< Resource > pass_resources_
GeometryStageLayout geometry_layout_
StringRefNull fragment_source_
ComputeStageLayout compute_layout_
void validate_merge(const ShaderCreateInfo &other_info)
Vector< StringRefNull > typedef_sources_
Vector< PushConst > push_constants_
Vector< FragOut > fragment_outputs_