OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include <stddef.h> | 4 #include <stddef.h> |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 sync_point_order_data_->Destroy(); | 135 sync_point_order_data_->Destroy(); |
136 sync_point_order_data_ = nullptr; | 136 sync_point_order_data_ = nullptr; |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 void RunCommandBuffer(const uint8_t* data, size_t size) { | 140 void RunCommandBuffer(const uint8_t* data, size_t size) { |
141 InitDecoder(); | 141 InitDecoder(); |
142 // The commands are flushed at a uint32_t granularity. If the data is not | 142 // The commands are flushed at a uint32_t granularity. If the data is not |
143 // a full command, we zero-pad it. | 143 // a full command, we zero-pad it. |
144 size_t padded_size = (size + 3) & ~3; | 144 size_t padded_size = (size + 3) & ~3; |
145 CHECK_LE(padded_size, buffer_->size()); | 145 size_t buffer_size = buffer_->size(); |
| 146 CHECK_LE(padded_size, buffer_size); |
146 command_buffer_->SetGetBuffer(buffer_id_); | 147 command_buffer_->SetGetBuffer(buffer_id_); |
147 auto* memory = static_cast<char*>(buffer_->memory()); | 148 auto* memory = static_cast<char*>(buffer_->memory()); |
148 memcpy(memory, data, size); | 149 memcpy(memory, data, size); |
149 if (padded_size > size) | 150 if (size < buffer_size) |
150 memset(memory + size, 0, padded_size - size); | 151 memset(memory + size, 0, buffer_size - size); |
151 command_buffer_->Flush(padded_size / 4); | 152 command_buffer_->Flush(padded_size / 4); |
152 ResetDecoder(); | 153 ResetDecoder(); |
153 } | 154 } |
154 | 155 |
155 private: | 156 private: |
156 void PumpCommands() { | 157 void PumpCommands() { |
157 if (!decoder_->MakeCurrent()) { | 158 if (!decoder_->MakeCurrent()) { |
158 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 159 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
159 command_buffer_->SetParseError(::gpu::error::kLostContext); | 160 command_buffer_->SetParseError(::gpu::error::kLostContext); |
160 return; | 161 return; |
(...skipping 27 matching lines...) Expand all Loading... |
188 if (!release_state) | 189 if (!release_state) |
189 return true; | 190 return true; |
190 | 191 |
191 if (release_state->IsFenceSyncReleased(release)) | 192 if (release_state->IsFenceSyncReleased(release)) |
192 return true; | 193 return true; |
193 | 194 |
194 executor_->SetScheduled(false); | 195 executor_->SetScheduled(false); |
195 return false; | 196 return false; |
196 } | 197 } |
197 | 198 |
| 199 void CreateTransferBuffer(size_t size, int32_t id) { |
| 200 scoped_refptr<Buffer> buffer = |
| 201 command_buffer_->CreateTransferBufferWithId(size, id); |
| 202 memset(buffer->memory(), 0, size); |
| 203 } |
| 204 |
198 void InitializeInitialCommandBuffer() { | 205 void InitializeInitialCommandBuffer() { |
199 buffer_id_ = 1; | 206 buffer_id_ = 1; |
200 buffer_ = command_buffer_->CreateTransferBufferWithId(kCommandBufferSize, | 207 buffer_ = command_buffer_->CreateTransferBufferWithId(kCommandBufferSize, |
201 buffer_id_); | 208 buffer_id_); |
202 CHECK(buffer_); | 209 CHECK(buffer_); |
203 // Create some transfer buffers. This is somewhat arbitrary, but having a | 210 // Create some transfer buffers. This is somewhat arbitrary, but having a |
204 // reasonably sized buffer in slot 4 allows us to prime the corpus with data | 211 // reasonably sized buffer in slot 4 allows us to prime the corpus with data |
205 // extracted from unit tests. | 212 // extracted from unit tests. |
206 command_buffer_->CreateTransferBufferWithId(kTransferBufferSize, 2); | 213 CreateTransferBuffer(kTransferBufferSize, 2); |
207 command_buffer_->CreateTransferBufferWithId(kSmallTransferBufferSize, 3); | 214 CreateTransferBuffer(kSmallTransferBufferSize, 3); |
208 command_buffer_->CreateTransferBufferWithId(kTransferBufferSize, 4); | 215 CreateTransferBuffer(kTransferBufferSize, 4); |
209 command_buffer_->CreateTransferBufferWithId(kTinyTransferBufferSize, 5); | 216 CreateTransferBuffer(kTinyTransferBufferSize, 5); |
210 } | 217 } |
211 | 218 |
212 base::AtExitManager atexit_manager_; | 219 base::AtExitManager atexit_manager_; |
213 | 220 |
214 gl::GLStubApi api_; | 221 gl::GLStubApi api_; |
215 GpuPreferences gpu_preferences_; | 222 GpuPreferences gpu_preferences_; |
216 | 223 |
217 std::unique_ptr<SyncPointManager> sync_point_manager_; | 224 std::unique_ptr<SyncPointManager> sync_point_manager_; |
218 scoped_refptr<SyncPointOrderData> sync_point_order_data_; | 225 scoped_refptr<SyncPointOrderData> sync_point_order_data_; |
219 std::unique_ptr<SyncPointClient> sync_point_client_; | 226 std::unique_ptr<SyncPointClient> sync_point_client_; |
(...skipping 24 matching lines...) Expand all Loading... |
244 | 251 |
245 static gpu::CommandBufferSetup& GetSetup() { | 252 static gpu::CommandBufferSetup& GetSetup() { |
246 static gpu::CommandBufferSetup setup; | 253 static gpu::CommandBufferSetup setup; |
247 return setup; | 254 return setup; |
248 } | 255 } |
249 | 256 |
250 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 257 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
251 GetSetup().RunCommandBuffer(data, size); | 258 GetSetup().RunCommandBuffer(data, size); |
252 return 0; | 259 return 0; |
253 } | 260 } |
OLD | NEW |