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

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

Issue 2471533003: Minor improvement in uniform block backing buffer validation. (Closed)
Patch Set: Fix Created 4 years, 1 month 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
« no previous file with comments | « gpu/command_buffer/service/buffer_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8681 matching lines...) Expand 10 before | Expand all | Expand 10 after
8692 if (!framebuffer->ValidateAndAdjustDrawBuffers( 8692 if (!framebuffer->ValidateAndAdjustDrawBuffers(
8693 fragment_output_type_mask, fragment_output_written_mask)) { 8693 fragment_output_type_mask, fragment_output_written_mask)) {
8694 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, 8694 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
8695 "buffer format and fragment output variable type incompatible"); 8695 "buffer format and fragment output variable type incompatible");
8696 return false; 8696 return false;
8697 } 8697 }
8698 return true; 8698 return true;
8699 } 8699 }
8700 8700
8701 bool GLES2DecoderImpl::ValidateUniformBlockBackings(const char* func_name) { 8701 bool GLES2DecoderImpl::ValidateUniformBlockBackings(const char* func_name) {
8702 if (feature_info_->IsWebGL1OrES2Context()) { 8702 DCHECK(feature_info_->IsWebGL2OrES3Context());
8703 // Uniform blocks do not exist in ES2 contexts. 8703 DCHECK(state_.current_program.get());
8704 int32_t max_index = -1;
8705 for (auto info : state_.current_program->uniform_block_size_info()) {
8706 int32_t index = static_cast<int32_t>(info.binding);
8707 if (index > max_index)
8708 max_index = index;
8709 }
8710 if (max_index < 0)
8704 return true; 8711 return true;
8712 std::vector<GLsizeiptr> uniform_block_sizes(max_index + 1);
8713 for (int32_t ii = 0; ii <= max_index; ++ii)
8714 uniform_block_sizes[ii] = 0;
8715 for (auto info : state_.current_program->uniform_block_size_info()) {
8716 uint32_t index = info.binding;
8717 uniform_block_sizes[index] = static_cast<GLsizeiptr>(info.data_size);
Zhenyao Mo 2016/11/02 18:50:04 This is the only change from previous patchset. E
8705 } 8718 }
8706 DCHECK(state_.current_program.get()); 8719 return buffer_manager()->RequestBuffersAccess(
8707 for (auto info : state_.current_program->uniform_block_size_info()) { 8720 state_.GetErrorState(), state_.indexed_uniform_buffer_bindings.get(),
8708 uint32_t buffer_size = static_cast<uint32_t>( 8721 uniform_block_sizes, 1, func_name, "uniform buffers");
8709 state_.indexed_uniform_buffer_bindings->GetEffectiveBufferSize(
8710 info.binding));
8711 if (info.data_size > buffer_size) {
8712 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
8713 "uniform blocks are not backed by a buffer with sufficient data");
8714 return false;
8715 }
8716 }
8717 return true;
8718 } 8722 }
8719 8723
8720 bool GLES2DecoderImpl::CheckUniformForApiType( 8724 bool GLES2DecoderImpl::CheckUniformForApiType(
8721 const Program::UniformInfo* info, 8725 const Program::UniformInfo* info,
8722 const char* function_name, 8726 const char* function_name,
8723 Program::UniformApiType api_type) { 8727 Program::UniformApiType api_type) {
8724 DCHECK(info); 8728 DCHECK(info);
8725 if ((api_type & info->accepts_api_type) == 0) { 8729 if ((api_type & info->accepts_api_type) == 0) {
8726 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, 8730 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
8727 "wrong uniform function for type"); 8731 "wrong uniform function for type");
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after
9818 if (!buffer_manager()->RequestBuffersAccess( 9822 if (!buffer_manager()->RequestBuffersAccess(
9819 state_.GetErrorState(), 9823 state_.GetErrorState(),
9820 state_.bound_transform_feedback.get(), 9824 state_.bound_transform_feedback.get(),
9821 state_.current_program->GetTransformFeedbackVaryingSizes(), 9825 state_.current_program->GetTransformFeedbackVaryingSizes(),
9822 count, 9826 count,
9823 function_name, 9827 function_name,
9824 "transformfeedback buffers")) { 9828 "transformfeedback buffers")) {
9825 return error::kNoError; 9829 return error::kNoError;
9826 } 9830 }
9827 } 9831 }
9832
9833 if (!ValidateUniformBlockBackings(function_name)) {
9834 return error::kNoError;
9835 }
9828 } 9836 }
9829 9837
9830 if (count == 0 || primcount == 0) { 9838 if (count == 0 || primcount == 0) {
9831 LOCAL_RENDER_WARNING("Render count or primcount is 0."); 9839 LOCAL_RENDER_WARNING("Render count or primcount is 0.");
9832 return error::kNoError; 9840 return error::kNoError;
9833 } 9841 }
9834 9842
9835 base::CheckedNumeric<GLuint> checked_max_vertex = first; 9843 base::CheckedNumeric<GLuint> checked_max_vertex = first;
9836 checked_max_vertex += count - 1; 9844 checked_max_vertex += count - 1;
9837 // first and count-1 are both a non-negative int, so their sum fits an 9845 // first and count-1 are both a non-negative int, so their sum fits an
(...skipping 16 matching lines...) Expand all
9854 } 9862 }
9855 bool simulated_fixed_attribs = false; 9863 bool simulated_fixed_attribs = false;
9856 if (SimulateFixedAttribs( 9864 if (SimulateFixedAttribs(
9857 function_name, max_vertex_accessed, &simulated_fixed_attribs, 9865 function_name, max_vertex_accessed, &simulated_fixed_attribs,
9858 primcount)) { 9866 primcount)) {
9859 bool textures_set = !PrepareTexturesForRender(); 9867 bool textures_set = !PrepareTexturesForRender();
9860 ApplyDirtyState(); 9868 ApplyDirtyState();
9861 if (!ValidateAndAdjustDrawBuffers(function_name)) { 9869 if (!ValidateAndAdjustDrawBuffers(function_name)) {
9862 return error::kNoError; 9870 return error::kNoError;
9863 } 9871 }
9864 if (!ValidateUniformBlockBackings(function_name)) {
9865 return error::kNoError;
9866 }
9867 if (!instanced) { 9872 if (!instanced) {
9868 glDrawArrays(mode, first, count); 9873 glDrawArrays(mode, first, count);
9869 } else { 9874 } else {
9870 glDrawArraysInstancedANGLE(mode, first, count, primcount); 9875 glDrawArraysInstancedANGLE(mode, first, count, primcount);
9871 } 9876 }
9872 if (textures_set) { 9877 if (textures_set) {
9873 RestoreStateForTextures(); 9878 RestoreStateForTextures();
9874 } 9879 }
9875 if (simulated_fixed_attribs) { 9880 if (simulated_fixed_attribs) {
9876 RestoreStateForSimulatedFixedAttribs(); 9881 RestoreStateForSimulatedFixedAttribs();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
9958 } 9963 }
9959 9964
9960 if (state_.bound_transform_feedback.get() && 9965 if (state_.bound_transform_feedback.get() &&
9961 state_.bound_transform_feedback->active() && 9966 state_.bound_transform_feedback->active() &&
9962 !state_.bound_transform_feedback->paused()) { 9967 !state_.bound_transform_feedback->paused()) {
9963 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, 9968 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
9964 "transformfeedback is active and not paused"); 9969 "transformfeedback is active and not paused");
9965 return error::kNoError; 9970 return error::kNoError;
9966 } 9971 }
9967 9972
9968 if (count == 0 || primcount == 0) {
9969 return error::kNoError;
9970 }
9971
9972 if (feature_info_->IsWebGL2OrES3Context()) { 9973 if (feature_info_->IsWebGL2OrES3Context()) {
9973 if (!AttribsTypeMatch()) { 9974 if (!AttribsTypeMatch()) {
9974 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, 9975 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
9975 "vertexAttrib function must match shader attrib type"); 9976 "vertexAttrib function must match shader attrib type");
9976 return error::kNoError; 9977 return error::kNoError;
9977 } 9978 }
9979 if (!ValidateUniformBlockBackings(function_name)) {
9980 return error::kNoError;
9981 }
9982 }
9983
9984 if (count == 0 || primcount == 0) {
9985 return error::kNoError;
9978 } 9986 }
9979 9987
9980 GLuint max_vertex_accessed; 9988 GLuint max_vertex_accessed;
9981 if (!element_array_buffer->GetMaxValueForRange( 9989 if (!element_array_buffer->GetMaxValueForRange(
9982 offset, count, type, 9990 offset, count, type,
9983 state_.enable_flags.primitive_restart_fixed_index, 9991 state_.enable_flags.primitive_restart_fixed_index,
9984 &max_vertex_accessed)) { 9992 &max_vertex_accessed)) {
9985 LOCAL_SET_GL_ERROR( 9993 LOCAL_SET_GL_ERROR(
9986 GL_INVALID_OPERATION, function_name, "range out of bounds for buffer"); 9994 GL_INVALID_OPERATION, function_name, "range out of bounds for buffer");
9987 return error::kNoError; 9995 return error::kNoError;
(...skipping 20 matching lines...) Expand all
10008 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); 10016 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset);
10009 bool used_client_side_array = false; 10017 bool used_client_side_array = false;
10010 if (element_array_buffer->IsClientSideArray()) { 10018 if (element_array_buffer->IsClientSideArray()) {
10011 used_client_side_array = true; 10019 used_client_side_array = true;
10012 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 10020 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
10013 indices = element_array_buffer->GetRange(offset, 0); 10021 indices = element_array_buffer->GetRange(offset, 0);
10014 } 10022 }
10015 if (!ValidateAndAdjustDrawBuffers(function_name)) { 10023 if (!ValidateAndAdjustDrawBuffers(function_name)) {
10016 return error::kNoError; 10024 return error::kNoError;
10017 } 10025 }
10018 if (!ValidateUniformBlockBackings(function_name)) {
10019 return error::kNoError;
10020 }
10021 if (state_.enable_flags.primitive_restart_fixed_index && 10026 if (state_.enable_flags.primitive_restart_fixed_index &&
10022 feature_info_->feature_flags(). 10027 feature_info_->feature_flags().
10023 emulate_primitive_restart_fixed_index) { 10028 emulate_primitive_restart_fixed_index) {
10024 glEnable(GL_PRIMITIVE_RESTART); 10029 glEnable(GL_PRIMITIVE_RESTART);
10025 buffer_manager()->SetPrimitiveRestartFixedIndexIfNecessary(type); 10030 buffer_manager()->SetPrimitiveRestartFixedIndexIfNecessary(type);
10026 } 10031 }
10027 if (!instanced) { 10032 if (!instanced) {
10028 glDrawElements(mode, count, type, indices); 10033 glDrawElements(mode, count, type, indices);
10029 } else { 10034 } else {
10030 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); 10035 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount);
(...skipping 8752 matching lines...) Expand 10 before | Expand all | Expand 10 after
18783 } 18788 }
18784 18789
18785 // Include the auto-generated part of this file. We split this because it means 18790 // Include the auto-generated part of this file. We split this because it means
18786 // we can easily edit the non-auto generated parts right here in this file 18791 // we can easily edit the non-auto generated parts right here in this file
18787 // instead of having to edit some template or the code generator. 18792 // instead of having to edit some template or the code generator.
18788 #include "base/macros.h" 18793 #include "base/macros.h"
18789 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 18794 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
18790 18795
18791 } // namespace gles2 18796 } // namespace gles2
18792 } // namespace gpu 18797 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/buffer_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698