blob: 6b49e5f84aab519ead080a9531c7b486c7e71fbe [file] [log] [blame]
Jason Samsbb51c402009-11-25 13:22:07 -08001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_SHADER_CACHE_H
18#define ANDROID_SHADER_CACHE_H
19
20
21#include "rsObjectBase.h"
22#include "rsVertexArray.h"
23
24// ---------------------------------------------------------------------------
25namespace android {
26namespace renderscript {
27
28
29// An element is a group of Components that occupies one cell in a structure.
30class ShaderCache
31{
32public:
33 ShaderCache();
34 virtual ~ShaderCache();
35
Jason Sams5dad8b42009-12-15 19:10:11 -080036 bool lookup(Context *rsc, ProgramVertex *, ProgramFragment *);
Jason Samsbb51c402009-11-25 13:22:07 -080037
38 void cleanupVertex(uint32_t id);
39 void cleanupFragment(uint32_t id);
40
41 void cleanupAll();
42
Alex Sakhartchouk4378f112010-09-29 09:49:13 -070043 int32_t vtxAttribSlot(const String8 &attrName) const;
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -080044 int32_t vtxUniformSlot(uint32_t a) const {return mCurrent->vtxUniforms[a].slot;}
45 uint32_t vtxUniformSize(uint32_t a) const {return mCurrent->vtxUniforms[a].arraySize;}
46 int32_t fragUniformSlot(uint32_t a) const {return mCurrent->fragUniforms[a].slot;}
47 uint32_t fragUniformSize(uint32_t a) const {return mCurrent->fragUniforms[a].arraySize;}
Jason Samsbb51c402009-11-25 13:22:07 -080048
49protected:
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -080050 struct UniformQueryData {
51 char *name;
52 uint32_t nameLength;
53 int32_t writtenLength;
54 int32_t arraySize;
55 uint32_t type;
56 UniformQueryData(uint32_t maxName) {
57 name = NULL;
58 nameLength = maxName;
59 if(nameLength > 0 ) {
60 name = new char[nameLength];
61 }
62 }
63 ~UniformQueryData() {
64 if(name != NULL) {
65 delete[] name;
66 name = NULL;
67 }
68 }
69 };
70 struct UniformData {
71 int32_t slot;
72 uint32_t arraySize;
73 };
74 struct AttrData {
75 int32_t slot;
76 const char* name;
77 };
78 struct ProgramEntry {
79 ProgramEntry(uint32_t numVtxAttr, uint32_t numVtxUnis,
80 uint32_t numFragUnis) : vtx(0), frag(0), program(0), vtxAttrCount(0),
81 vtxAttrs(0), vtxUniforms(0), fragUniforms(0) {
82 vtxAttrCount = numVtxAttr;
83 if(numVtxAttr) {
84 vtxAttrs = new AttrData[numVtxAttr];
85 }
86 if(numVtxUnis) {
87 vtxUniforms = new UniformData[numVtxUnis];
88 }
89 if(numFragUnis) {
90 fragUniforms = new UniformData[numFragUnis];
91 }
92 }
93 ~ProgramEntry() {
94 if(vtxAttrs) {
95 delete[] vtxAttrs;
96 vtxAttrs = NULL;
97 }
98 if(vtxUniforms) {
99 delete[] vtxUniforms;
100 vtxUniforms = NULL;
101 }
102 if(fragUniforms) {
103 delete[] fragUniforms;
104 fragUniforms = NULL;
105 }
106 }
Jason Samsbb51c402009-11-25 13:22:07 -0800107 uint32_t vtx;
108 uint32_t frag;
109 uint32_t program;
Alex Sakhartchouk4378f112010-09-29 09:49:13 -0700110 uint32_t vtxAttrCount;
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800111 AttrData *vtxAttrs;
112 UniformData *vtxUniforms;
113 UniformData *fragUniforms;
Jason Samsbb51c402009-11-25 13:22:07 -0800114
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800115 };
116 Vector<ProgramEntry*> mEntries;
117 ProgramEntry *mCurrent;
Jason Samsbb51c402009-11-25 13:22:07 -0800118
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -0800119 bool hasArrayUniforms(ProgramVertex *vtx, ProgramFragment *frag);
120 void populateUniformData(Program *prog, uint32_t linkedID, UniformData *data);
121 void updateUniformArrayData(Context *rsc, Program *prog, uint32_t linkedID,
122 UniformData *data, const char* logTag,
123 UniformQueryData **uniformList, uint32_t uniListSize);
Jason Samsbb51c402009-11-25 13:22:07 -0800124};
125
126
127
128}
129}
130#endif //ANDROID_SHADER_CACHE_H
131
132
133
134