1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2022-2022 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 /*!
21  * \file  esextFragmentShadingRateTests.cpp
22  * \brief Base test group for fragment shading rate tests
23  */ /*-------------------------------------------------------------------*/
24 
25 #include "esextcFragmentShadingRateTests.hpp"
26 #include "esextcFragmentShadingRateAPI.hpp"
27 #include "esextcFragmentShadingRateComplex.hpp"
28 #include "esextcFragmentShadingRateRenderTarget.hpp"
29 #include "glwEnums.hpp"
30 
31 namespace glcts
32 {
33 
34 /// Constructor
35 ///
36 /// @param context       Test context
37 /// @param extParams   extra parameters
FragmentShadingRateTests(glcts::Context & context,const ExtParameters & extParams)38 FragmentShadingRateTests::FragmentShadingRateTests(glcts::Context &context, const ExtParameters &extParams)
39     : TestCaseGroupBase(context, extParams, "fragment_shading_rate", "Fragment Shading Rate")
40 {
41 }
42 
43 /// Initializes test cases for fragment shading rate tests
init(void)44 void FragmentShadingRateTests::init(void)
45 {
46     // Initialize base class
47     TestCaseGroupBase::init();
48 
49     // Case 1 - via basic shading rate function
50     addChild(new FragmentShadingRateAPI(m_context, m_extParams));
51 
52     // Case 2 - fragment shading rate combination cases
53     addChild(new FragmentShadingRateComplex(m_context, m_extParams));
54 
55     // Case 3 - fragment shading rate attachment cases
56     addChild(new FragmentShadingRateRenderTarget(m_context, m_extParams));
57 }
58 
59 namespace fsrutils
60 {
61 
62 /// Tranlate Primitive ID to packed size of shading rate
63 ///
64 /// @param shadingRate shading rate enumeration to pack integer
65 ///
66 /// @return packed shading rate which is combined log of width and height
packShadingRate(glw::GLenum shadingRate)67 uint32_t packShadingRate(glw::GLenum shadingRate)
68 {
69     uint32_t width_shift;  // 0, 1, 2
70     uint32_t height_shift; // 0, 1, 2
71 
72     switch (shadingRate)
73     {
74     case GL_SHADING_RATE_1X1_PIXELS_EXT:
75         width_shift  = 0;
76         height_shift = 0;
77         break;
78     case GL_SHADING_RATE_1X2_PIXELS_EXT:
79         width_shift  = 0;
80         height_shift = 1;
81         break;
82     case GL_SHADING_RATE_1X4_PIXELS_EXT:
83         width_shift  = 0;
84         height_shift = 2;
85         break;
86     case GL_SHADING_RATE_2X1_PIXELS_EXT:
87         width_shift  = 1;
88         height_shift = 0;
89         break;
90     case GL_SHADING_RATE_2X2_PIXELS_EXT:
91         width_shift  = 1;
92         height_shift = 1;
93         break;
94     case GL_SHADING_RATE_2X4_PIXELS_EXT:
95         width_shift  = 1;
96         height_shift = 2;
97         break;
98     case GL_SHADING_RATE_4X1_PIXELS_EXT:
99         width_shift  = 2;
100         height_shift = 0;
101         break;
102     case GL_SHADING_RATE_4X2_PIXELS_EXT:
103         width_shift  = 2;
104         height_shift = 1;
105         break;
106     case GL_SHADING_RATE_4X4_PIXELS_EXT:
107         width_shift  = 2;
108         height_shift = 2;
109         break;
110     default:
111         width_shift  = 0;
112         height_shift = 0;
113         DE_ASSERT(0);
114         break;
115     }
116 
117     const uint32_t packedShadingRate = ((width_shift << 2) | height_shift);
118     return packedShadingRate;
119 }
120 
121 } // namespace fsrutils
122 } // namespace glcts
123