2 * Copyright © 2014 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * With Nvidia OpenGL drivers, the texelFetch() GLSL shader function
26 * cannot return the correct data in the TextureView if we set the texture
27 * parameter GL_TEXTURE_MAX_LEVEL for the TextureView.bug.
30 * -- Present in : Nvidia GTX 650, driver - 319.32
31 * -- Fixed in : driver 319.59
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_core_version
= 32;
40 config
.supports_gl_compat_version
= 32;
42 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
43 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
45 PIGLIT_GL_TEST_CONFIG_END
50 #define COLOR_RED 0xFF0000FF
51 #define COLOR_GREEN 0x00FF00FF
52 #define COLOR_BLUE 0x0000FFFF
53 #define COLOR_CYAN 0x00FFFFFF
54 #define COLOR_MAGENTA 0xFF00FFFF
55 #define COLOR_YELLOW 0xFFFF00FF
56 #define COLOR_GRAY 0x7F7F7FFF
57 #define CLEAR_COLOR 0x000033FF
58 #define NUM_VERTICES 4
67 static const float vertArray
[] = {
68 1.0f
, -1.0f
, 0.0f
, 1.0f
,
69 1.0f
, 1.0f
, 0.0f
, 1.0f
,
70 -1.0f
, -1.0f
, 0.0f
, 1.0f
,
71 -1.0f
, 1.0f
, 0.0f
, 1.0f
,
73 GLint attrLoc
= -1, samplerLoc
= -1;
74 const GLuint white
= 0xffffffff;
75 const unsigned int colors
[LEVELS
] = {COLOR_RED
, COLOR_GREEN
,
76 COLOR_BLUE
, COLOR_CYAN
,
77 COLOR_CYAN
, COLOR_MAGENTA
};
78 const unsigned int numPixels
= WIDTH
* HEIGHT
;
79 GLuint texData
[WIDTH
* HEIGHT
];
80 GLuint i
, texFbo
, tex
, view
, fbo
, vertexArray
, vertexBuf
, l
;
82 for (i
= 0; i
< numPixels
; ++i
) {
86 /* Create 2D textures */
87 glGenTextures(1, &texFbo
);
88 glActiveTexture(GL_TEXTURE0
);
89 glBindTexture(GL_TEXTURE_2D
, texFbo
);
90 glTexStorage2D(GL_TEXTURE_2D
, 1, GL_RGBA8
, WIDTH
, HEIGHT
);
91 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, 0);
92 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
93 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, WIDTH
, HEIGHT
,
94 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, texData
);
96 glGenTextures(1, &tex
);
97 glBindTexture(GL_TEXTURE_2D
, tex
);
98 glTexStorage2D(GL_TEXTURE_2D
, LEVELS
, GL_RGBA8
, WIDTH
, HEIGHT
);
100 for (l
= 0; l
< LEVELS
; ++l
) {
101 for (i
= 0; i
< numPixels
>> (l
* 2); ++i
) {
102 texData
[i
] = colors
[l
];
105 glPixelStorei(GL_UNPACK_ROW_LENGTH
, WIDTH
>> l
);
106 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
107 glTexSubImage2D(GL_TEXTURE_2D
, l
, 0, 0,
108 WIDTH
>> l
, HEIGHT
>> l
,
109 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
,
113 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, LEVELS
- 1);
116 * Create a texture view that is the (VIEW_LEVEL) mipmap level
117 * of the original texture.
119 glGenTextures(1, &view
);
120 glTextureView(view
, GL_TEXTURE_2D
, tex
, GL_RGBA8
,
121 VIEW_LEVEL
, 1, 0, 1);
122 glBindTexture(GL_TEXTURE_2D
, view
);
123 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_BASE_LEVEL
, 0);
124 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
126 if (!piglit_check_gl_error(GL_NO_ERROR
))
129 /* Setup the sampler */
130 samplerLoc
= glGetUniformLocation(prog
, "s");
131 glUniform1i(samplerLoc
, 0); // GL_TEXTURE0
133 /* Setup vertex attributes. */
134 attrLoc
= glGetAttribLocation(prog
, "Attr0");
135 glGenVertexArrays(1, &vertexArray
);
136 glBindVertexArray(vertexArray
);
137 glGenBuffers(1, &vertexBuf
);
138 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuf
);
139 glBufferData(GL_ARRAY_BUFFER
, sizeof(vertArray
), vertArray
,
141 glEnableVertexAttribArray(attrLoc
);
142 glVertexAttribPointer(attrLoc
, ATTR_SIZE
, GL_FLOAT
, GL_FALSE
,
143 ATTR_SIZE
* sizeof(float), 0);
145 if (!piglit_check_gl_error(GL_NO_ERROR
))
149 glGenFramebuffers(1, &fbo
);
150 glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
151 glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
152 GL_TEXTURE_2D
, texFbo
, 0);
153 if (glCheckFramebufferStatus(GL_FRAMEBUFFER
) !=
154 GL_FRAMEBUFFER_COMPLETE
) {
155 printf("incomplete framebuffer at line %d\n", __LINE__
);
159 glDrawBuffer(GL_COLOR_ATTACHMENT0
);
160 if (glCheckFramebufferStatus(GL_FRAMEBUFFER
) !=
161 GL_FRAMEBUFFER_COMPLETE
) {
162 printf("incomplete framebuffer at line %d\n", __LINE__
);
167 glViewport(0, 0, WIDTH
, HEIGHT
);
168 glClearColor(((CLEAR_COLOR
>> 24) & 0xFF) / 255.0f
,
169 ((CLEAR_COLOR
>> 16) & 0xFF) / 255.0f
,
170 ((CLEAR_COLOR
>> 8) & 0xFF) / 255.0f
,
171 ((CLEAR_COLOR
) & 0xFF) / 255.0f
);
172 glClear(GL_COLOR_BUFFER_BIT
);
173 glDrawArrays(GL_TRIANGLE_STRIP
, 0, NUM_VERTICES
);
176 glReadBuffer(GL_COLOR_ATTACHMENT0
);
177 if (glCheckFramebufferStatus(GL_FRAMEBUFFER
) !=
178 GL_FRAMEBUFFER_COMPLETE
) {
179 printf("incomplete framebuffer at line %d\n", __LINE__
);
183 /* read color buffer */
184 glPixelStorei(GL_PACK_ROW_LENGTH
, WIDTH
);
185 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
186 memset(texData
, 0, sizeof(texData
));
187 glReadPixels(0, 0, WIDTH
, HEIGHT
,
188 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, texData
);
190 if (texData
[0] != colors
[VIEW_LEVEL
]) {
191 printf("At pixel (0,0) expected 0x%x but found 0x%x\n",
192 colors
[VIEW_LEVEL
], texData
[0]);
194 glDeleteTextures(1, &tex
);
195 glDeleteTextures(1, &texFbo
);
196 glDeleteTextures(1, &view
);
197 glDeleteFramebuffers(1, &fbo
);
201 if (!piglit_check_gl_error(GL_NO_ERROR
))
204 glDeleteTextures(1, &tex
);
205 glDeleteTextures(1, &texFbo
);
206 glDeleteTextures(1, &view
);
207 glDeleteFramebuffers(1, &fbo
);
215 bool pass
= test_max_level();
217 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
224 static const char *vsSrc
=
228 " gl_Position = Attr0;"
230 static const char *fsSrc
=
232 "uniform sampler2D s;"
233 "out vec4 fragColor0;"
235 " fragColor0 = texelFetch(s, ivec2(0, 0), 0);"
238 /* Create shaders and the program */
239 prog
= piglit_build_simple_program(vsSrc
, fsSrc
);
240 glBindFragDataLocation(prog
, 0, "fragColor0");
247 piglit_init(int argc
, char **argv
)
249 piglit_require_extension("GL_ARB_texture_storage");
250 piglit_require_extension("GL_ARB_texture_view");