2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
2020-02-12 12:48:44 +01:00
|
|
|
*
|
|
|
|
|
* Generate shader code from the intermediate node graph.
|
2011-02-27 20:25:53 +00:00
|
|
|
*/
|
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
#include "BLI_hash_mm2a.hh"
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
|
2024-02-01 10:40:24 -05:00
|
|
|
#include "GPU_material.hh"
|
2025-05-22 17:53:22 +02:00
|
|
|
#include "GPU_vertex_format.hh"
|
|
|
|
|
#include "gpu_node_graph.hh"
|
|
|
|
|
#include "gpu_shader_create_info.hh"
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
namespace blender::gpu::shader {
|
|
|
|
|
|
|
|
|
|
struct GPUCodegenCreateInfo : ShaderCreateInfo {
|
|
|
|
|
struct NameBuffer {
|
|
|
|
|
using NameEntry = std::array<char, 32>;
|
|
|
|
|
|
|
|
|
|
/** Duplicate attribute names to avoid reference the GPUNodeGraph directly. */
|
|
|
|
|
char attr_names[16][GPU_MAX_SAFE_ATTR_NAME + 1];
|
|
|
|
|
char var_names[16][8];
|
|
|
|
|
Vector<std::unique_ptr<NameEntry>, 16> sampler_names;
|
|
|
|
|
|
|
|
|
|
/* Returns the appended name memory location */
|
|
|
|
|
const char *append_sampler_name(const char name[32]);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Optional generated interface. */
|
|
|
|
|
StageInterfaceInfo *interface_generated = nullptr;
|
|
|
|
|
/** Optional name buffer containing names referenced by StringRefNull. */
|
|
|
|
|
NameBuffer name_buffer;
|
|
|
|
|
/** Copy of the GPUMaterial name, to prevent dangling pointers. */
|
|
|
|
|
std::string info_name_;
|
|
|
|
|
|
|
|
|
|
GPUCodegenCreateInfo(const char *name) : ShaderCreateInfo(name), info_name_(name)
|
|
|
|
|
{
|
|
|
|
|
/* Base class is always initialized first, so we need to update the name_ pointer here. */
|
|
|
|
|
name_ = info_name_.c_str();
|
|
|
|
|
};
|
|
|
|
|
~GPUCodegenCreateInfo()
|
|
|
|
|
{
|
|
|
|
|
MEM_delete(interface_generated);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GPUCodegen {
|
|
|
|
|
public:
|
|
|
|
|
GPUMaterial &mat;
|
|
|
|
|
GPUNodeGraph &graph;
|
|
|
|
|
GPUCodegenOutput output = {};
|
|
|
|
|
GPUCodegenCreateInfo *create_info = nullptr;
|
2020-07-25 18:10:43 +02:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
private:
|
|
|
|
|
uint32_t hash_ = 0;
|
|
|
|
|
BLI_HashMurmur2A hm2a_;
|
|
|
|
|
ListBase ubo_inputs_ = {nullptr, nullptr};
|
|
|
|
|
GPUInput *cryptomatte_input_ = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
/** Cache parameters for complexity heuristic. */
|
|
|
|
|
uint nodes_total_ = 0;
|
|
|
|
|
uint textures_total_ = 0;
|
|
|
|
|
uint uniforms_total_ = 0;
|
2011-09-09 11:55:38 +00:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
public:
|
|
|
|
|
GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_, const char *debug_name);
|
|
|
|
|
~GPUCodegen();
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
void generate_graphs();
|
|
|
|
|
void generate_cryptomatte();
|
|
|
|
|
void generate_uniform_buffer();
|
|
|
|
|
void generate_attribs();
|
|
|
|
|
void generate_resources();
|
|
|
|
|
void generate_library();
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
uint32_t hash_get() const
|
|
|
|
|
{
|
|
|
|
|
return hash_;
|
|
|
|
|
}
|
2024-06-07 16:11:50 +02:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
/* Heuristic determined during pass codegen for whether a
|
|
|
|
|
* more optimal variant of this material should be compiled. */
|
|
|
|
|
bool should_optimize_heuristic() const;
|
2024-06-07 16:11:50 +02:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
private:
|
|
|
|
|
void set_unique_ids();
|
2024-07-25 19:18:07 +02:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
void node_serialize(std::stringstream &eval_ss, const GPUNode *node);
|
|
|
|
|
std::string graph_serialize(eGPUNodeTag tree_tag,
|
|
|
|
|
GPUNodeLink *output_link,
|
|
|
|
|
const char *output_default = nullptr);
|
|
|
|
|
std::string graph_serialize(eGPUNodeTag tree_tag);
|
|
|
|
|
};
|
2018-03-11 23:43:09 +01:00
|
|
|
|
2025-05-22 17:53:22 +02:00
|
|
|
} // namespace blender::gpu::shader
|