Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 1822643002: [Command buffer] Enable primitive restart for WebGL 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 6218 matching lines...) Expand 10 before | Expand all | Expand 10 after
6229 framebuffer->AttachRenderbuffer(attachment, renderbuffer); 6229 framebuffer->AttachRenderbuffer(attachment, renderbuffer);
6230 } 6230 }
6231 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { 6231 if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) {
6232 framebuffer_state_.clear_state_dirty = true; 6232 framebuffer_state_.clear_state_dirty = true;
6233 } 6233 }
6234 OnFboChanged(); 6234 OnFboChanged();
6235 } 6235 }
6236 6236
6237 void GLES2DecoderImpl::DoDisable(GLenum cap) { 6237 void GLES2DecoderImpl::DoDisable(GLenum cap) {
6238 if (SetCapabilityState(cap, false)) { 6238 if (SetCapabilityState(cap, false)) {
6239 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX &&
6240 feature_info_->feature_flags().emulate_primitive_restart_fixed_index) {
6241 // Enable and Disable PRIMITIVE_RESTART only before and after
6242 // DrawElements* for old desktop GL.
6243 return;
6244 }
6239 glDisable(cap); 6245 glDisable(cap);
6240 } 6246 }
6241 } 6247 }
6242 6248
6243 void GLES2DecoderImpl::DoEnable(GLenum cap) { 6249 void GLES2DecoderImpl::DoEnable(GLenum cap) {
6244 if (SetCapabilityState(cap, true)) { 6250 if (SetCapabilityState(cap, true)) {
6251 if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX &&
6252 feature_info_->feature_flags().emulate_primitive_restart_fixed_index) {
6253 // Enable and Disable PRIMITIVE_RESTART only before and after
6254 // DrawElements* for old desktop GL.
6255 return;
6256 }
6245 glEnable(cap); 6257 glEnable(cap);
6246 } 6258 }
6247 } 6259 }
6248 6260
6249 void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { 6261 void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) {
6250 state_.z_near = std::min(1.0f, std::max(0.0f, znear)); 6262 state_.z_near = std::min(1.0f, std::max(0.0f, znear));
6251 state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); 6263 state_.z_far = std::min(1.0f, std::max(0.0f, zfar));
6252 glDepthRange(znear, zfar); 6264 glDepthRange(znear, zfar);
6253 } 6265 }
6254 6266
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after
8258 // it in each draw call, and attrib 0 generic data queries use cached 8270 // it in each draw call, and attrib 0 generic data queries use cached
8259 // values instead of passing down to the underlying driver. 8271 // values instead of passing down to the underlying driver.
8260 RestoreStateForAttrib(0, false); 8272 RestoreStateForAttrib(0, false);
8261 } 8273 }
8262 } 8274 }
8263 return error::kNoError; 8275 return error::kNoError;
8264 } 8276 }
8265 8277
8266 error::Error GLES2DecoderImpl::HandleDrawArrays(uint32_t immediate_data_size, 8278 error::Error GLES2DecoderImpl::HandleDrawArrays(uint32_t immediate_data_size,
8267 const void* cmd_data) { 8279 const void* cmd_data) {
8268 // TODO(zmo): crbug.com/481184
8269 // On Desktop GL with versions lower than 4.3, we need to emulate
8270 // GL_PRIMITIVE_RESTART_FIXED_INDEX using glPrimitiveRestartIndex().
8271 const cmds::DrawArrays& c = *static_cast<const cmds::DrawArrays*>(cmd_data); 8280 const cmds::DrawArrays& c = *static_cast<const cmds::DrawArrays*>(cmd_data);
8272 return DoDrawArrays("glDrawArrays", 8281 return DoDrawArrays("glDrawArrays",
8273 false, 8282 false,
8274 static_cast<GLenum>(c.mode), 8283 static_cast<GLenum>(c.mode),
8275 static_cast<GLint>(c.first), 8284 static_cast<GLint>(c.first),
8276 static_cast<GLsizei>(c.count), 8285 static_cast<GLsizei>(c.count),
8277 1); 8286 1);
8278 } 8287 }
8279 8288
8280 error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE( 8289 error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
8336 8345
8337 if (count == 0 || primcount == 0) { 8346 if (count == 0 || primcount == 0) {
8338 return error::kNoError; 8347 return error::kNoError;
8339 } 8348 }
8340 8349
8341 GLuint max_vertex_accessed; 8350 GLuint max_vertex_accessed;
8342 Buffer* element_array_buffer = 8351 Buffer* element_array_buffer =
8343 state_.vertex_attrib_manager->element_array_buffer(); 8352 state_.vertex_attrib_manager->element_array_buffer();
8344 8353
8345 if (!element_array_buffer->GetMaxValueForRange( 8354 if (!element_array_buffer->GetMaxValueForRange(
8346 offset, count, type, &max_vertex_accessed)) { 8355 offset, count, type,
8356 state_.enable_flags.primitive_restart_fixed_index,
8357 &max_vertex_accessed)) {
8347 LOCAL_SET_GL_ERROR( 8358 LOCAL_SET_GL_ERROR(
8348 GL_INVALID_OPERATION, function_name, "range out of bounds for buffer"); 8359 GL_INVALID_OPERATION, function_name, "range out of bounds for buffer");
8349 return error::kNoError; 8360 return error::kNoError;
8350 } 8361 }
8351 8362
8352 if (IsDrawValid(function_name, max_vertex_accessed, instanced, primcount)) { 8363 if (IsDrawValid(function_name, max_vertex_accessed, instanced, primcount)) {
8353 if (!ClearUnclearedTextures()) { 8364 if (!ClearUnclearedTextures()) {
8354 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); 8365 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory");
8355 return error::kNoError; 8366 return error::kNoError;
8356 } 8367 }
(...skipping 11 matching lines...) Expand all
8368 // TODO(gman): Refactor to hide these details in BufferManager or 8379 // TODO(gman): Refactor to hide these details in BufferManager or
8369 // VertexAttribManager. 8380 // VertexAttribManager.
8370 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); 8381 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset);
8371 bool used_client_side_array = false; 8382 bool used_client_side_array = false;
8372 if (element_array_buffer->IsClientSideArray()) { 8383 if (element_array_buffer->IsClientSideArray()) {
8373 used_client_side_array = true; 8384 used_client_side_array = true;
8374 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 8385 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
8375 indices = element_array_buffer->GetRange(offset, 0); 8386 indices = element_array_buffer->GetRange(offset, 0);
8376 } 8387 }
8377 8388
8389 if (state_.enable_flags.primitive_restart_fixed_index &&
8390 feature_info_->feature_flags().emulate_primitive_restart_fixed_index) {
Zhenyao Mo 2016/03/25 17:24:29 nit: this is beyond 80 characters.
yunchao 2016/03/30 08:25:22 Done.
8391 glEnable(GL_PRIMITIVE_RESTART);
8392 buffer_manager()->SetPrimitiveRestartFixedIndexIfNecessary(type);
8393 }
8394
8378 if (!instanced) { 8395 if (!instanced) {
8379 glDrawElements(mode, count, type, indices); 8396 glDrawElements(mode, count, type, indices);
8380 } else { 8397 } else {
8381 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); 8398 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount);
8382 } 8399 }
8383 8400
8401 if (state_.enable_flags.primitive_restart_fixed_index &&
8402 feature_info_->feature_flags().emulate_primitive_restart_fixed_index) {
Zhenyao Mo 2016/03/25 17:24:29 nit: this is beyond 80 characters.
yunchao 2016/03/30 08:25:22 Done.
8403 glDisable(GL_PRIMITIVE_RESTART);
8404 }
8405
8384 if (used_client_side_array) { 8406 if (used_client_side_array) {
8385 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 8407 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
8386 element_array_buffer->service_id()); 8408 element_array_buffer->service_id());
8387 } 8409 }
8388 8410
8389 if (textures_set) { 8411 if (textures_set) {
8390 RestoreStateForTextures(); 8412 RestoreStateForTextures();
8391 } 8413 }
8392 if (simulated_fixed_attribs) { 8414 if (simulated_fixed_attribs) {
8393 RestoreStateForSimulatedFixedAttribs(); 8415 RestoreStateForSimulatedFixedAttribs();
8394 } 8416 }
8395 } 8417 }
8396 if (simulated_attrib_0) { 8418 if (simulated_attrib_0) {
8397 // We don't have to restore attrib 0 generic data at the end of this 8419 // We don't have to restore attrib 0 generic data at the end of this
8398 // function even if it is simulated. This is because we will simulate 8420 // function even if it is simulated. This is because we will simulate
8399 // it in each draw call, and attrib 0 generic data queries use cached 8421 // it in each draw call, and attrib 0 generic data queries use cached
8400 // values instead of passing down to the underlying driver. 8422 // values instead of passing down to the underlying driver.
8401 RestoreStateForAttrib(0, false); 8423 RestoreStateForAttrib(0, false);
8402 } 8424 }
8403 } 8425 }
8404 return error::kNoError; 8426 return error::kNoError;
8405 } 8427 }
8406 8428
8407 error::Error GLES2DecoderImpl::HandleDrawElements(uint32_t immediate_data_size, 8429 error::Error GLES2DecoderImpl::HandleDrawElements(uint32_t immediate_data_size,
8408 const void* cmd_data) { 8430 const void* cmd_data) {
8409 // TODO(zmo): crbug.com/481184
8410 // On Desktop GL with versions lower than 4.3, we need to emulate
8411 // GL_PRIMITIVE_RESTART_FIXED_INDEX using glPrimitiveRestartIndex().
8412 const gles2::cmds::DrawElements& c = 8431 const gles2::cmds::DrawElements& c =
8413 *static_cast<const gles2::cmds::DrawElements*>(cmd_data); 8432 *static_cast<const gles2::cmds::DrawElements*>(cmd_data);
8414 return DoDrawElements("glDrawElements", false, static_cast<GLenum>(c.mode), 8433 return DoDrawElements("glDrawElements", false, static_cast<GLenum>(c.mode),
8415 static_cast<GLsizei>(c.count), 8434 static_cast<GLsizei>(c.count),
8416 static_cast<GLenum>(c.type), 8435 static_cast<GLenum>(c.type),
8417 static_cast<int32_t>(c.index_offset), 1); 8436 static_cast<int32_t>(c.index_offset), 1);
8418 } 8437 }
8419 8438
8420 error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE( 8439 error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE(
8421 uint32_t immediate_data_size, 8440 uint32_t immediate_data_size,
(...skipping 11 matching lines...) Expand all
8433 8452
8434 GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( 8453 GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM(
8435 GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { 8454 GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) {
8436 GLuint max_vertex_accessed = 0; 8455 GLuint max_vertex_accessed = 0;
8437 Buffer* buffer = GetBuffer(buffer_id); 8456 Buffer* buffer = GetBuffer(buffer_id);
8438 if (!buffer) { 8457 if (!buffer) {
8439 // TODO(gman): Should this be a GL error or a command buffer error? 8458 // TODO(gman): Should this be a GL error or a command buffer error?
8440 LOCAL_SET_GL_ERROR( 8459 LOCAL_SET_GL_ERROR(
8441 GL_INVALID_VALUE, "GetMaxValueInBufferCHROMIUM", "unknown buffer"); 8460 GL_INVALID_VALUE, "GetMaxValueInBufferCHROMIUM", "unknown buffer");
8442 } else { 8461 } else {
8462 // The max value is used here to emulate client-side vertex
8463 // arrays, by uploading enough vertices into buffer objects to
8464 // cover the DrawElements call. Baking the primitive restart bit
8465 // into this result isn't strictly correct in all cases; the
8466 // client side code should pass down the bit and decide how to use
8467 // the result. However, the only caller makes the draw call
8468 // immediately afterward, so the state won't change between this
8469 // query and the draw call.
8443 if (!buffer->GetMaxValueForRange( 8470 if (!buffer->GetMaxValueForRange(
8444 offset, count, type, &max_vertex_accessed)) { 8471 offset, count, type,
8472 state_.enable_flags.primitive_restart_fixed_index,
8473 &max_vertex_accessed)) {
8445 // TODO(gman): Should this be a GL error or a command buffer error? 8474 // TODO(gman): Should this be a GL error or a command buffer error?
8446 LOCAL_SET_GL_ERROR( 8475 LOCAL_SET_GL_ERROR(
8447 GL_INVALID_OPERATION, 8476 GL_INVALID_OPERATION,
8448 "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer"); 8477 "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer");
8449 } 8478 }
8450 } 8479 }
8451 return max_vertex_accessed; 8480 return max_vertex_accessed;
8452 } 8481 }
8453 8482
8454 void GLES2DecoderImpl::DoShaderSource( 8483 void GLES2DecoderImpl::DoShaderSource(
(...skipping 7878 matching lines...) Expand 10 before | Expand all | Expand 10 after
16333 } 16362 }
16334 16363
16335 // Include the auto-generated part of this file. We split this because it means 16364 // Include the auto-generated part of this file. We split this because it means
16336 // we can easily edit the non-auto generated parts right here in this file 16365 // we can easily edit the non-auto generated parts right here in this file
16337 // instead of having to edit some template or the code generator. 16366 // instead of having to edit some template or the code generator.
16338 #include "base/macros.h" 16367 #include "base/macros.h"
16339 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 16368 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
16340 16369
16341 } // namespace gles2 16370 } // namespace gles2
16342 } // namespace gpu 16371 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698