Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_shader_create_info.cc
| Show All 21 Lines | |||||
| * | * | ||||
| * Descriptor type used to define shader structure, resources and interfaces. | * Descriptor type used to define shader structure, resources and interfaces. | ||||
| */ | */ | ||||
| #include "BLI_map.hh" | #include "BLI_map.hh" | ||||
| #include "BLI_set.hh" | #include "BLI_set.hh" | ||||
| #include "BLI_string_ref.hh" | #include "BLI_string_ref.hh" | ||||
| #include "GPU_capabilities.h" | |||||
| #include "GPU_platform.h" | |||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "gpu_shader_create_info.hh" | #include "gpu_shader_create_info.hh" | ||||
| #include "gpu_shader_create_info_private.hh" | #include "gpu_shader_create_info_private.hh" | ||||
| #undef GPU_SHADER_INTERFACE_INFO | #undef GPU_SHADER_INTERFACE_INFO | ||||
| #undef GPU_SHADER_CREATE_INFO | #undef GPU_SHADER_CREATE_INFO | ||||
| Show All 15 Lines | void ShaderCreateInfo::finalize() | ||||
| for (auto &info_name : additional_infos_) { | for (auto &info_name : additional_infos_) { | ||||
| const ShaderCreateInfo &info = *reinterpret_cast<const ShaderCreateInfo *>( | const ShaderCreateInfo &info = *reinterpret_cast<const ShaderCreateInfo *>( | ||||
| gpu_shader_create_info_get(info_name.c_str())); | gpu_shader_create_info_get(info_name.c_str())); | ||||
| /* Recursive. */ | /* Recursive. */ | ||||
| const_cast<ShaderCreateInfo &>(info).finalize(); | const_cast<ShaderCreateInfo &>(info).finalize(); | ||||
| #if 0 /* Enabled for debugging merging. TODO(fclem) exception handling and error reporting in \ | |||||
| console. */ | |||||
| std::cout << "Merging : " << info_name << " > " << name_ << std::endl; | |||||
| #endif | |||||
| interface_names_size_ += info.interface_names_size_; | interface_names_size_ += info.interface_names_size_; | ||||
| vertex_inputs_.extend(info.vertex_inputs_); | vertex_inputs_.extend(info.vertex_inputs_); | ||||
| fragment_outputs_.extend(info.fragment_outputs_); | fragment_outputs_.extend(info.fragment_outputs_); | ||||
| vertex_out_interfaces_.extend(info.vertex_out_interfaces_); | vertex_out_interfaces_.extend(info.vertex_out_interfaces_); | ||||
| geometry_out_interfaces_.extend(info.geometry_out_interfaces_); | geometry_out_interfaces_.extend(info.geometry_out_interfaces_); | ||||
| push_constants_.extend(info.push_constants_); | push_constants_.extend(info.push_constants_); | ||||
| defines_.extend(info.defines_); | defines_.extend(info.defines_); | ||||
| batch_resources_.extend(info.batch_resources_); | batch_resources_.extend(info.batch_resources_); | ||||
| pass_resources_.extend(info.pass_resources_); | pass_resources_.extend(info.pass_resources_); | ||||
| typedef_sources_.extend(info.typedef_sources_); | typedef_sources_.extend_non_duplicates(info.typedef_sources_); | ||||
| validate(info); | validate(info); | ||||
| if (info.compute_layout_.local_size_x != -1) { | if (info.compute_layout_.local_size_x != -1) { | ||||
| compute_layout_.local_size_x = info.compute_layout_.local_size_x; | compute_layout_.local_size_x = info.compute_layout_.local_size_x; | ||||
| compute_layout_.local_size_y = info.compute_layout_.local_size_y; | compute_layout_.local_size_y = info.compute_layout_.local_size_y; | ||||
| compute_layout_.local_size_z = info.compute_layout_.local_size_z; | compute_layout_.local_size_z = info.compute_layout_.local_size_z; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
| /* Baked shader data appended to create infos. */ | /* Baked shader data appended to create infos. */ | ||||
| /* TODO(jbakker): should call a function with a callback. so we could switch implementations. | /* TODO(jbakker): should call a function with a callback. so we could switch implementations. | ||||
| * We cannot compile bf_gpu twice. */ | * We cannot compile bf_gpu twice. */ | ||||
| #ifdef GPU_RUNTIME | #ifdef GPU_RUNTIME | ||||
| # include "gpu_shader_baked.hh" | # include "gpu_shader_baked.hh" | ||||
| #endif | #endif | ||||
| /* WORKAROUND: Replace draw_mesh info with the legacy one for systems that have problems with UBO | |||||
| * indexing. */ | |||||
| if (GPU_type_matches(GPU_DEVICE_INTEL | GPU_DEVICE_INTEL_UHD, GPU_OS_ANY, GPU_DRIVER_ANY) || | |||||
| GPU_type_matches(GPU_DEVICE_ANY, GPU_OS_MAC, GPU_DRIVER_ANY) || GPU_crappy_amd_driver()) { | |||||
| draw_modelmat = draw_modelmat_legacy; | |||||
| } | |||||
| /* TEST */ | /* TEST */ | ||||
| // gpu_shader_create_info_compile_all(); | // gpu_shader_create_info_compile_all(); | ||||
| } | } | ||||
| void gpu_shader_create_info_exit() | void gpu_shader_create_info_exit() | ||||
| { | { | ||||
| for (auto *value : g_create_infos->values()) { | for (auto *value : g_create_infos->values()) { | ||||
| delete value; | delete value; | ||||
| } | } | ||||
| delete g_create_infos; | delete g_create_infos; | ||||
| for (auto *value : g_interfaces->values()) { | for (auto *value : g_interfaces->values()) { | ||||
| delete value; | delete value; | ||||
| } | } | ||||
| delete g_interfaces; | delete g_interfaces; | ||||
| } | } | ||||
| bool gpu_shader_create_info_compile_all() | bool gpu_shader_create_info_compile_all() | ||||
| { | { | ||||
| int success = 0; | |||||
| int total = 0; | |||||
| for (ShaderCreateInfo *info : g_create_infos->values()) { | for (ShaderCreateInfo *info : g_create_infos->values()) { | ||||
| if (info->do_static_compilation_) { | if (info->do_static_compilation_) { | ||||
| // printf("Compiling %s: ... \n", info->name_.c_str()); | total++; | ||||
| GPUShader *shader = GPU_shader_create_from_info( | GPUShader *shader = GPU_shader_create_from_info( | ||||
| reinterpret_cast<const GPUShaderCreateInfo *>(info)); | reinterpret_cast<const GPUShaderCreateInfo *>(info)); | ||||
| if (shader == nullptr) { | if (shader == nullptr) { | ||||
| printf("Compilation %s Failed\n", info->name_.c_str()); | printf("Compilation %s Failed\n", info->name_.c_str()); | ||||
| return false; | } | ||||
| else { | |||||
| success++; | |||||
| } | } | ||||
| GPU_shader_free(shader); | GPU_shader_free(shader); | ||||
| // printf("Success\n"); | |||||
| } | } | ||||
| } | } | ||||
| return true; | printf("===============================\n"); | ||||
| printf("Shader Test compilation result: \n"); | |||||
| printf("%d Total\n", total); | |||||
| printf("%d Passed\n", success); | |||||
| printf("%d Failed\n", total - success); | |||||
| printf("===============================\n"); | |||||
| return success == total; | |||||
| } | } | ||||
| /* Runtime create infos are not registered in the dictionary and cannot be searched. */ | /* Runtime create infos are not registered in the dictionary and cannot be searched. */ | ||||
| const GPUShaderCreateInfo *gpu_shader_create_info_get(const char *info_name) | const GPUShaderCreateInfo *gpu_shader_create_info_get(const char *info_name) | ||||
| { | { | ||||
| if (g_create_infos->contains(info_name) == false) { | |||||
| printf("Error: Cannot find shader create info named \"%s\"\n", info_name); | |||||
| } | |||||
| ShaderCreateInfo *info = g_create_infos->lookup(info_name); | ShaderCreateInfo *info = g_create_infos->lookup(info_name); | ||||
| return reinterpret_cast<const GPUShaderCreateInfo *>(info); | return reinterpret_cast<const GPUShaderCreateInfo *>(info); | ||||
| } | } | ||||