Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only reset uniforms that needs resetting, only set each uniform once per item draw. #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions glass-renderer/bitmap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef BITMAP_H
#define BITMAP_H

#define BITMAP(arr, idx) ((arr[(idx) / 8] & (1 << ((idx) % 8))) >> ((idx) % 8))
#define BITMAP_SET(arr, idx, val) (arr[(idx) / 8] = ((arr[(idx) / 8] & ~(1 << ((idx) % 8))) | ((val) << ((idx) % 8))))

#endif
33 changes: 27 additions & 6 deletions glass-renderer/item.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <limits.h>
#include "property.h"
#include "debug.h"
#include "list.h"
#include "rendering.h"
#include <X11/Xatom.h>

Expand Down Expand Up @@ -110,6 +111,32 @@ void item_constructor(Item *item, Window window) {
void item_destructor(Item *item) {
texture_destroy(&item->window_texture);
}
void item_reset_uniforms(Rendering *rendering) {
rendering->properties = root_item->properties;
rendering->properties_prefix = "root_";
properties_set_program_cache_idx(rendering);
ProgramCache *root_cache = &root_item->properties->programs[rendering->program_cache_idx];

rendering->properties = rendering->item->properties;
rendering->properties_prefix = "";
properties_set_program_cache_idx(rendering);
ProgramCache *cache = &rendering->properties->programs[rendering->program_cache_idx];


Shader *shader = rendering->shader;
List *uniforms = shader->uniforms;
unsigned char *used_uniforms = cache->used_uniforms;
unsigned char *root_used_uniforms = root_cache->used_uniforms;

for (size_t i = 0; i*8 < uniforms->count; i++) {
unsigned char mask = used_uniforms[i] | root_used_uniforms[i];
for (int j = 0; (j < 8) && (i*8 + j < uniforms->count); j++, mask=mask>>1) {
if (!(mask & 1)) {
shader_reset_uniform((Uniform *) uniforms->entries[i*8 + j]);
}
}
}
}
void item_draw(Rendering *rendering) {
if (rendering->item->is_mapped) {
Item *item = (Item *) rendering->item;
Expand All @@ -125,15 +152,9 @@ void item_draw(Rendering *rendering) {
rendering->texture_unit++;
}


properties_to_gl(root_item->properties, "root_", rendering);
GL_CHECK_ERROR("item_draw_root_properties", "%ld.%s", item->window, rendering->shader->name_str);
properties_to_gl(rendering->item->properties, "", rendering);
GL_CHECK_ERROR("item_draw_properties", "%ld.%s", item->window, rendering->shader->name_str);

glUniform1i(shader->picking_mode_attr, rendering->view->picking);
glUniform4fv(shader->screen_attr, 1, rendering->view->screen);
glUniform2i(shader->size_attr, rendering->view->width, rendering->view->height);
glUniform1i(shader->border_width_attr, rendering->item->attr.border_width);

DEBUG("setwin", "%ld\n", rendering->item->window);
Expand Down
1 change: 1 addition & 0 deletions glass-renderer/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern void item_add(Item *item);
extern void item_remove(Item *item);

extern void item_draw(Rendering *rendering);
extern void item_reset_uniforms(Rendering *rendering);
extern void item_update(Item *item);
extern Shader *item_get_shader(Item *item);
extern void item_print(Item *);
Expand Down
47 changes: 43 additions & 4 deletions glass-renderer/property.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "property.h"
#include "shader.h"
#include "rendering.h"
#include "bitmap.h"
#include "debug.h"

Property *property_allocate(Properties *properties, Atom name) {
Expand All @@ -11,6 +12,7 @@ Property *property_allocate(Properties *properties, Atom name) {
prop->type = None;
prop->values.bytes = NULL;
for (size_t i = 0; i < PROGRAM_CACHE_SIZE; i++) {
prop->programs[i].shader = NULL;
prop->programs[i].program = -1;
prop->programs[i].prefix = NULL;
prop->programs[i].data = NULL;
Expand Down Expand Up @@ -72,6 +74,7 @@ void property_free(Property *prop) {

void property_update_gl_cache(Property *prop, Rendering *rendering, ProgramCache *cache, PropertyProgramCache *prop_cache, PropertyTypeHandler *type) {
if (prop_cache->program != -1) type->free_program(prop, rendering->program_cache_idx);
prop_cache->shader = cache->shader;
prop_cache->program = cache->program;
prop_cache->prefix = cache->prefix;
prop_cache->name_str = realloc(prop_cache->name_str, strlen(cache->prefix) + strlen(prop->name_str) + 1);
Expand All @@ -91,11 +94,11 @@ void property_update_gl_cache(Property *prop, Rendering *rendering, ProgramCache
glCreateBuffers(1, &prop_cache->buffer);
}
}

type->load_program(prop, rendering);
if (prop_cache->location != -1) BITMAP_SET(cache->used_uniforms, prop_cache->location, 1);
if (type->load_program) type->load_program(prop, rendering);
}

void property_to_gl(Property *prop, Rendering *rendering) {
void property_load_program(Property *prop, Rendering *rendering) {
PropertyTypeHandler *type = prop->type_handler;
if (!type) return;

Expand All @@ -108,6 +111,11 @@ void property_to_gl(Property *prop, Rendering *rendering) {
|| prop_cache->prefix != cache->prefix) {
property_update_gl_cache(prop, rendering, cache, prop_cache, type);
}
}

void property_to_gl(Property *prop, Rendering *rendering) {
PropertyTypeHandler *type = prop->type_handler;
if (!type) return;
type->to_gl(prop, rendering);
}

Expand All @@ -127,6 +135,12 @@ Properties *properties_load(Window window) {
properties->window = window;
properties->programs_pos = 0;
properties->properties = list_create();
for (size_t idx = 0; idx < PROGRAM_CACHE_SIZE; idx++) {
properties->programs[idx].shader = NULL;
properties->programs[idx].program = None;
properties->programs[idx].prefix = NULL;
memset(properties->programs[idx].used_uniforms, 0, GL_MAX_UNIFORM_LOCATIONS / 8 + 1);
}
int nr_props;
Atom *prop_names = XListProperties(display, window, &nr_props);
for (int i = 0; i < nr_props; i++) {
Expand Down Expand Up @@ -160,12 +174,24 @@ void properties_free(Properties *properties) {
free(properties);
}

void properties_load_program(Rendering *rendering) {
size_t program_cache_idx = rendering->program_cache_idx;
ProgramCache *cache = &rendering->properties->programs[program_cache_idx];

if (!cache->shader || !cache->used_uniforms) return;

for (size_t i = 0; i < rendering->properties->properties->count; i++) {
Property *prop = rendering->properties->properties->entries[i];
property_load_program(prop, rendering);
}
}

void properties_set_program_cache_idx(Rendering *rendering) {
size_t idx;
Properties *properties = rendering->properties;

for (idx = 0; idx < PROGRAM_CACHE_SIZE; idx++) {
if ( properties->programs[idx].program == rendering->shader->program
if ( properties->programs[idx].shader == rendering->shader
&& properties->programs[idx].prefix == rendering->properties_prefix) {
rendering->program_cache_idx = idx;
return;
Expand All @@ -175,8 +201,21 @@ void properties_set_program_cache_idx(Rendering *rendering) {
properties->programs_pos = idx;
rendering->program_cache_idx = idx;

properties->programs[idx].shader = rendering->shader;
properties->programs[idx].program = rendering->shader->program;
properties->programs[idx].prefix = rendering->properties_prefix;

unsigned char *used_uniforms = properties->programs[idx].used_uniforms;
memset(used_uniforms, 0, GL_MAX_UNIFORM_LOCATIONS / 8 + 1);

BITMAP_SET(used_uniforms, rendering->shader->screen_attr, 1);
BITMAP_SET(used_uniforms, rendering->shader->size_attr, 1);
BITMAP_SET(used_uniforms, rendering->shader->border_width_attr, 1);
BITMAP_SET(used_uniforms, rendering->shader->picking_mode_attr, 1);
BITMAP_SET(used_uniforms, rendering->shader->window_id_attr, 1);
BITMAP_SET(used_uniforms, rendering->shader->window_sampler_attr , 1);

properties_load_program(rendering);
}

void properties_to_gl(Properties *properties, char *prefix, Rendering *rendering) {
Expand Down
6 changes: 5 additions & 1 deletion glass-renderer/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef struct PropertyTypeHandlerT PropertyTypeHandler;


struct PropertyProgramCacheStruct {
Shader *shader;
GLint program;
char *prefix;
char *name_str;
Expand Down Expand Up @@ -61,8 +62,10 @@ extern void property_to_gl(Property *prop, Rendering *rendering);
extern void property_print(Property *prop, FILE *fp);

struct ProgramCacheStruct {
GLint program;
Shader *shader;
GLint program;
char *prefix;
unsigned char used_uniforms[GL_MAX_UNIFORM_LOCATIONS / 8 + 1];
};
struct PropertiesStruct {
Window window;
Expand All @@ -74,6 +77,7 @@ struct PropertiesStruct {
extern Properties *properties_load(Window window);
extern Bool properties_update(Properties *properties, Atom name);
extern void properties_free(Properties *properties);
extern void properties_set_program_cache_idx(Rendering *rendering);
extern void properties_to_gl(Properties *properties, char *prefix, Rendering *rendering);
extern void properties_print(Properties *properties, FILE *fp);
extern Property *properties_find(Properties *properties, Atom name);
Expand Down
4 changes: 4 additions & 0 deletions glass-renderer/property_net_wm_icon.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "property_net_wm_icon.h"
#include "rendering.h"
#include "texture.h"
#include "bitmap.h"
#include "debug.h"

typedef struct {
Expand Down Expand Up @@ -46,6 +47,7 @@ void property_net_wm_icon_print(Property *prop, FILE *fp) {
fprintf(fp, "%ld.%s=<_NET_WM_ICON icon>\n", prop->window, prop->name_str);
}
void property_net_wm_load_program(Property *prop, Rendering *rendering) {
ProgramCache *cache = &rendering->properties->programs[rendering->program_cache_idx];
PropertyProgramCache *prop_cache = &prop->programs[rendering->program_cache_idx];
prop_cache->data = malloc(sizeof(NetWmIconPropertyProgramData));
NetWmIconPropertyProgramData *program_data = (NetWmIconPropertyProgramData *) prop_cache->data;
Expand All @@ -55,6 +57,8 @@ void property_net_wm_load_program(Property *prop, Rendering *rendering) {
strcpy(program_data->enabled_str + strlen(prop_cache->name_str), "_enabled");

program_data->enabled_location = glGetUniformLocation(prop_cache->program, program_data->enabled_str);
if (program_data->enabled_location != -1) BITMAP_SET(cache->used_uniforms, program_data->enabled_location, 1);

char *icon_status = "";
char *icon_enabled_status = "";
char *all_status = "";
Expand Down
5 changes: 5 additions & 0 deletions glass-renderer/property_svg.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "glapi.h"
#include "xapi.h"
#include "wm.h"
#include "bitmap.h"
#include "debug.h"
#include <librsvg/rsvg.h>

Expand Down Expand Up @@ -202,6 +203,7 @@ void property_svg_print(Property *prop, FILE *fp) {
fprintf(fp, "%ld.%s=<svg>\n", prop->window, prop->name_str);
}
void property_svg_load_program(Property *prop, Rendering *rendering) {
ProgramCache *cache = &rendering->properties->programs[rendering->program_cache_idx];
PropertyProgramCache *prop_cache = &prop->programs[rendering->program_cache_idx];

prop_cache->data = malloc(sizeof(SvgPropertyData));
Expand All @@ -213,6 +215,9 @@ void property_svg_load_program(Property *prop, Rendering *rendering) {

program_data->texture_location = glGetUniformLocation(prop_cache->program, prop_cache->name_str);
program_data->transform_location = glGetUniformLocation(prop_cache->program, program_data->transform_str);
if (program_data->texture_location != -1) BITMAP_SET(cache->used_uniforms, program_data->texture_location, 1);
if (program_data->transform_location != -1) BITMAP_SET(cache->used_uniforms, program_data->transform_location, 1);

char *status = NULL;
if (program_data->texture_location != -1 && program_data->transform_location != -1) {
status = "enabled";
Expand Down
7 changes: 7 additions & 0 deletions glass-renderer/property_wm_hints_icon.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "property_wm_hints_icon.h"
#include "rendering.h"
#include "texture.h"
#include "bitmap.h"
#include "debug.h"

typedef struct {
Expand Down Expand Up @@ -83,6 +84,7 @@ void property_wm_hints_icon_print(Property *prop, FILE *fp) {
fprintf(fp, "%ld.%s=<WM_HINTS icon>\n", prop->window, prop->name_str);
}
void property_wm_hints_load_program(Property *prop, Rendering *rendering) {
ProgramCache *cache = &rendering->properties->programs[rendering->program_cache_idx];
PropertyProgramCache *prop_cache = &prop->programs[rendering->program_cache_idx];

prop_cache->data = malloc(sizeof(WmHintsPropertyProgramData));
Expand All @@ -108,6 +110,11 @@ void property_wm_hints_load_program(Property *prop, Rendering *rendering) {
program_data->icon_mask_location = glGetUniformLocation(prop_cache->program, program_data->icon_mask_str);
program_data->icon_enabled_location = glGetUniformLocation(prop_cache->program, program_data->icon_enabled_str);
program_data->icon_mask_enabled_location = glGetUniformLocation(prop_cache->program, program_data->icon_mask_enabled_str);
if (program_data->icon_location != -1) BITMAP_SET(cache->used_uniforms, program_data->icon_location, 1);
if (program_data->icon_mask_location != -1) BITMAP_SET(cache->used_uniforms, program_data->icon_mask_location, 1);
if (program_data->icon_enabled_location != -1) BITMAP_SET(cache->used_uniforms, program_data->icon_enabled_location, 1);
if (program_data->icon_mask_enabled_location != -1) BITMAP_SET(cache->used_uniforms, program_data->icon_mask_enabled_location, 1);

char *icon_status = "";
char *icon_mask_status = "";
char *icon_enabled_status = "";
Expand Down
19 changes: 11 additions & 8 deletions glass-renderer/rendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ struct PropertiesStruct;
typedef struct PropertiesStruct Properties;

typedef struct {
Item *item;
View *view;
Shader *shader;
Properties *properties;
char *properties_prefix;
size_t program_cache_idx;
GLuint texture_unit;
size_t array_length;
unsigned char *initialized_shaders;
GLuint *global_texture_units;

Item *item;
View *view;
Shader *shader;
Properties *properties;
char *properties_prefix;
size_t program_cache_idx;
GLuint texture_unit;
size_t array_length;
} Rendering;

#endif
Loading