2011-06-30 15:55:56 +01:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2011-06-30 15:55:56 +01:00
|
|
|
*
|
2013-03-25 16:54:51 +00:00
|
|
|
* Copyright (C) 2011, 2013 Intel Corporation.
|
2011-06-30 15:55:56 +01:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2011-06-30 15:55:56 +01:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2011-06-30 15:55:56 +01:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2011-06-30 15:55:56 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2016-05-05 22:21:51 +08:00
|
|
|
#include "cogl-config.h"
|
2011-06-30 15:55:56 +01:00
|
|
|
|
2011-09-23 16:43:05 +08:00
|
|
|
#include "cogl-context-private.h"
|
2011-06-30 15:55:56 +01:00
|
|
|
#include "cogl-pipeline-private.h"
|
|
|
|
#include "cogl-pipeline-cache.h"
|
2022-08-05 10:55:42 +02:00
|
|
|
#include "cogl-pipeline-cache-private.h"
|
2013-03-25 16:54:51 +00:00
|
|
|
#include "cogl-pipeline-hash-table.h"
|
2011-06-30 15:55:56 +01:00
|
|
|
|
|
|
|
struct _CoglPipelineCache
|
|
|
|
{
|
2013-03-25 16:54:51 +00:00
|
|
|
CoglPipelineHashTable fragment_hash;
|
|
|
|
CoglPipelineHashTable vertex_hash;
|
|
|
|
CoglPipelineHashTable combined_hash;
|
2011-06-30 15:55:56 +01:00
|
|
|
};
|
|
|
|
|
2013-03-25 16:54:51 +00:00
|
|
|
CoglPipelineCache *
|
|
|
|
_cogl_pipeline_cache_new (void)
|
2011-06-30 15:55:56 +01:00
|
|
|
{
|
2019-07-09 11:13:09 +02:00
|
|
|
g_autofree CoglPipelineCache *cache = g_new (CoglPipelineCache, 1);
|
2013-03-25 16:54:51 +00:00
|
|
|
unsigned long vertex_state;
|
|
|
|
unsigned long layer_vertex_state;
|
2011-06-30 15:55:56 +01:00
|
|
|
unsigned int fragment_state;
|
|
|
|
unsigned int layer_fragment_state;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
2013-03-25 16:54:51 +00:00
|
|
|
vertex_state =
|
2013-06-20 13:25:49 +01:00
|
|
|
_cogl_pipeline_get_state_for_vertex_codegen (ctx);
|
2013-03-25 16:54:51 +00:00
|
|
|
layer_vertex_state =
|
|
|
|
COGL_PIPELINE_LAYER_STATE_AFFECTS_VERTEX_CODEGEN;
|
2011-06-30 15:55:56 +01:00
|
|
|
fragment_state =
|
|
|
|
_cogl_pipeline_get_state_for_fragment_codegen (ctx);
|
|
|
|
layer_fragment_state =
|
|
|
|
_cogl_pipeline_get_layer_state_for_fragment_codegen (ctx);
|
|
|
|
|
2013-03-25 16:54:51 +00:00
|
|
|
_cogl_pipeline_hash_table_init (&cache->vertex_hash,
|
|
|
|
vertex_state,
|
|
|
|
layer_vertex_state,
|
|
|
|
"vertex shaders");
|
|
|
|
_cogl_pipeline_hash_table_init (&cache->fragment_hash,
|
|
|
|
fragment_state,
|
|
|
|
layer_fragment_state,
|
|
|
|
"fragment shaders");
|
|
|
|
_cogl_pipeline_hash_table_init (&cache->combined_hash,
|
|
|
|
vertex_state | fragment_state,
|
|
|
|
layer_vertex_state | layer_fragment_state,
|
|
|
|
"programs");
|
2011-06-30 15:55:56 +01:00
|
|
|
|
2019-07-09 11:13:09 +02:00
|
|
|
return g_steal_pointer (&cache);
|
2011-06-30 15:55:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-01 14:15:25 +00:00
|
|
|
_cogl_pipeline_cache_free (CoglPipelineCache *cache)
|
2011-06-30 15:55:56 +01:00
|
|
|
{
|
2013-03-25 16:54:51 +00:00
|
|
|
_cogl_pipeline_hash_table_destroy (&cache->fragment_hash);
|
|
|
|
_cogl_pipeline_hash_table_destroy (&cache->vertex_hash);
|
|
|
|
_cogl_pipeline_hash_table_destroy (&cache->combined_hash);
|
2011-06-30 15:55:56 +01:00
|
|
|
g_free (cache);
|
|
|
|
}
|
|
|
|
|
2013-12-18 15:18:39 +00:00
|
|
|
CoglPipelineCacheEntry *
|
2011-06-30 15:55:56 +01:00
|
|
|
_cogl_pipeline_cache_get_fragment_template (CoglPipelineCache *cache,
|
|
|
|
CoglPipeline *key_pipeline)
|
|
|
|
{
|
2013-03-25 16:54:51 +00:00
|
|
|
return _cogl_pipeline_hash_table_get (&cache->fragment_hash,
|
|
|
|
key_pipeline);
|
2011-06-30 15:55:56 +01:00
|
|
|
}
|
2011-06-30 18:34:05 +01:00
|
|
|
|
2013-12-18 15:18:39 +00:00
|
|
|
CoglPipelineCacheEntry *
|
2011-06-30 18:34:05 +01:00
|
|
|
_cogl_pipeline_cache_get_vertex_template (CoglPipelineCache *cache,
|
|
|
|
CoglPipeline *key_pipeline)
|
|
|
|
{
|
2013-03-25 16:54:51 +00:00
|
|
|
return _cogl_pipeline_hash_table_get (&cache->vertex_hash,
|
|
|
|
key_pipeline);
|
2011-06-30 18:34:05 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 15:18:39 +00:00
|
|
|
CoglPipelineCacheEntry *
|
2011-06-30 18:34:05 +01:00
|
|
|
_cogl_pipeline_cache_get_combined_template (CoglPipelineCache *cache,
|
|
|
|
CoglPipeline *key_pipeline)
|
|
|
|
{
|
2013-03-25 16:54:51 +00:00
|
|
|
return _cogl_pipeline_hash_table_get (&cache->combined_hash,
|
|
|
|
key_pipeline);
|
2011-06-30 18:34:05 +01:00
|
|
|
}
|
2013-12-18 15:18:39 +00:00
|
|
|
|
2022-08-05 10:55:42 +02:00
|
|
|
CoglPipelineHashTable *
|
|
|
|
cogl_pipeline_cache_get_fragment_hash (CoglPipelineCache *cache)
|
2013-12-18 15:18:39 +00:00
|
|
|
{
|
2022-08-05 10:55:42 +02:00
|
|
|
return &cache->fragment_hash;
|
2013-12-18 15:18:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-05 10:55:42 +02:00
|
|
|
CoglPipelineHashTable *
|
|
|
|
cogl_pipeline_cache_get_combined_hash (CoglPipelineCache *cache)
|
2013-12-18 15:18:39 +00:00
|
|
|
{
|
2022-08-05 10:55:42 +02:00
|
|
|
return &cache->combined_hash;
|
2013-12-18 15:18:39 +00:00
|
|
|
}
|