vktPipelineReferenceRenderer.hpp revision c6e8b5a8389a64972259b357407b5e0f4edd5716
1#ifndef _VKTPIPELINEREFERENCERENDERER_HPP 2#define _VKTPIPELINEREFERENCERENDERER_HPP 3/*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2015 The Khronos Group Inc. 8 * Copyright (c) 2015 Imagination Technologies Ltd. 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining a 11 * copy of this software and/or associated documentation files (the 12 * "Materials"), to deal in the Materials without restriction, including 13 * without limitation the rights to use, copy, modify, merge, publish, 14 * distribute, sublicense, and/or sell copies of the Materials, and to 15 * permit persons to whom the Materials are furnished to do so, subject to 16 * the following conditions: 17 * 18 * The above copyright notice(s) and this permission notice shall be included 19 * in all copies or substantial portions of the Materials. 20 * 21 * The Materials are Confidential Information as defined by the 22 * Khronos Membership Agreement until designated non-confidential by Khronos, 23 * at which point this condition clause shall be removed. 24 * 25 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 28 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 29 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 30 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 31 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 32 * 33 *//*! 34 * \file 35 * \brief Reference renderer. 36 *//*--------------------------------------------------------------------*/ 37 38#include "vkDefs.hpp" 39#include "vktPipelineVertexUtil.hpp" 40#include "tcuVector.hpp" 41#include "tcuVectorType.hpp" 42#include "tcuTexture.hpp" 43#include "tcuTextureUtil.hpp" 44#include "rrRenderState.hpp" 45#include "rrRenderer.hpp" 46#include <cstring> 47 48namespace vkt 49{ 50 51namespace pipeline 52{ 53 54class ColorVertexShader : public rr::VertexShader 55{ 56public: 57 ColorVertexShader (void) : rr::VertexShader(2, 2) 58 { 59 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 60 m_inputs[1].type = rr::GENERICVECTYPE_FLOAT; 61 62 m_outputs[0].type = rr::GENERICVECTYPE_FLOAT; 63 m_outputs[1].type = rr::GENERICVECTYPE_FLOAT; 64 } 65 66 virtual ~ColorVertexShader (void) {} 67 68 virtual void shadeVertices (const rr::VertexAttrib* inputs, 69 rr::VertexPacket* const* packets, 70 const int numPackets) const 71 { 72 tcu::Vec4 position; 73 tcu::Vec4 color; 74 75 for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 76 { 77 rr::VertexPacket* const packet = packets[packetNdx]; 78 79 readVertexAttrib(position, inputs[0], packet->instanceNdx, packet->vertexNdx); 80 readVertexAttrib(color, inputs[1], packet->instanceNdx, packet->vertexNdx); 81 82 packet->outputs[0] = position; 83 packet->outputs[1] = color; 84 packet->position = position; 85 } 86 } 87}; 88 89class ColorFragmentShader : public rr::FragmentShader 90{ 91private: 92 const tcu::TextureFormat m_colorFormat; 93 const tcu::TextureFormatInfo m_colorFormatInfo; 94 const tcu::TextureFormat m_depthStencilFormat; 95 96public: 97 ColorFragmentShader (const tcu::TextureFormat& colorFormat, 98 const tcu::TextureFormat& depthStencilFormat) 99 : rr::FragmentShader (2, 1) 100 , m_colorFormat (colorFormat) 101 , m_colorFormatInfo (tcu::getTextureFormatInfo(colorFormat)) 102 , m_depthStencilFormat (depthStencilFormat) 103 { 104 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(m_colorFormat.type); 105 106 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT; 107 m_inputs[1].type = rr::GENERICVECTYPE_FLOAT; 108 m_outputs[0].type = (channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)? rr::GENERICVECTYPE_INT32 : 109 (channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)? rr::GENERICVECTYPE_UINT32 110 : rr::GENERICVECTYPE_FLOAT; 111 } 112 113 virtual ~ColorFragmentShader (void) {} 114 115 virtual void shadeFragments (rr::FragmentPacket* packets, 116 const int numPackets, 117 const rr::FragmentShadingContext& context) const 118 { 119 for (int packetNdx = 0; packetNdx < numPackets; packetNdx++) 120 { 121 const rr::FragmentPacket& packet = packets[packetNdx]; 122 123 if (m_depthStencilFormat.order == tcu::TextureFormat::D || m_depthStencilFormat.order == tcu::TextureFormat::DS) 124 { 125 for (int fragNdx = 0; fragNdx < 4; fragNdx++) 126 { 127 const tcu::Vec4 vtxPosition = rr::readVarying<float>(packet, context, 0, fragNdx); 128 rr::writeFragmentDepth(context, packetNdx, fragNdx, 0, vtxPosition.z()); 129 } 130 } 131 132 for (int fragNdx = 0; fragNdx < 4; fragNdx++) 133 { 134 const tcu::Vec4 vtxColor = rr::readVarying<float>(packet, context, 1, fragNdx); 135 136 rr::writeFragmentOutput(context, 137 packetNdx, 138 fragNdx, 139 0, 140 (vtxColor - m_colorFormatInfo.lookupBias) / m_colorFormatInfo.lookupScale); 141 } 142 } 143 } 144}; 145 146class ReferenceRenderer 147{ 148public: 149 ReferenceRenderer (int surfaceWidth, 150 int surfaceHeight, 151 int numSamples, 152 const tcu::TextureFormat& colorFormat, 153 const tcu::TextureFormat& depthStencilFormat, 154 const rr::Program* const program); 155 156 virtual ~ReferenceRenderer (void); 157 158 void draw (const rr::RenderState& renderState, 159 const rr::PrimitiveType primitive, 160 const std::vector<Vertex4RGBA>& vertexBuffer); 161 tcu::PixelBufferAccess getAccess (void); 162 const rr::ViewportState getViewportState (void) const; 163 164private: 165 rr::Renderer m_renderer; 166 167 const int m_surfaceWidth; 168 const int m_surfaceHeight; 169 const int m_numSamples; 170 171 const tcu::TextureFormat m_colorFormat; 172 const tcu::TextureFormat m_depthStencilFormat; 173 174 tcu::TextureLevel m_colorBuffer; 175 tcu::TextureLevel m_resolveColorBuffer; 176 tcu::TextureLevel m_depthStencilBuffer; 177 178 rr::RenderTarget* m_renderTarget; 179 const rr::Program* m_program; 180}; 181 182rr::TestFunc mapVkCompareOp (vk::VkCompareOp compareFunc); 183rr::PrimitiveType mapVkPrimitiveTopology (vk::VkPrimitiveTopology primitiveTopology); 184 185} // pipeline 186} // vkt 187 188#endif // _VKTPIPELINEREFERENCERENDERER_HPP 189 190