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

Side by Side Diff: gpu/command_buffer/tests/fuzzer_main.cc

Issue 2691643002: Add gpu_angle_passthrough_fuzzer. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « gpu/BUILD.gn ('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 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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "gpu/command_buffer/common/constants.h" 17 #include "gpu/command_buffer/common/constants.h"
18 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 18 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
19 #include "gpu/command_buffer/common/sync_token.h" 19 #include "gpu/command_buffer/common/sync_token.h"
20 #include "gpu/command_buffer/service/buffer_manager.h" 20 #include "gpu/command_buffer/service/buffer_manager.h"
21 #include "gpu/command_buffer/service/command_buffer_service.h" 21 #include "gpu/command_buffer/service/command_buffer_service.h"
22 #include "gpu/command_buffer/service/command_executor.h" 22 #include "gpu/command_buffer/service/command_executor.h"
23 #include "gpu/command_buffer/service/context_group.h" 23 #include "gpu/command_buffer/service/context_group.h"
24 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 24 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
25 #include "gpu/command_buffer/service/gpu_switches.h"
25 #include "gpu/command_buffer/service/logger.h" 26 #include "gpu/command_buffer/service/logger.h"
26 #include "gpu/command_buffer/service/mailbox_manager_impl.h" 27 #include "gpu/command_buffer/service/mailbox_manager_impl.h"
27 #include "gpu/command_buffer/service/sync_point_manager.h" 28 #include "gpu/command_buffer/service/sync_point_manager.h"
28 #include "gpu/command_buffer/service/transfer_buffer_manager.h" 29 #include "gpu/command_buffer/service/transfer_buffer_manager.h"
29 #include "ui/gfx/geometry/size.h" 30 #include "ui/gfx/geometry/size.h"
30 #include "ui/gl/gl_context.h" 31 #include "ui/gl/gl_context.h"
31 #include "ui/gl/gl_context_egl.h" 32 #include "ui/gl/gl_context_egl.h"
32 #include "ui/gl/gl_context_stub.h" 33 #include "ui/gl/gl_context_stub.h"
33 #include "ui/gl/gl_image_ref_counted_memory.h" 34 #include "ui/gl/gl_image_ref_counted_memory.h"
34 #include "ui/gl/gl_share_group.h" 35 #include "ui/gl/gl_share_group.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 CommandBufferSetup() 90 CommandBufferSetup()
90 : atexit_manager_(), 91 : atexit_manager_(),
91 sync_point_manager_(new SyncPointManager(false)), 92 sync_point_manager_(new SyncPointManager(false)),
92 sync_point_order_data_(SyncPointOrderData::Create()), 93 sync_point_order_data_(SyncPointOrderData::Create()),
93 mailbox_manager_(new gles2::MailboxManagerImpl), 94 mailbox_manager_(new gles2::MailboxManagerImpl),
94 share_group_(new gl::GLShareGroup), 95 share_group_(new gl::GLShareGroup),
95 command_buffer_id_(CommandBufferId::FromUnsafeValue(1)) { 96 command_buffer_id_(CommandBufferId::FromUnsafeValue(1)) {
96 logging::SetMinLogLevel(logging::LOG_FATAL); 97 logging::SetMinLogLevel(logging::LOG_FATAL);
97 base::CommandLine::Init(0, NULL); 98 base::CommandLine::Init(0, NULL);
98 99
100 auto* command_line = base::CommandLine::ForCurrentProcess();
101 (void)command_line;
piman 2017/03/09 18:15:13 nit: ALLOW_UNUSED_LOCAL
Geoff Lang 2017/03/09 19:29:10 Done.
102
103 #if defined(GPU_FUZZER_USE_PASSTHROUGH_CMD_DECODER)
104 command_line->AppendSwitch(switches::kUsePassthroughCmdDecoder);
105 gpu_preferences_.use_passthrough_cmd_decoder = true;
106 #endif
107
99 #if defined(GPU_FUZZER_USE_ANGLE) 108 #if defined(GPU_FUZZER_USE_ANGLE)
100 auto* command_line = base::CommandLine::ForCurrentProcess();
101 command_line->AppendSwitchASCII(switches::kUseGL, 109 command_line->AppendSwitchASCII(switches::kUseGL,
102 gl::kGLImplementationANGLEName); 110 gl::kGLImplementationANGLEName);
103 command_line->AppendSwitchASCII(switches::kUseANGLE, 111 command_line->AppendSwitchASCII(switches::kUseANGLE,
104 gl::kANGLEImplementationNullName); 112 gl::kANGLEImplementationNullName);
105 gl::init::InitializeGLOneOffImplementation(gl::kGLImplementationEGLGLES2, 113 gl::init::InitializeGLOneOffImplementation(gl::kGLImplementationEGLGLES2,
106 false, false, false); 114 false, false, false);
115 #else
116 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
117 #endif
118
119 sync_point_client_ = sync_point_manager_->CreateSyncPointClient(
120 sync_point_order_data_, CommandBufferNamespace::IN_PROCESS,
121 command_buffer_id_);
122
123 translator_cache_ = new gles2::ShaderTranslatorCache(gpu_preferences_);
124 completeness_cache_ = new gles2::FramebufferCompletenessCache;
125
126 InitDecoder();
127 }
128
129 void InitDecoder() {
130 if (decoder_initialized_) {
131 return;
132 }
133
134 #if defined(GPU_FUZZER_USE_ANGLE)
107 surface_ = new gl::PbufferGLSurfaceEGL(gfx::Size()); 135 surface_ = new gl::PbufferGLSurfaceEGL(gfx::Size());
108 surface_->Initialize(); 136 surface_->Initialize();
109 137
110 context_ = new gl::GLContextEGL(share_group_.get()); 138 context_ = new gl::GLContextEGL(share_group_.get());
111 context_->Initialize(surface_.get(), gl::GLContextAttribs()); 139 context_->Initialize(surface_.get(), gl::GLContextAttribs());
piman 2017/03/09 18:15:13 Did you intend to recreate the context on every te
Geoff Lang 2017/03/09 19:29:10 Yea, it didn't seem to have too much of an effect
112 #else 140 #else
113 surface_ = new gl::GLSurfaceStub; 141 surface_ = new gl::GLSurfaceStub;
114 scoped_refptr<gl::GLContextStub> context_stub = 142 scoped_refptr<gl::GLContextStub> context_stub =
115 new gl::GLContextStub(share_group_.get()); 143 new gl::GLContextStub(share_group_.get());
116 context_stub->SetGLVersionString("OpenGL ES 3.1"); 144 context_stub->SetGLVersionString("OpenGL ES 3.1");
117 context_stub->SetExtensionsString(kExtensions); 145 context_stub->SetExtensionsString(kExtensions);
118 context_stub->SetUseStubApi(true); 146 context_stub->SetUseStubApi(true);
119 context_ = context_stub; 147 context_ = context_stub;
120 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
121 #endif 148 #endif
122 149
123 sync_point_client_ = sync_point_manager_->CreateSyncPointClient(
124 sync_point_order_data_, CommandBufferNamespace::IN_PROCESS,
125 command_buffer_id_);
126
127 translator_cache_ = new gles2::ShaderTranslatorCache(gpu_preferences_);
128 completeness_cache_ = new gles2::FramebufferCompletenessCache;
129 }
130
131 void InitDecoder() {
132 context_->MakeCurrent(surface_.get()); 150 context_->MakeCurrent(surface_.get());
133 scoped_refptr<gles2::FeatureInfo> feature_info = 151 scoped_refptr<gles2::FeatureInfo> feature_info =
134 new gles2::FeatureInfo(); 152 new gles2::FeatureInfo();
135 scoped_refptr<gles2::ContextGroup> context_group = new gles2::ContextGroup( 153 scoped_refptr<gles2::ContextGroup> context_group = new gles2::ContextGroup(
136 gpu_preferences_, mailbox_manager_.get(), nullptr, translator_cache_, 154 gpu_preferences_, mailbox_manager_.get(), nullptr, translator_cache_,
137 completeness_cache_, feature_info, true /* bind_generates_resource */, 155 completeness_cache_, feature_info, true /* bind_generates_resource */,
138 nullptr /* image_factory */, nullptr /* progress_reporter */); 156 nullptr /* image_factory */, nullptr /* progress_reporter */);
139 command_buffer_.reset( 157 command_buffer_.reset(
140 new CommandBufferService(context_group->transfer_buffer_manager())); 158 new CommandBufferService(context_group->transfer_buffer_manager()));
141 command_buffer_->SetPutOffsetChangeCallback( 159 command_buffer_->SetPutOffsetChangeCallback(
(...skipping 28 matching lines...) Expand all
170 CHECK(result); 188 CHECK(result);
171 decoder_->set_max_bucket_size(8 << 20); 189 decoder_->set_max_bucket_size(8 << 20);
172 context_group->buffer_manager()->set_max_buffer_size(8 << 20); 190 context_group->buffer_manager()->set_max_buffer_size(8 << 20);
173 if (!vertex_translator_) { 191 if (!vertex_translator_) {
174 // Keep a reference to the translators, which keeps them in the cache even 192 // Keep a reference to the translators, which keeps them in the cache even
175 // after the decoder is reset. They are expensive to initialize, but they 193 // after the decoder is reset. They are expensive to initialize, but they
176 // don't keep state. 194 // don't keep state.
177 vertex_translator_ = decoder_->GetTranslator(GL_VERTEX_SHADER); 195 vertex_translator_ = decoder_->GetTranslator(GL_VERTEX_SHADER);
178 fragment_translator_ = decoder_->GetTranslator(GL_FRAGMENT_SHADER); 196 fragment_translator_ = decoder_->GetTranslator(GL_FRAGMENT_SHADER);
179 } 197 }
198
199 decoder_initialized_ = true;
piman 2017/03/09 18:15:13 Why the need for this? Before this change, we init
Geoff Lang 2017/03/09 19:29:10 I added this due to the comment referenced below.
piman 2017/03/09 22:12:35 Right, the important part is that the ANGLE DLL is
Geoff Lang 2017/03/09 22:22:13 Sounds good, I'll update that when I get back to M
Geoff Lang 2017/03/16 17:22:08 Done, I also updated it to only re-create the cont
180 } 200 }
181 201
182 void ResetDecoder() { 202 void ResetDecoder() {
203 if (!decoder_initialized_) {
204 return;
205 }
206
183 decoder_->Destroy(true); 207 decoder_->Destroy(true);
184 decoder_.reset(); 208 decoder_.reset();
185 command_buffer_.reset(); 209 command_buffer_.reset();
210 surface_ = nullptr;
211 context_->ReleaseCurrent(nullptr);
212 context_ = nullptr;
213
214 decoder_initialized_ = false;
186 } 215 }
187 216
188 ~CommandBufferSetup() { 217 ~CommandBufferSetup() {
218 ResetDecoder();
189 sync_point_client_ = nullptr; 219 sync_point_client_ = nullptr;
190 if (sync_point_order_data_) { 220 if (sync_point_order_data_) {
191 sync_point_order_data_->Destroy(); 221 sync_point_order_data_->Destroy();
192 sync_point_order_data_ = nullptr; 222 sync_point_order_data_ = nullptr;
193 } 223 }
194 } 224 }
195 225
196 void RunCommandBuffer(const uint8_t* data, size_t size) { 226 void RunCommandBuffer(const uint8_t* data, size_t size) {
197 // The commands are flushed at a uint32_t granularity. If the data is not 227 // The commands are flushed at a uint32_t granularity. If the data is not
198 // a full command, we zero-pad it. 228 // a full command, we zero-pad it.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 311
282 GpuPreferences gpu_preferences_; 312 GpuPreferences gpu_preferences_;
283 313
284 std::unique_ptr<SyncPointManager> sync_point_manager_; 314 std::unique_ptr<SyncPointManager> sync_point_manager_;
285 scoped_refptr<SyncPointOrderData> sync_point_order_data_; 315 scoped_refptr<SyncPointOrderData> sync_point_order_data_;
286 std::unique_ptr<SyncPointClient> sync_point_client_; 316 std::unique_ptr<SyncPointClient> sync_point_client_;
287 scoped_refptr<gles2::MailboxManager> mailbox_manager_; 317 scoped_refptr<gles2::MailboxManager> mailbox_manager_;
288 scoped_refptr<gl::GLShareGroup> share_group_; 318 scoped_refptr<gl::GLShareGroup> share_group_;
289 const gpu::CommandBufferId command_buffer_id_; 319 const gpu::CommandBufferId command_buffer_id_;
290 320
321 bool decoder_initialized_ = false;
322
291 scoped_refptr<gl::GLSurface> surface_; 323 scoped_refptr<gl::GLSurface> surface_;
292 scoped_refptr<gl::GLContext> context_; 324 scoped_refptr<gl::GLContext> context_;
293 325
294 scoped_refptr<gles2::ShaderTranslatorCache> translator_cache_; 326 scoped_refptr<gles2::ShaderTranslatorCache> translator_cache_;
295 scoped_refptr<gles2::FramebufferCompletenessCache> completeness_cache_; 327 scoped_refptr<gles2::FramebufferCompletenessCache> completeness_cache_;
296 328
297 std::unique_ptr<CommandBufferService> command_buffer_; 329 std::unique_ptr<CommandBufferService> command_buffer_;
298 330
299 std::unique_ptr<gles2::GLES2Decoder> decoder_; 331 std::unique_ptr<gles2::GLES2Decoder> decoder_;
300 std::unique_ptr<CommandExecutor> executor_; 332 std::unique_ptr<CommandExecutor> executor_;
301 333
302 scoped_refptr<gles2::ShaderTranslatorInterface> vertex_translator_; 334 scoped_refptr<gles2::ShaderTranslatorInterface> vertex_translator_;
303 scoped_refptr<gles2::ShaderTranslatorInterface> fragment_translator_; 335 scoped_refptr<gles2::ShaderTranslatorInterface> fragment_translator_;
304 336
305 scoped_refptr<Buffer> buffer_; 337 scoped_refptr<Buffer> buffer_;
306 int32_t buffer_id_ = 0; 338 int32_t buffer_id_ = 0;
307 }; 339 };
308 340
309 // Intentionally leaked because asan tries to exit cleanly after a crash, but 341 // Intentionally leaked because asan tries to exit cleanly after a crash, but
310 // the decoder is usually in a bad state at that point. 342 // the decoder is usually in a bad state at that point.
311 // We need to load ANGLE libraries before the fuzzer infrastructure starts, 343 // We need to load ANGLE libraries before the fuzzer infrastructure starts,
312 // because it gets confused about new coverage counters being dynamically 344 // because it gets confused about new coverage counters being dynamically
313 // registered, causing crashes. 345 // registered, causing crashes.
314 CommandBufferSetup* g_setup = new CommandBufferSetup(); 346 CommandBufferSetup* g_setup = new CommandBufferSetup();
Geoff Lang 2017/03/09 19:29:10 ref
315 347
316 } // anonymous namespace 348 } // anonymous namespace
317 } // namespace gpu 349 } // namespace gpu
318 350
319 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 351 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
320 gpu::g_setup->RunCommandBuffer(data, size); 352 gpu::g_setup->RunCommandBuffer(data, size);
321 return 0; 353 return 0;
322 } 354 }
OLDNEW
« no previous file with comments | « gpu/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698