1 #ifndef _VKTPIPELINEREFERENCERENDERER_HPP
2 #define _VKTPIPELINEREFERENCERENDERER_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 The Khronos Group Inc.
8 * Copyright (c) 2015 Imagination Technologies Ltd.
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 * \brief Reference renderer.
25 *//*--------------------------------------------------------------------*/
28 #include "vktPipelineVertexUtil.hpp"
29 #include "tcuVector.hpp"
30 #include "tcuVectorType.hpp"
31 #include "tcuTexture.hpp"
32 #include "tcuTextureUtil.hpp"
33 #include "rrRenderState.hpp"
34 #include "rrRenderer.hpp"
43 tcu::Vec4 swizzle (const tcu::Vec4& color, const tcu::UVec4& swizzle);
45 class ColorVertexShader : public rr::VertexShader
48 ColorVertexShader (void) : rr::VertexShader(2, 2)
50 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
51 m_inputs[1].type = rr::GENERICVECTYPE_FLOAT;
53 m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
54 m_outputs[1].type = rr::GENERICVECTYPE_FLOAT;
57 virtual ~ColorVertexShader (void) {}
59 virtual void shadeVertices (const rr::VertexAttrib* inputs,
60 rr::VertexPacket* const* packets,
61 const int numPackets) const
66 for (int packetNdx = 0; packetNdx < numPackets; packetNdx++)
68 rr::VertexPacket* const packet = packets[packetNdx];
70 readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx);
71 readVertexAttrib(color, inputs[1], packet->instanceNdx, packet->vertexNdx);
73 packet->outputs[0] = position;
74 packet->outputs[1] = color;
75 packet->position = position;
80 class TexCoordVertexShader : public rr::VertexShader
83 TexCoordVertexShader (void) : rr::VertexShader(2, 2)
85 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
86 m_inputs[1].type = rr::GENERICVECTYPE_FLOAT;
88 m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
89 m_outputs[1].type = rr::GENERICVECTYPE_FLOAT;
92 virtual ~TexCoordVertexShader (void) {}
94 virtual void shadeVertices (const rr::VertexAttrib* inputs,
95 rr::VertexPacket* const* packets,
96 const int numPackets) const
101 for (int packetNdx = 0; packetNdx < numPackets; packetNdx++)
103 rr::VertexPacket* const packet = packets[packetNdx];
105 readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx);
106 readVertexAttrib(texCoord, inputs[1], packet->instanceNdx, packet->vertexNdx);
108 packet->outputs[0] = position;
109 packet->outputs[1] = texCoord;
110 packet->position = position;
115 class ColorFragmentShader : public rr::FragmentShader
118 const tcu::TextureFormat m_colorFormat;
119 const tcu::TextureFormat m_depthStencilFormat;
122 ColorFragmentShader (const tcu::TextureFormat& colorFormat,
123 const tcu::TextureFormat& depthStencilFormat)
124 : rr::FragmentShader (2, 1)
125 , m_colorFormat (colorFormat)
126 , m_depthStencilFormat (depthStencilFormat)
128 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(m_colorFormat.type);
130 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
131 m_inputs[1].type = rr::GENERICVECTYPE_FLOAT;
132 m_outputs[0].type = (channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)? rr::GENERICVECTYPE_INT32 :
133 (channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)? rr::GENERICVECTYPE_UINT32
134 : rr::GENERICVECTYPE_FLOAT;
137 virtual ~ColorFragmentShader (void) {}
139 virtual void shadeFragments (rr::FragmentPacket* packets,
140 const int numPackets,
141 const rr::FragmentShadingContext& context) const
143 for (int packetNdx = 0; packetNdx < numPackets; packetNdx++)
145 const rr::FragmentPacket& packet = packets[packetNdx];
147 if (m_depthStencilFormat.order == tcu::TextureFormat::D || m_depthStencilFormat.order == tcu::TextureFormat::DS)
149 for (int fragNdx = 0; fragNdx < 4; fragNdx++)
151 const tcu::Vec4 vtxPosition = rr::readVarying<float>(packet, context, 0, fragNdx);
152 rr::writeFragmentDepth(context, packetNdx, fragNdx, 0, vtxPosition.z());
156 for (int fragNdx = 0; fragNdx < 4; fragNdx++)
158 const tcu::Vec4 vtxColor = rr::readVarying<float>(packet, context, 1, fragNdx);
159 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, vtxColor);
165 class CoordinateCaptureFragmentShader : public rr::FragmentShader
168 CoordinateCaptureFragmentShader (void)
169 : rr::FragmentShader(2, 1)
171 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
172 m_inputs[1].type = rr::GENERICVECTYPE_FLOAT;
173 m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
176 virtual ~CoordinateCaptureFragmentShader (void)
180 virtual void shadeFragments (rr::FragmentPacket* packets,
181 const int numPackets,
182 const rr::FragmentShadingContext& context) const
184 for (int packetNdx = 0; packetNdx < numPackets; packetNdx++)
186 const rr::FragmentPacket& packet = packets[packetNdx];
188 for (int fragNdx = 0; fragNdx < 4; fragNdx++)
190 const tcu::Vec4 vtxTexCoord = rr::readVarying<float>(packet, context, 1, fragNdx);
191 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, vtxTexCoord);
200 virtual ~Program (void) { }
202 virtual rr::Program getReferenceProgram (void) const = 0;
205 class CoordinateCaptureProgram : public Program
208 TexCoordVertexShader m_vertexShader;
209 CoordinateCaptureFragmentShader m_fragmentShader;
211 CoordinateCaptureProgram (void)
215 virtual ~CoordinateCaptureProgram (void) { }
217 virtual rr::Program getReferenceProgram (void) const
219 return rr::Program(&m_vertexShader, &m_fragmentShader);
223 class ReferenceRenderer
226 ReferenceRenderer (int surfaceWidth,
229 const tcu::TextureFormat& colorFormat,
230 const tcu::TextureFormat& depthStencilFormat,
231 const rr::Program* const program);
233 virtual ~ReferenceRenderer (void);
235 void colorClear (const tcu::Vec4& color);
237 void draw (const rr::RenderState& renderState,
238 const rr::PrimitiveType primitive,
239 const std::vector<Vertex4RGBA>& vertexBuffer);
241 void draw (const rr::RenderState& renderState,
242 const rr::PrimitiveType primitive,
243 const std::vector<Vertex4Tex4>& vertexBuffer);
245 tcu::PixelBufferAccess getAccess (void);
246 const rr::ViewportState getViewportState (void) const;
249 rr::Renderer m_renderer;
251 const int m_surfaceWidth;
252 const int m_surfaceHeight;
253 const int m_numSamples;
255 const tcu::TextureFormat m_colorFormat;
256 const tcu::TextureFormat m_depthStencilFormat;
258 tcu::TextureLevel m_colorBuffer;
259 tcu::TextureLevel m_resolveColorBuffer;
260 tcu::TextureLevel m_depthStencilBuffer;
262 rr::RenderTarget* m_renderTarget;
263 const rr::Program* m_program;
266 rr::TestFunc mapVkCompareOp (vk::VkCompareOp compareFunc);
267 rr::PrimitiveType mapVkPrimitiveTopology (vk::VkPrimitiveTopology primitiveTopology);
268 rr::BlendFunc mapVkBlendFactor (vk::VkBlendFactor blendFactor);
269 rr::BlendEquation mapVkBlendOp (vk::VkBlendOp blendOp);
270 tcu::BVec4 mapVkColorComponentFlags (vk::VkColorComponentFlags flags);
271 rr::StencilOp mapVkStencilOp (vk::VkStencilOp stencilOp);
276 #endif // _VKTPIPELINEREFERENCERENDERER_HPP