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

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

Issue 1949303003: Improve indexed gl state related GL commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tex
Patch Set: fix a DCHECK failure Created 4 years, 7 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/indexed_buffer_binding_host.h" 5 #include "gpu/command_buffer/service/indexed_buffer_binding_host.h"
6 6
7 #include "gpu/command_buffer/service/buffer_manager.h" 7 #include "gpu/command_buffer/service/buffer_manager.h"
8 8
9 namespace gpu { 9 namespace gpu {
10 namespace gles2 { 10 namespace gles2 {
(...skipping 10 matching lines...) Expand all
21 : type(other.type), 21 : type(other.type),
22 buffer(other.buffer.get()), 22 buffer(other.buffer.get()),
23 offset(other.offset), 23 offset(other.offset),
24 size(other.size), 24 size(other.size),
25 effective_full_buffer_size(other.effective_full_buffer_size) { 25 effective_full_buffer_size(other.effective_full_buffer_size) {
26 } 26 }
27 27
28 IndexedBufferBindingHost::IndexedBufferBinding::~IndexedBufferBinding() { 28 IndexedBufferBindingHost::IndexedBufferBinding::~IndexedBufferBinding() {
29 } 29 }
30 30
31 bool IndexedBufferBindingHost::IndexedBufferBinding::operator==(
32 const IndexedBufferBindingHost::IndexedBufferBinding& other) const {
33 if (type == kBindBufferNone && other.type == kBindBufferNone) {
34 // This should be the most common case so an early out.
35 return true;
36 }
37 return (type == other.type &&
38 buffer.get() == other.buffer.get() &&
39 offset == other.offset &&
40 size == other.size &&
41 effective_full_buffer_size == other.effective_full_buffer_size);
42 }
43
31 void IndexedBufferBindingHost::IndexedBufferBinding::SetBindBufferBase( 44 void IndexedBufferBindingHost::IndexedBufferBinding::SetBindBufferBase(
32 Buffer* _buffer) { 45 Buffer* _buffer) {
33 if (!_buffer) { 46 if (!_buffer) {
34 Reset(); 47 Reset();
35 return; 48 return;
36 } 49 }
37 type = kBindBufferBase; 50 type = kBindBufferBase;
38 buffer = _buffer; 51 buffer = _buffer;
39 offset = 0; 52 offset = 0;
40 size = 0; 53 size = 0;
(...skipping 17 matching lines...) Expand all
58 type = kBindBufferNone; 71 type = kBindBufferNone;
59 buffer = nullptr; 72 buffer = nullptr;
60 offset = 0; 73 offset = 0;
61 size = 0; 74 size = 0;
62 effective_full_buffer_size = 0; 75 effective_full_buffer_size = 0;
63 } 76 }
64 77
65 78
66 IndexedBufferBindingHost::IndexedBufferBindingHost( 79 IndexedBufferBindingHost::IndexedBufferBindingHost(
67 uint32_t max_bindings, bool needs_emulation) 80 uint32_t max_bindings, bool needs_emulation)
68 : needs_emulation_(needs_emulation) { 81 : needs_emulation_(needs_emulation),
82 max_non_null_binding_index_plus_one_(0u) {
69 buffer_bindings_.resize(max_bindings); 83 buffer_bindings_.resize(max_bindings);
70 } 84 }
71 85
72 IndexedBufferBindingHost::~IndexedBufferBindingHost() { 86 IndexedBufferBindingHost::~IndexedBufferBindingHost() {
73 } 87 }
74 88
75 void IndexedBufferBindingHost::DoBindBufferBase( 89 void IndexedBufferBindingHost::DoBindBufferBase(
76 GLenum target, GLuint index, Buffer* buffer) { 90 GLenum target, GLuint index, Buffer* buffer) {
77 DCHECK_LT(index, buffer_bindings_.size()); 91 DCHECK_LT(index, buffer_bindings_.size());
78 GLuint service_id = buffer ? buffer->service_id() : 0; 92 GLuint service_id = buffer ? buffer->service_id() : 0;
79 glBindBufferBase(target, index, service_id); 93 glBindBufferBase(target, index, service_id);
80 94
81 buffer_bindings_[index].SetBindBufferBase(buffer); 95 buffer_bindings_[index].SetBindBufferBase(buffer);
96 UpdateMaxNonNullBindingIndex(index);
82 } 97 }
83 98
84 void IndexedBufferBindingHost::DoBindBufferRange( 99 void IndexedBufferBindingHost::DoBindBufferRange(
85 GLenum target, GLuint index, Buffer* buffer, GLintptr offset, 100 GLenum target, GLuint index, Buffer* buffer, GLintptr offset,
86 GLsizeiptr size) { 101 GLsizeiptr size) {
87 DCHECK_LT(index, buffer_bindings_.size()); 102 DCHECK_LT(index, buffer_bindings_.size());
88 GLuint service_id = buffer ? buffer->service_id() : 0; 103 GLuint service_id = buffer ? buffer->service_id() : 0;
89 if (buffer && needs_emulation_) { 104 if (buffer && needs_emulation_) {
90 DoAdjustedBindBufferRange( 105 DoAdjustedBindBufferRange(
91 target, index, service_id, offset, size, buffer->size()); 106 target, index, service_id, offset, size, buffer->size());
92 } else { 107 } else {
93 glBindBufferRange(target, index, service_id, offset, size); 108 glBindBufferRange(target, index, service_id, offset, size);
94 } 109 }
95 110
96 buffer_bindings_[index].SetBindBufferRange(buffer, offset, size); 111 buffer_bindings_[index].SetBindBufferRange(buffer, offset, size);
112 UpdateMaxNonNullBindingIndex(index);
97 } 113 }
98 114
99 // static 115 // static
100 void IndexedBufferBindingHost::DoAdjustedBindBufferRange( 116 void IndexedBufferBindingHost::DoAdjustedBindBufferRange(
101 GLenum target, GLuint index, GLuint service_id, GLintptr offset, 117 GLenum target, GLuint index, GLuint service_id, GLintptr offset,
102 GLsizeiptr size, GLsizeiptr full_buffer_size) { 118 GLsizeiptr size, GLsizeiptr full_buffer_size) {
103 GLsizeiptr adjusted_size = size; 119 GLsizeiptr adjusted_size = size;
104 if (offset >= full_buffer_size) { 120 if (offset >= full_buffer_size) {
105 // Situation 1: We can't really call glBindBufferRange with reasonable 121 // Situation 1: We can't really call glBindBufferRange with reasonable
106 // offset/size without triggering a GL error because size == 0 isn't 122 // offset/size without triggering a GL error because size == 0 isn't
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 buffer_bindings_[ii].effective_full_buffer_size = buffer->size(); 173 buffer_bindings_[ii].effective_full_buffer_size = buffer->size();
158 } 174 }
159 } 175 }
160 } 176 }
161 } 177 }
162 178
163 void IndexedBufferBindingHost::RemoveBoundBuffer(Buffer* buffer) { 179 void IndexedBufferBindingHost::RemoveBoundBuffer(Buffer* buffer) {
164 for (size_t ii = 0; ii < buffer_bindings_.size(); ++ii) { 180 for (size_t ii = 0; ii < buffer_bindings_.size(); ++ii) {
165 if (buffer_bindings_[ii].buffer.get() == buffer) { 181 if (buffer_bindings_[ii].buffer.get() == buffer) {
166 buffer_bindings_[ii].Reset(); 182 buffer_bindings_[ii].Reset();
183 UpdateMaxNonNullBindingIndex(ii);
167 } 184 }
168 } 185 }
169 } 186 }
170 187
171 Buffer* IndexedBufferBindingHost::GetBufferBinding(GLuint index) const { 188 Buffer* IndexedBufferBindingHost::GetBufferBinding(GLuint index) const {
172 DCHECK_LT(index, buffer_bindings_.size()); 189 DCHECK_LT(index, buffer_bindings_.size());
173 return buffer_bindings_[index].buffer.get(); 190 return buffer_bindings_[index].buffer.get();
174 } 191 }
175 192
176 GLsizeiptr IndexedBufferBindingHost::GetBufferSize(GLuint index) const { 193 GLsizeiptr IndexedBufferBindingHost::GetBufferSize(GLuint index) const {
177 DCHECK_LT(index, buffer_bindings_.size()); 194 DCHECK_LT(index, buffer_bindings_.size());
178 return buffer_bindings_[index].size; 195 return buffer_bindings_[index].size;
179 } 196 }
180 197
181 GLintptr IndexedBufferBindingHost::GetBufferStart(GLuint index) const { 198 GLintptr IndexedBufferBindingHost::GetBufferStart(GLuint index) const {
182 DCHECK_LT(index, buffer_bindings_.size()); 199 DCHECK_LT(index, buffer_bindings_.size());
183 return buffer_bindings_[index].offset; 200 return buffer_bindings_[index].offset;
184 } 201 }
185 202
203 void IndexedBufferBindingHost::RestoreBindings(
204 IndexedBufferBindingHost* prev) {
205 size_t limit = max_non_null_binding_index_plus_one_;
206 if (prev && prev->max_non_null_binding_index_plus_one_ > limit) {
207 limit = prev->max_non_null_binding_index_plus_one_;
208 }
209 for (size_t ii = 0; ii < limit; ++ii) {
210 if (prev && buffer_bindings_[ii] == prev->buffer_bindings_[ii]) {
211 continue;
212 }
213 switch (buffer_bindings_[ii].type) {
214 case kBindBufferBase:
215 case kBindBufferNone:
216 DoBindBufferBase(
217 GL_UNIFORM_BUFFER, ii, buffer_bindings_[ii].buffer.get());
218 break;
219 case kBindBufferRange:
220 DoBindBufferRange(
221 GL_UNIFORM_BUFFER, ii, buffer_bindings_[ii].buffer.get(),
222 buffer_bindings_[ii].offset, buffer_bindings_[ii].size);
223 break;
224 }
225 }
226 }
227
228 void IndexedBufferBindingHost::UpdateMaxNonNullBindingIndex(
229 size_t changed_index) {
230 size_t plus_one = changed_index + 1;
231 DCHECK_LT(changed_index, buffer_bindings_.size());
232 if (buffer_bindings_[changed_index].buffer.get()) {
233 max_non_null_binding_index_plus_one_ =
234 std::max(max_non_null_binding_index_plus_one_, plus_one);
235 } else {
236 if (plus_one == max_non_null_binding_index_plus_one_) {
237 for (size_t ii = changed_index; ii > 0; --ii) {
238 if (buffer_bindings_[ii - 1].buffer.get()) {
239 max_non_null_binding_index_plus_one_ = ii;
240 break;
241 }
242 }
243 }
244 }
245 }
246
186 } // namespace gles2 247 } // namespace gles2
187 } // namespace gpu 248 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698