GPU: Shader: Remove legacy creation API
This API is no longer used for 5.0. Pull Request: https://projects.blender.org/blender/blender/pulls/144819
This commit is contained in:
committed by
Clément Foucault
parent
d803ee4c79
commit
2f2ff44e56
@@ -309,30 +309,6 @@ void GPU_shader_batch_specializations_cancel(SpecializationBatchHandle &handle);
|
||||
* All of this section is deprecated and should be ported to use the API described above.
|
||||
* \{ */
|
||||
|
||||
blender::gpu::Shader *GPU_shader_create(std::optional<blender::StringRefNull> vertcode,
|
||||
std::optional<blender::StringRefNull> fragcode,
|
||||
std::optional<blender::StringRefNull> geomcode,
|
||||
std::optional<blender::StringRefNull> libcode,
|
||||
std::optional<blender::StringRefNull> defines,
|
||||
blender::StringRefNull shname);
|
||||
blender::gpu::Shader *GPU_shader_create_compute(std::optional<blender::StringRefNull> computecode,
|
||||
std::optional<blender::StringRefNull> libcode,
|
||||
std::optional<blender::StringRefNull> defines,
|
||||
blender::StringRefNull shname);
|
||||
blender::gpu::Shader *GPU_shader_create_from_python(std::optional<blender::StringRefNull> vertcode,
|
||||
std::optional<blender::StringRefNull> fragcode,
|
||||
std::optional<blender::StringRefNull> geomcode,
|
||||
std::optional<blender::StringRefNull> libcode,
|
||||
std::optional<blender::StringRefNull> defines,
|
||||
std::optional<blender::StringRefNull> name);
|
||||
blender::gpu::Shader *GPU_shader_create_ex(std::optional<blender::StringRefNull> vertcode,
|
||||
std::optional<blender::StringRefNull> fragcode,
|
||||
std::optional<blender::StringRefNull> geomcode,
|
||||
std::optional<blender::StringRefNull> computecode,
|
||||
std::optional<blender::StringRefNull> libcode,
|
||||
std::optional<blender::StringRefNull> defines,
|
||||
blender::StringRefNull shname);
|
||||
|
||||
/**
|
||||
* Shader cache warming.
|
||||
* For each shader, rendering APIs perform a two-step compilation:
|
||||
@@ -432,9 +408,6 @@ enum GPUUniformBlockBuiltin {
|
||||
GPU_NUM_UNIFORM_BLOCKS, /* Special value, denotes number of builtin uniforms block. */
|
||||
};
|
||||
|
||||
/** DEPRECATED: Use hard-coded buffer location instead. */
|
||||
int GPU_shader_get_builtin_block(blender::gpu::Shader *shader, int builtin);
|
||||
|
||||
/** DEPRECATED: Kept only because of Python GPU API. */
|
||||
int GPU_shader_get_uniform_block(blender::gpu::Shader *shader, const char *name);
|
||||
|
||||
|
||||
@@ -119,95 +119,6 @@ static void standard_defines(Vector<StringRefNull> &sources)
|
||||
}
|
||||
}
|
||||
|
||||
blender::gpu::Shader *GPU_shader_create_ex(const std::optional<StringRefNull> vertcode,
|
||||
const std::optional<StringRefNull> fragcode,
|
||||
const std::optional<StringRefNull> geomcode,
|
||||
const std::optional<StringRefNull> computecode,
|
||||
const std::optional<StringRefNull> libcode,
|
||||
const std::optional<StringRefNull> defines,
|
||||
const StringRefNull shname)
|
||||
{
|
||||
/* At least a vertex shader and a fragment shader are required, or only a compute shader. */
|
||||
BLI_assert((fragcode.has_value() && vertcode.has_value() && !computecode.has_value()) ||
|
||||
(!fragcode.has_value() && !vertcode.has_value() && !geomcode.has_value() &&
|
||||
computecode.has_value()));
|
||||
|
||||
Shader *shader = GPUBackend::get()->shader_alloc(shname.c_str());
|
||||
/* Needs to be called before init as GL uses the default specialization constants state to insert
|
||||
* default shader inside a map. */
|
||||
shader->constants = std::make_unique<const shader::SpecializationConstants>();
|
||||
shader->init();
|
||||
|
||||
if (vertcode) {
|
||||
Vector<StringRefNull> sources;
|
||||
standard_defines(sources);
|
||||
sources.append("#define GPU_VERTEX_SHADER\n");
|
||||
sources.append("#define IN_OUT out\n");
|
||||
if (geomcode) {
|
||||
sources.append("#define USE_GEOMETRY_SHADER\n");
|
||||
}
|
||||
if (defines) {
|
||||
sources.append(*defines);
|
||||
}
|
||||
sources.append(*vertcode);
|
||||
|
||||
shader->vertex_shader_from_glsl(sources);
|
||||
}
|
||||
|
||||
if (fragcode) {
|
||||
Vector<StringRefNull> sources;
|
||||
standard_defines(sources);
|
||||
sources.append("#define GPU_FRAGMENT_SHADER\n");
|
||||
sources.append("#define IN_OUT in\n");
|
||||
if (geomcode) {
|
||||
sources.append("#define USE_GEOMETRY_SHADER\n");
|
||||
}
|
||||
if (defines) {
|
||||
sources.append(*defines);
|
||||
}
|
||||
if (libcode) {
|
||||
sources.append(*libcode);
|
||||
}
|
||||
sources.append(*fragcode);
|
||||
|
||||
shader->fragment_shader_from_glsl(sources);
|
||||
}
|
||||
|
||||
if (geomcode) {
|
||||
Vector<StringRefNull> sources;
|
||||
standard_defines(sources);
|
||||
sources.append("#define GPU_GEOMETRY_SHADER\n");
|
||||
if (defines) {
|
||||
sources.append(*defines);
|
||||
}
|
||||
sources.append(*geomcode);
|
||||
|
||||
shader->geometry_shader_from_glsl(sources);
|
||||
}
|
||||
|
||||
if (computecode) {
|
||||
Vector<StringRefNull> sources;
|
||||
standard_defines(sources);
|
||||
sources.append("#define GPU_COMPUTE_SHADER\n");
|
||||
if (defines) {
|
||||
sources.append(*defines);
|
||||
}
|
||||
if (libcode) {
|
||||
sources.append(*libcode);
|
||||
}
|
||||
sources.append(*computecode);
|
||||
|
||||
shader->compute_shader_from_glsl(sources);
|
||||
}
|
||||
|
||||
if (!shader->finalize()) {
|
||||
delete shader;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
void GPU_shader_free(blender::gpu::Shader *shader)
|
||||
{
|
||||
delete shader;
|
||||
@@ -219,26 +130,6 @@ void GPU_shader_free(blender::gpu::Shader *shader)
|
||||
/** \name Creation utils
|
||||
* \{ */
|
||||
|
||||
blender::gpu::Shader *GPU_shader_create(const std::optional<StringRefNull> vertcode,
|
||||
const std::optional<StringRefNull> fragcode,
|
||||
const std::optional<StringRefNull> geomcode,
|
||||
const std::optional<StringRefNull> libcode,
|
||||
const std::optional<StringRefNull> defines,
|
||||
const StringRefNull shname)
|
||||
{
|
||||
return GPU_shader_create_ex(
|
||||
vertcode, fragcode, geomcode, std::nullopt, libcode, defines, shname);
|
||||
}
|
||||
|
||||
blender::gpu::Shader *GPU_shader_create_compute(const std::optional<StringRefNull> computecode,
|
||||
const std::optional<StringRefNull> libcode,
|
||||
const std::optional<StringRefNull> defines,
|
||||
const StringRefNull shname)
|
||||
{
|
||||
return GPU_shader_create_ex(
|
||||
std::nullopt, std::nullopt, std::nullopt, computecode, libcode, defines, shname);
|
||||
}
|
||||
|
||||
const GPUShaderCreateInfo *GPU_shader_create_info_get(const char *info_name)
|
||||
{
|
||||
return gpu_shader_create_info_get(info_name);
|
||||
@@ -311,63 +202,6 @@ blender::gpu::Shader *GPU_shader_create_from_info_python(const GPUShaderCreateIn
|
||||
return result;
|
||||
}
|
||||
|
||||
blender::gpu::Shader *GPU_shader_create_from_python(std::optional<StringRefNull> vertcode,
|
||||
std::optional<StringRefNull> fragcode,
|
||||
std::optional<StringRefNull> geomcode,
|
||||
std::optional<StringRefNull> libcode,
|
||||
std::optional<StringRefNull> defines,
|
||||
const std::optional<StringRefNull> name)
|
||||
{
|
||||
std::string defines_cat = "#define GPU_RAW_PYTHON_SHADER\n";
|
||||
if (defines) {
|
||||
defines_cat += defines.value();
|
||||
defines = defines_cat;
|
||||
}
|
||||
else {
|
||||
defines = defines_cat;
|
||||
}
|
||||
|
||||
std::string libcodecat;
|
||||
|
||||
if (!libcode) {
|
||||
libcode = datatoc_gpu_shader_colorspace_lib_glsl;
|
||||
}
|
||||
else {
|
||||
libcodecat = *libcode + datatoc_gpu_shader_colorspace_lib_glsl;
|
||||
libcode = libcodecat;
|
||||
}
|
||||
|
||||
std::string vertex_source_processed;
|
||||
std::string fragment_source_processed;
|
||||
std::string geometry_source_processed;
|
||||
std::string library_source_processed;
|
||||
|
||||
if (vertcode.has_value()) {
|
||||
vertex_source_processed = GPU_shader_preprocess_source(*vertcode);
|
||||
vertcode = vertex_source_processed;
|
||||
}
|
||||
if (fragcode.has_value()) {
|
||||
fragment_source_processed = GPU_shader_preprocess_source(*fragcode);
|
||||
fragcode = fragment_source_processed;
|
||||
}
|
||||
if (geomcode.has_value()) {
|
||||
geometry_source_processed = GPU_shader_preprocess_source(*geomcode);
|
||||
geomcode = geometry_source_processed;
|
||||
}
|
||||
if (libcode.has_value()) {
|
||||
library_source_processed = GPU_shader_preprocess_source(*libcode);
|
||||
libcode = library_source_processed;
|
||||
}
|
||||
|
||||
/* Use pyGPUShader as default name for shader. */
|
||||
blender::StringRefNull shname = name.value_or("pyGPUShader");
|
||||
|
||||
blender::gpu::Shader *sh = GPU_shader_create_ex(
|
||||
vertcode, fragcode, geomcode, std::nullopt, libcode, defines, shname);
|
||||
|
||||
return sh;
|
||||
}
|
||||
|
||||
BatchHandle GPU_shader_batch_create_from_infos(Span<const GPUShaderCreateInfo *> infos,
|
||||
CompilationPriority priority)
|
||||
{
|
||||
@@ -575,12 +409,6 @@ int GPU_shader_get_builtin_uniform(blender::gpu::Shader *shader, int builtin)
|
||||
return interface->uniform_builtin((GPUUniformBuiltin)builtin);
|
||||
}
|
||||
|
||||
int GPU_shader_get_builtin_block(blender::gpu::Shader *shader, int builtin)
|
||||
{
|
||||
const ShaderInterface *interface = shader->interface;
|
||||
return interface->ubo_builtin((GPUUniformBlockBuiltin)builtin);
|
||||
}
|
||||
|
||||
int GPU_shader_get_ssbo_binding(blender::gpu::Shader *shader, const char *name)
|
||||
{
|
||||
const ShaderInterface *interface = shader->interface;
|
||||
|
||||
@@ -71,8 +71,6 @@ class Shader {
|
||||
|
||||
/* TODO: Remove `is_batch_compilation`. */
|
||||
virtual void init(const shader::ShaderCreateInfo &info, bool is_batch_compilation) = 0;
|
||||
/* Variant for legacy python shaders. To be removed, not supported in Vulkan or Metal. */
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual void vertex_shader_from_glsl(MutableSpan<StringRefNull> sources) = 0;
|
||||
virtual void geometry_shader_from_glsl(MutableSpan<StringRefNull> sources) = 0;
|
||||
|
||||
@@ -234,7 +234,6 @@ class MTLShader : public Shader {
|
||||
~MTLShader();
|
||||
|
||||
void init(const shader::ShaderCreateInfo & /*info*/, bool is_batch_compilation) override;
|
||||
void init() override {}
|
||||
|
||||
/* Assign GLSL source. */
|
||||
void vertex_shader_from_glsl(MutableSpan<StringRefNull> sources) override;
|
||||
|
||||
@@ -87,18 +87,6 @@ void GLShader::init(const shader::ShaderCreateInfo &info, bool is_batch_compilat
|
||||
}
|
||||
}
|
||||
|
||||
void GLShader::init()
|
||||
{
|
||||
main_program_ = program_cache_
|
||||
.lookup_or_add_cb(constants->values,
|
||||
[]() { return std::make_unique<GLProgram>(); })
|
||||
.get();
|
||||
if (!main_program_->program_id) {
|
||||
main_program_->program_id = glCreateProgram();
|
||||
debug::object_label(GL_PROGRAM, main_program_->program_id, name);
|
||||
}
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
@@ -133,7 +133,6 @@ class GLShader : public Shader {
|
||||
~GLShader();
|
||||
|
||||
void init(const shader::ShaderCreateInfo &info, bool is_batch_compilation) override;
|
||||
void init() override;
|
||||
|
||||
/** Return true on success. */
|
||||
void vertex_shader_from_glsl(MutableSpan<StringRefNull> sources) override;
|
||||
|
||||
@@ -58,7 +58,6 @@ class VKShader : public Shader {
|
||||
virtual ~VKShader();
|
||||
|
||||
void init(const shader::ShaderCreateInfo &info, bool is_batch_compilation) override;
|
||||
void init() override {}
|
||||
|
||||
void vertex_shader_from_glsl(MutableSpan<StringRefNull> sources) override;
|
||||
void geometry_shader_from_glsl(MutableSpan<StringRefNull> sources) override;
|
||||
|
||||
Reference in New Issue
Block a user