Workaround: Allow patching CreateInfos at runtime
Temporary workaround for Overlay Next. Pull Request: https://projects.blender.org/blender/blender/pulls/128452
This commit is contained in:
@@ -16,13 +16,10 @@ ShaderModule::ShaderPtr ShaderModule::shader(
|
||||
const char *create_info_name,
|
||||
const FunctionRef<void(gpu::shader::ShaderCreateInfo &info)> patch)
|
||||
{
|
||||
const gpu::shader::ShaderCreateInfo *info_ptr =
|
||||
reinterpret_cast<const gpu::shader::ShaderCreateInfo *>(
|
||||
GPU_shader_create_info_get(create_info_name));
|
||||
BLI_assert(info_ptr != nullptr);
|
||||
|
||||
/* Perform a copy for patching. */
|
||||
gpu::shader::ShaderCreateInfo info = *info_ptr;
|
||||
gpu::shader::ShaderCreateInfo info(create_info_name);
|
||||
GPU_shader_create_info_get_unfinalized_copy(create_info_name,
|
||||
reinterpret_cast<GPUShaderCreateInfo &>(info));
|
||||
|
||||
patch(info);
|
||||
|
||||
@@ -45,8 +42,11 @@ ShaderModule::ShaderPtr ShaderModule::selectable_shader(const char *create_info_
|
||||
// this->shader_ = GPU_shader_create_from_info_name(create_info_name.c_str());
|
||||
|
||||
/* WORKAROUND: ... but for now, we have to patch the create info used by the old engine. */
|
||||
gpu::shader::ShaderCreateInfo info = *reinterpret_cast<const gpu::shader::ShaderCreateInfo *>(
|
||||
GPU_shader_create_info_get(create_info_name));
|
||||
|
||||
/* Perform a copy for patching. */
|
||||
gpu::shader::ShaderCreateInfo info(create_info_name);
|
||||
GPU_shader_create_info_get_unfinalized_copy(create_info_name,
|
||||
reinterpret_cast<GPUShaderCreateInfo &>(info));
|
||||
|
||||
info.define("OVERLAY_NEXT");
|
||||
|
||||
@@ -74,8 +74,10 @@ ShaderModule::ShaderPtr ShaderModule::selectable_shader(
|
||||
const char *create_info_name,
|
||||
const FunctionRef<void(gpu::shader::ShaderCreateInfo &info)> patch)
|
||||
{
|
||||
gpu::shader::ShaderCreateInfo info = *reinterpret_cast<const gpu::shader::ShaderCreateInfo *>(
|
||||
GPU_shader_create_info_get(create_info_name));
|
||||
/* Perform a copy for patching. */
|
||||
gpu::shader::ShaderCreateInfo info(create_info_name);
|
||||
GPU_shader_create_info_get_unfinalized_copy(create_info_name,
|
||||
reinterpret_cast<GPUShaderCreateInfo &>(info));
|
||||
|
||||
patch(info);
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ GPUShader *GPU_shader_create_from_info_name(const char *info_name);
|
||||
*/
|
||||
const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name);
|
||||
|
||||
void GPU_shader_create_info_get_unfinalized_copy(const char *info_name,
|
||||
GPUShaderCreateInfo &r_info);
|
||||
|
||||
/**
|
||||
* Error checking for user created shaders.
|
||||
* \return true is create info is valid.
|
||||
|
||||
@@ -261,6 +261,12 @@ const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name)
|
||||
return gpu_shader_create_info_get(info_name);
|
||||
}
|
||||
|
||||
void GPU_shader_create_info_get_unfinalized_copy(const char *info_name,
|
||||
GPUShaderCreateInfo &r_info)
|
||||
{
|
||||
gpu_shader_create_info_get_unfinalized_copy(info_name, r_info);
|
||||
}
|
||||
|
||||
bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128])
|
||||
{
|
||||
using namespace blender::gpu::shader;
|
||||
|
||||
@@ -32,9 +32,11 @@
|
||||
namespace blender::gpu::shader {
|
||||
|
||||
using CreateInfoDictionnary = Map<StringRef, ShaderCreateInfo *>;
|
||||
using CreateInfoValueDictionnary = Map<StringRef, ShaderCreateInfo>;
|
||||
using InterfaceDictionnary = Map<StringRef, StageInterfaceInfo *>;
|
||||
|
||||
static CreateInfoDictionnary *g_create_infos = nullptr;
|
||||
static CreateInfoValueDictionnary *g_create_infos_unfinalized = nullptr;
|
||||
static InterfaceDictionnary *g_interfaces = nullptr;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
@@ -450,6 +452,7 @@ using namespace blender::gpu::shader;
|
||||
void gpu_shader_create_info_init()
|
||||
{
|
||||
g_create_infos = new CreateInfoDictionnary();
|
||||
g_create_infos_unfinalized = new CreateInfoValueDictionnary();
|
||||
g_interfaces = new InterfaceDictionnary();
|
||||
|
||||
#define GPU_SHADER_NAMED_INTERFACE_INFO(_interface, _inst_name) \
|
||||
@@ -584,7 +587,8 @@ void gpu_shader_create_info_init()
|
||||
#endif
|
||||
}
|
||||
|
||||
for (ShaderCreateInfo *info : g_create_infos->values()) {
|
||||
for (auto [key, info] : g_create_infos->items()) {
|
||||
g_create_infos_unfinalized->add_new(key, *info);
|
||||
info->finalize(true);
|
||||
}
|
||||
|
||||
@@ -602,6 +606,8 @@ void gpu_shader_create_info_exit()
|
||||
}
|
||||
delete g_create_infos;
|
||||
|
||||
delete g_create_infos_unfinalized;
|
||||
|
||||
for (auto *value : g_interfaces->values()) {
|
||||
delete value;
|
||||
}
|
||||
@@ -704,3 +710,16 @@ const GPUShaderCreateInfo *gpu_shader_create_info_get(const char *info_name)
|
||||
ShaderCreateInfo *info = g_create_infos->lookup(info_name);
|
||||
return reinterpret_cast<const GPUShaderCreateInfo *>(info);
|
||||
}
|
||||
|
||||
void gpu_shader_create_info_get_unfinalized_copy(const char *info_name,
|
||||
GPUShaderCreateInfo &r_info)
|
||||
{
|
||||
if (g_create_infos_unfinalized->contains(info_name) == false) {
|
||||
std::string msg = std::string("Error: Cannot find shader create info named \"") + info_name +
|
||||
"\"\n";
|
||||
BLI_assert_msg(0, msg.c_str());
|
||||
}
|
||||
else {
|
||||
reinterpret_cast<ShaderCreateInfo &>(r_info) = g_create_infos_unfinalized->lookup(info_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,3 +22,6 @@ bool gpu_shader_create_info_compile(const char *name_starts_with_filter);
|
||||
|
||||
/** Runtime create infos are not registered in the dictionary and cannot be searched. */
|
||||
const GPUShaderCreateInfo *gpu_shader_create_info_get(const char *info_name);
|
||||
|
||||
void gpu_shader_create_info_get_unfinalized_copy(const char *info_name,
|
||||
GPUShaderCreateInfo &r_info);
|
||||
|
||||
Reference in New Issue
Block a user