1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_
11 #include "base/containers/hash_tables.h"
12 #include "base/sha1.h"
13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
15 #include "gpu/command_buffer/service/shader_manager.h"
22 // Program cache base class for caching linked gpu programs
23 class GPU_EXPORT ProgramCache
{
25 static const size_t kHashLength
= base::kSHA1Length
;
27 typedef std::map
<std::string
, GLint
> LocationMap
;
29 enum LinkedProgramStatus
{
34 enum ProgramLoadResult
{
40 virtual ~ProgramCache();
42 LinkedProgramStatus
GetLinkedProgramStatus(
43 const std::string
& shader_signature_a
,
44 const std::string
& shader_signature_b
,
45 const LocationMap
* bind_attrib_location_map
,
46 const std::vector
<std::string
>& transform_feedback_varyings
,
47 GLenum transform_feedback_buffer_mode
) const;
49 // Loads the linked program from the cache. If the program is not found or
50 // there was an error, PROGRAM_LOAD_FAILURE should be returned.
51 virtual ProgramLoadResult
LoadLinkedProgram(
55 const LocationMap
* bind_attrib_location_map
,
56 const std::vector
<std::string
>& transform_feedback_varyings
,
57 GLenum transform_feedback_buffer_mode
,
58 const ShaderCacheCallback
& shader_callback
) = 0;
60 // Saves the program into the cache. If successful, the implementation should
61 // call LinkedProgramCacheSuccess.
62 virtual void SaveLinkedProgram(
64 const Shader
* shader_a
,
65 const Shader
* shader_b
,
66 const LocationMap
* bind_attrib_location_map
,
67 const std::vector
<std::string
>& transform_feedback_varyings
,
68 GLenum transform_feedback_buffer_mode
,
69 const ShaderCacheCallback
& shader_callback
) = 0;
71 virtual void LoadProgram(const std::string
& program
) = 0;
77 void LinkedProgramCacheSuccess(const std::string
& shader_signature_a
,
78 const std::string
& shader_signature_b
,
79 const LocationMap
* bind_attrib_location_map
,
80 const std::vector
<std::string
>& transform_feedback_varyings
,
81 GLenum transform_feedback_buffer_mode
);
84 // called by implementing class after a shader was successfully cached
85 void LinkedProgramCacheSuccess(const std::string
& program_hash
);
87 // result is not null terminated
88 void ComputeShaderHash(const std::string
& shader
,
91 // result is not null terminated. hashed shaders are expected to be
92 // kHashLength in length
93 void ComputeProgramHash(
94 const char* hashed_shader_0
,
95 const char* hashed_shader_1
,
96 const LocationMap
* bind_attrib_location_map
,
97 const std::vector
<std::string
>& transform_feedback_varyings
,
98 GLenum transform_feedback_buffer_mode
,
101 void Evict(const std::string
& program_hash
);
104 typedef base::hash_map
<std::string
,
105 LinkedProgramStatus
> LinkStatusMap
;
107 // called to clear the backend cache
108 virtual void ClearBackend() = 0;
110 LinkStatusMap link_status_
;
112 DISALLOW_COPY_AND_ASSIGN(ProgramCache
);
118 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_