xref: /aosp_15_r20/external/deqp/framework/referencerenderer/rrRenderer.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _RRRENDERER_HPP
2 #define _RRRENDERER_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Reference Renderer
5  * -----------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Reference renderer interface.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "rrDefs.hpp"
27 #include "rrShaders.hpp"
28 #include "rrRenderState.hpp"
29 #include "rrPrimitiveTypes.hpp"
30 #include "rrMultisamplePixelBufferAccess.hpp"
31 #include "tcuTexture.hpp"
32 
33 namespace rr
34 {
35 
36 class RenderTarget
37 {
38 public:
39     enum
40     {
41         MAX_COLOR_BUFFERS = 4
42     };
43 
44     RenderTarget(const MultisamplePixelBufferAccess &colorMultisampleBuffer,
45                  const MultisamplePixelBufferAccess &depthMultisampleBuffer   = MultisamplePixelBufferAccess(),
46                  const MultisamplePixelBufferAccess &stencilMultisampleBuffer = MultisamplePixelBufferAccess());
47 
48     int getNumSamples(void) const;
49 
getColorBuffer(int ndx) const50     const MultisamplePixelBufferAccess &getColorBuffer(int ndx) const
51     {
52         DE_ASSERT(de::inRange(ndx, 0, m_numColorBuffers));
53         return m_colorBuffers[ndx];
54     }
getNumColorBuffers(void) const55     int getNumColorBuffers(void) const
56     {
57         return m_numColorBuffers;
58     }
getStencilBuffer(void) const59     const MultisamplePixelBufferAccess &getStencilBuffer(void) const
60     {
61         return m_stencilBuffer;
62     }
getDepthBuffer(void) const63     const MultisamplePixelBufferAccess &getDepthBuffer(void) const
64     {
65         return m_depthBuffer;
66     }
67 
68 private:
69     MultisamplePixelBufferAccess m_colorBuffers[MAX_COLOR_BUFFERS];
70     const int m_numColorBuffers;
71     const MultisamplePixelBufferAccess m_depthBuffer;
72     const MultisamplePixelBufferAccess m_stencilBuffer;
73 } DE_WARN_UNUSED_TYPE;
74 
75 struct Program
76 {
Programrr::Program77     Program(const VertexShader *vertexShader_, const FragmentShader *fragmentShader_,
78             const GeometryShader *geometryShader_ = DE_NULL)
79         : vertexShader(vertexShader_)
80         , fragmentShader(fragmentShader_)
81         , geometryShader(geometryShader_)
82     {
83     }
84 
85     const VertexShader *vertexShader;
86     const FragmentShader *fragmentShader;
87     const GeometryShader *geometryShader;
88 } DE_WARN_UNUSED_TYPE;
89 
90 struct DrawIndices
91 {
92     DrawIndices(const uint32_t *, int baseVertex = 0);
93     DrawIndices(const uint16_t *, int baseVertex = 0);
94     DrawIndices(const uint8_t *, int baseVertex = 0);
95     DrawIndices(const void *ptr, IndexType type, int baseVertex = 0);
96 
97     const void *const indices;
98     const IndexType indexType;
99     const int baseVertex;
100 } DE_WARN_UNUSED_TYPE;
101 
102 class PrimitiveList
103 {
104 public:
105     PrimitiveList(PrimitiveType primitiveType, int numElements,
106                   const int firstElement); // !< primitive list for drawArrays-like call
107     PrimitiveList(PrimitiveType primitiveType, int numElements,
108                   const DrawIndices &indices); // !< primitive list for drawElements-like call
109 
110     size_t getIndex(size_t elementNdx) const;
111     bool isRestartIndex(size_t elementNdx, uint32_t restartIndex) const;
112 
getNumElements(void) const113     inline size_t getNumElements(void) const
114     {
115         return m_numElements;
116     }
getPrimitiveType(void) const117     inline PrimitiveType getPrimitiveType(void) const
118     {
119         return m_primitiveType;
120     }
getIndexType(void) const121     inline IndexType getIndexType(void) const
122     {
123         return m_indexType;
124     }
125 
126 private:
127     const PrimitiveType m_primitiveType;
128     const size_t m_numElements;
129     const void *const
130         m_indices; // !< if indices is NULL, indices is interpreted as [first (== baseVertex) + 0, first + 1, first + 2, ...]
131     const IndexType m_indexType;
132     const int m_baseVertex;
133 };
134 
135 class DrawCommand
136 {
137 public:
DrawCommand(const RenderState & state_,const RenderTarget & renderTarget_,const Program & program_,int numVertexAttribs_,const VertexAttrib * vertexAttribs_,const PrimitiveList & primitives_)138     DrawCommand(const RenderState &state_, const RenderTarget &renderTarget_, const Program &program_,
139                 int numVertexAttribs_, const VertexAttrib *vertexAttribs_, const PrimitiveList &primitives_)
140         : state(state_)
141         , renderTarget(renderTarget_)
142         , program(program_)
143         , numVertexAttribs(numVertexAttribs_)
144         , vertexAttribs(vertexAttribs_)
145         , primitives(primitives_)
146     {
147     }
148 
149     const RenderState &state;
150     const RenderTarget &renderTarget;
151     const Program &program;
152 
153     const int numVertexAttribs;
154     const VertexAttrib *const vertexAttribs;
155 
156     const PrimitiveList &primitives;
157 } DE_WARN_UNUSED_TYPE;
158 
159 class Renderer
160 {
161 public:
162     Renderer(void);
163     ~Renderer(void);
164 
165     void draw(const DrawCommand &command) const;
166     void drawInstanced(const DrawCommand &command, int numInstances) const;
167 } DE_WARN_UNUSED_TYPE;
168 
169 } // namespace rr
170 
171 #endif // _RRRENDERER_HPP
172