32 glUniformBlockBinding(
program, block_index, block_index);
43 glGetActiveUniformsiv(
program, 1, &uniform_index, GL_UNIFORM_TYPE, &
type);
50 case GL_SAMPLER_CUBE_MAP_ARRAY_ARB:
51 case GL_SAMPLER_1D_SHADOW:
52 case GL_SAMPLER_2D_SHADOW:
53 case GL_SAMPLER_1D_ARRAY:
54 case GL_SAMPLER_2D_ARRAY:
55 case GL_SAMPLER_1D_ARRAY_SHADOW:
56 case GL_SAMPLER_2D_ARRAY_SHADOW:
57 case GL_SAMPLER_2D_MULTISAMPLE:
58 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
59 case GL_SAMPLER_CUBE_SHADOW:
60 case GL_SAMPLER_BUFFER:
61 case GL_INT_SAMPLER_1D:
62 case GL_INT_SAMPLER_2D:
63 case GL_INT_SAMPLER_3D:
64 case GL_INT_SAMPLER_CUBE:
65 case GL_INT_SAMPLER_1D_ARRAY:
66 case GL_INT_SAMPLER_2D_ARRAY:
67 case GL_INT_SAMPLER_2D_MULTISAMPLE:
68 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
69 case GL_INT_SAMPLER_BUFFER:
70 case GL_UNSIGNED_INT_SAMPLER_1D:
71 case GL_UNSIGNED_INT_SAMPLER_2D:
72 case GL_UNSIGNED_INT_SAMPLER_3D:
73 case GL_UNSIGNED_INT_SAMPLER_CUBE:
74 case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY:
75 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
76 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
77 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
78 case GL_UNSIGNED_INT_SAMPLER_BUFFER: {
81 int binding = *sampler_len;
82 glUniform1i(uniform_location, binding);
98 glGetActiveUniformsiv(
program, 1, &uniform_index, GL_UNIFORM_TYPE, &
type);
105 case GL_IMAGE_BUFFER:
106 case GL_IMAGE_1D_ARRAY:
107 case GL_IMAGE_2D_ARRAY:
108 case GL_IMAGE_CUBE_MAP_ARRAY:
109 case GL_INT_IMAGE_1D:
110 case GL_INT_IMAGE_2D:
111 case GL_INT_IMAGE_3D:
112 case GL_INT_IMAGE_CUBE:
113 case GL_INT_IMAGE_BUFFER:
114 case GL_INT_IMAGE_1D_ARRAY:
115 case GL_INT_IMAGE_2D_ARRAY:
116 case GL_INT_IMAGE_CUBE_MAP_ARRAY:
117 case GL_UNSIGNED_INT_IMAGE_1D:
118 case GL_UNSIGNED_INT_IMAGE_2D:
119 case GL_UNSIGNED_INT_IMAGE_3D:
120 case GL_UNSIGNED_INT_IMAGE_CUBE:
121 case GL_UNSIGNED_INT_IMAGE_BUFFER:
122 case GL_UNSIGNED_INT_IMAGE_1D_ARRAY:
123 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
124 case GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY: {
127 int binding = *image_len;
128 glUniform1i(uniform_location, binding);
140 GLenum
property = GL_BUFFER_BINDING;
141 GLint values_written = 0;
142 glGetProgramResourceiv(
143 program, GL_SHADER_STORAGE_BLOCK, ssbo_index, 1, &property, 1, &values_written, &binding);
159 GLint max_attr_name_len = 0, attr_len = 0;
160 glGetProgramiv(
program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_attr_name_len);
161 glGetProgramiv(
program, GL_ACTIVE_ATTRIBUTES, &attr_len);
163 GLint max_ubo_name_len = 0, ubo_len = 0;
164 glGetProgramiv(
program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &max_ubo_name_len);
165 glGetProgramiv(
program, GL_ACTIVE_UNIFORM_BLOCKS, &ubo_len);
167 GLint max_uniform_name_len = 0, active_uniform_len = 0, uniform_len = 0;
168 glGetProgramiv(
program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_uniform_name_len);
169 glGetProgramiv(
program, GL_ACTIVE_UNIFORMS, &active_uniform_len);
170 uniform_len = active_uniform_len;
172 GLint max_ssbo_name_len = 0, ssbo_len = 0;
174 glGetProgramInterfaceiv(
program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &ssbo_len);
175 glGetProgramInterfaceiv(
176 program, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &max_ssbo_name_len);
183 if (attr_len > 0 && max_attr_name_len == 0) {
184 max_attr_name_len = 256;
186 if (ubo_len > 0 && max_ubo_name_len == 0) {
187 max_ubo_name_len = 256;
189 if (uniform_len > 0 && max_uniform_name_len == 0) {
190 max_uniform_name_len = 256;
192 if (ssbo_len > 0 && max_ssbo_name_len == 0) {
193 max_ssbo_name_len = 256;
198 GLint max_ubo_uni_len = 0;
199 for (
int i = 0; i < ubo_len; i++) {
201 glGetActiveUniformBlockiv(
program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &ubo_uni_len);
202 max_ubo_uni_len =
max_ii(max_ubo_uni_len, ubo_uni_len);
203 uniform_len -= ubo_uni_len;
208 GLint *ubo_uni_ids = (GLint *)
MEM_mallocN(
sizeof(GLint) * max_ubo_uni_len, __func__);
209 for (
int i = 0; i < ubo_len; i++) {
211 glGetActiveUniformBlockiv(
program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &ubo_uni_len);
212 glGetActiveUniformBlockiv(
program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, ubo_uni_ids);
213 for (
int u = 0; u < ubo_uni_len; u++) {
219 int input_tot_len = attr_len + ubo_len + uniform_len + ssbo_len;
222 const uint32_t name_buffer_len = attr_len * max_attr_name_len + ubo_len * max_ubo_name_len +
223 uniform_len * max_uniform_name_len +
224 ssbo_len * max_ssbo_name_len;
230 for (
int i = 0; i < attr_len; i++) {
232 GLsizei remaining_buffer = name_buffer_len - name_buffer_offset;
233 GLsizei name_len = 0;
237 glGetActiveAttrib(
program, i, remaining_buffer, &name_len, &
size, &
type, name);
238 GLint location = glGetAttribLocation(
program, name);
240 if (location == -1) {
252 for (
int i = 0; i < ubo_len; i++) {
254 GLsizei remaining_buffer = name_buffer_len - name_buffer_offset;
255 GLsizei name_len = 0;
257 glGetActiveUniformBlockName(
program, i, remaining_buffer, &name_len, name);
262 name_buffer_offset += this->
set_input_name(input, name, name_len);
267 for (
int i = 0,
sampler = 0,
image = 0; i < active_uniform_len; i++) {
272 GLsizei remaining_buffer = name_buffer_len - name_buffer_offset;
273 GLsizei name_len = 0;
275 glGetActiveUniformName(
program, i, remaining_buffer, &name_len, name);
281 name_buffer_offset += this->
set_input_name(input, name, name_len);
284 if (
input->binding == -1) {
292 for (
int i = 0; i < ssbo_len; i++) {
294 GLsizei remaining_buffer = name_buffer_len - name_buffer_offset;
295 GLsizei name_len = 0;
296 glGetProgramResourceName(
297 program, GL_SHADER_STORAGE_BLOCK, i, remaining_buffer, &name_len, name);
304 name_buffer_offset += this->
set_input_name(input, name, name_len);
324 if (name_buffer_offset < name_buffer_len) {
347 switch (res.bind_type) {
348 case ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
351 case ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
354 case ShaderCreateInfo::Resource::BindType::SAMPLER:
357 case ShaderCreateInfo::Resource::BindType::IMAGE:
363 size_t workaround_names_size = 0;
365 auto check_enabled_uniform = [&](
const char *uniform_name) {
366 if (glGetUniformLocation(
program, uniform_name) != -1) {
367 workaround_uniform_names.
append(uniform_name);
374 check_enabled_uniform(
"gpu_BaseInstance");
399 if (
input->location != -1) {
407 if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) {
411 glUniformBlockBinding(
program,
input->location, res.slot);
413 input->binding = res.slot;
421 if (res.bind_type == ShaderCreateInfo::Resource::BindType::SAMPLER) {
426 input->location = glGetUniformLocation(
program, res.sampler.name.c_str());
427 glUniform1i(
input->location, res.slot);
429 input->binding = res.slot;
433 else if (res.bind_type == ShaderCreateInfo::Resource::BindType::IMAGE) {
437 input->location = glGetUniformLocation(
program, res.image.name.c_str());
438 glUniform1i(
input->location, res.slot);
440 input->binding = res.slot;
453 for (
auto &name : workaround_uniform_names) {
462 if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) {
491 for (
auto *ref : refs_) {
492 if (ref !=
nullptr) {
506 for (
int i = 0; i < refs_.size(); i++) {
507 if (refs_[i] ==
nullptr) {
517 for (
int i = 0; i < refs_.size(); i++) {
518 if (refs_[i] == ref) {
#define BLI_assert_msg(a, msg)
#define BLI_BITMAP_NEW(_num, _alloc_string)
#define BLI_BITMAP_TEST(_bitmap, _index)
#define BLI_BITMAP_ENABLE(_bitmap, _index)
MINLINE int max_ii(int a, int b)
bool GPU_shader_storage_buffer_objects_support(void)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
#define MEM_reallocN(vmemh, len)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr int64_t size() const
constexpr const char * c_str() const
void append(const T &value)
void extend(Span< T > array)
static bool shader_draw_parameters_support
static bool explicit_location_support
void ref_add(GLVaoCache *ref)
GLShaderInterface(GLuint program, const shader::ShaderCreateInfo &info)
void ref_remove(GLVaoCache *ref)
void copy_input_name(ShaderInput *input, const StringRefNull &name, char *name_buffer, uint32_t &name_buffer_offset) const
const ShaderInput * ubo_get(const char *name) const
uint16_t enabled_ssbo_mask_
uint64_t enabled_tex_mask_
uint32_t set_input_name(ShaderInput *input, char *name, uint32_t name_len) const
static const char * builtin_uniform_block_name(GPUUniformBlockBuiltin u)
uint8_t enabled_ima_mask_
int32_t builtin_blocks_[GPU_NUM_UNIFORM_BLOCKS]
const ShaderInput * uniform_get(const char *name) const
int32_t builtins_[GPU_NUM_UNIFORMS]
uint16_t enabled_attr_mask_
uint16_t enabled_ubo_mask_
static const char * builtin_uniform_name(GPUUniformBuiltin u)
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
ccl_global KernelShaderEvalInput * input
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
static int block_binding(int32_t program, uint32_t block_index)
static int sampler_binding(int32_t program, uint32_t uniform_index, int32_t uniform_location, int *sampler_len)
static int ssbo_binding(int32_t program, uint32_t ssbo_index)
static int image_binding(int32_t program, uint32_t uniform_index, int32_t uniform_location, int *image_len)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Vector< VertIn > vertex_inputs_
Vector< Resource > batch_resources_
size_t interface_names_size_
Vector< Resource > pass_resources_
Vector< PushConst > push_constants_