gpu: Cache GL state

That way we don't need to setup the textures and program for every
command.
This commit is contained in:
Benjamin Otte 2023-11-04 04:13:57 +01:00
parent 1733671295
commit 6230ff0fc4
4 changed files with 32 additions and 9 deletions

View File

@ -155,10 +155,10 @@ gsk_gpu_mipmap_op_gl_command (GskGpuOp *op,
{
GskGpuMipmapOp *self = (GskGpuMipmapOp *) op;
/* not sure the ActiveTexture call is needed, but better not
* use any random texturing instance */
glActiveTexture (GL_TEXTURE0);
gsk_gl_image_bind_texture (GSK_GL_IMAGE (self->image));
/* need to reset the images again */
state->desc = NULL;
glGenerateMipmap (GL_TEXTURE_2D);

View File

@ -23,6 +23,12 @@ typedef struct _GskVulkanCommandState GskVulkanCommandState;
struct _GskGLCommandState
{
gsize flip_y;
struct {
const GskGpuOpClass *op_class;
GskGpuShaderClip clip;
gsize n_external;
} current_program;
GskGLDescriptors *desc;
};
#ifdef GDK_RENDERING_VULKAN

View File

@ -92,16 +92,32 @@ gsk_gpu_shader_op_gl_command_n (GskGpuOp *op,
GskGpuShaderOpClass *shader_op_class = (GskGpuShaderOpClass *) op->op_class;
GskGLDescriptors *desc;
GskGpuOp *next;
gsize i, n;
gsize i, n, n_external;
desc = GSK_GL_DESCRIPTORS (self->desc);
if (desc)
n_external = gsk_gl_descriptors_get_n_external (desc);
else
n_external = 0;
if (state->current_program.op_class != op->op_class ||
state->current_program.clip != self->clip ||
state->current_program.n_external != n_external)
{
state->current_program.op_class = op->op_class;
state->current_program.clip = self->clip;
state->current_program.n_external = n_external;
gsk_gl_frame_use_program (GSK_GL_FRAME (frame),
shader_op_class,
self->clip,
desc ? gsk_gl_descriptors_get_n_external (desc) : 0);
n_external);
}
if (desc)
gsk_gl_descriptors_use (GSK_GL_DESCRIPTORS (desc));
if (desc != state->desc && desc)
{
gsk_gl_descriptors_use (desc);
state->desc = desc;
}
if (gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_MERGE))
n = MAX_MERGE_OPS;

View File

@ -6,6 +6,7 @@
#define GSK_GPU_PATTERN_STACK_SIZE 16
typedef struct _GskGLDescriptors GskGLDescriptors;
typedef struct _GskGpuBuffer GskGpuBuffer;
typedef struct _GskGpuDescriptors GskGpuDescriptors;
typedef struct _GskGpuDevice GskGpuDevice;