blob: 59f0a335fee79a924a49bedeb7ac28d1af49859f [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -07002 * Copyright (C) 2011 The Android Open Source Project
Jason Sams326e0dd2009-05-22 14:03:28 -07003 *
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_RS_PROGRAM_H
18#define ANDROID_RS_PROGRAM_H
19
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070020#include "rsProgramBase.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070021#include "rsElement.h"
22
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
Jason Sams326e0dd2009-05-22 14:03:28 -070026
Alex Sakhartchouke7ae69f2010-09-14 09:50:43 -070027#define RS_SHADER_INTERNAL "//rs_shader_internal\n"
Alex Sakhartchouk886f11a2010-09-29 09:49:13 -070028#define RS_SHADER_ATTR "ATTRIB_"
29#define RS_SHADER_UNI "UNI_"
Alex Sakhartchouke7ae69f2010-09-14 09:50:43 -070030
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070031class Program : public ProgramBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070032public:
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070033 struct Hal {
34 mutable void *drv;
35
36 struct State {
37 // The difference between Textures and Constants is how they are accessed
38 // Texture lookups go though a sampler which in effect converts normalized
39 // coordinates into type specific. Multiple samples may also be taken
40 // and filtered.
41 //
42 // Constants are strictly accessed by the shader code
43 Allocation **textures;
44 RsTextureTarget *textureTargets;
45 uint32_t texturesCount;
46
47 Sampler **samplers;
48 uint32_t samplersCount;
49
50 Allocation **constants;
51 Type **constantTypes;
52 uint32_t constantsCount;
53
54 Element **inputElements;
55 uint32_t inputElementsCount;
56 };
57 State state;
58 };
59 Hal mHal;
Jason Samsc460e552009-11-25 13:22:07 -080060
Alex Sakhartchouk748eb072012-02-15 16:21:46 -080061 Program(Context *, const char * shaderText, size_t shaderLength,
Ian Rogersf8852d02014-01-29 15:35:17 -080062 const uintptr_t * params, size_t paramLength);
Jason Sams326e0dd2009-05-22 14:03:28 -070063 virtual ~Program();
Jason Samsc7cec1e2011-08-18 18:01:33 -070064 virtual bool freeChildren();
Jason Sams326e0dd2009-05-22 14:03:28 -070065
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -070066 void bindAllocation(Context *, Allocation *, uint32_t slot);
Jason Samsc460e552009-11-25 13:22:07 -080067
Alex Sakhartchouke7ae69f2010-09-14 09:50:43 -070068 bool isUserProgram() const {return !mIsInternal;}
Jason Sams433eca32010-01-06 11:57:52 -080069
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -070070 void bindTexture(Context *, uint32_t slot, Allocation *);
71 void bindSampler(Context *, uint32_t slot, Sampler *);
Jason Sams7dad9c32009-12-17 16:55:08 -080072
Jason Sams326e0dd2009-05-22 14:03:28 -070073protected:
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070074 ObjectBaseRef<Allocation> *mTextures;
75 ObjectBaseRef<Sampler> *mSamplers;
76 ObjectBaseRef<Allocation> *mConstants;
77 ObjectBaseRef<Type> *mConstantTypes;
78 ObjectBaseRef<Element> *mInputElements;
79
Alex Sakhartchouke7ae69f2010-09-14 09:50:43 -070080 bool mIsInternal;
Jason Samsf313dc32013-07-09 14:29:39 -070081 const char *mUserShader;
82 size_t mUserShaderLen;
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -080083 void initMemberVars();
Jason Sams326e0dd2009-05-22 14:03:28 -070084};
85
Rahul Chaudhry7974fc02017-02-09 12:33:28 -080086} // namespace renderscript
87} // namespace android
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070088#endif // ANDROID_RS_PROGRAM_H
Jason Sams326e0dd2009-05-22 14:03:28 -070089
90
91