Commit 7bc44599 authored by Jonathan Backer's avatar Jonathan Backer Committed by Commit Bot

Enable GPU debug flags for unittests

This refactor CL allows useful GPU service flags like
--enable-gpu-service-logging (log all GL commands processed) and
--enable-gpu-debugging (check for GL error after every command) to be
used when running unittests (e.g. cc_unittests) that use
InProcessCommandBuffer.

There are no security implications of this change because

- only tests use the codepath updated here (Viz and android webview do
  not)

- flags are whitelist passed to child processes (renderer/GPU processes)

ParseGpuPreferences could not easily be added as a member of
GpuPreferences because of dependencies.

  - ParseGpuPreferences depends on gpu/command_buffer/service:gles2 to
    check if passthrough decoder is enabled.

  - gpu/command_buffer/service:gles2 has a dependency on
    gpu/command_buffer/service:service

  - GpuPreferences lives in gpu/command_buffer/service:service

  - Moving GpuPreferences to gpu/command_buffer/service:gles2 seems
    non-trivial. I did not want to introduce a new component just for
    GpuPreferences.

ParseGpuPreferences did not seem to belong to gpu_preferences_util.h
because that is IPC specific.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I76db4fe0eebd3eb7720fa24265f69093715c6137
Reviewed-on: https://chromium-review.googlesource.com/1019662Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Jonathan Backer <backer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553707}
parent 6307cee9
...@@ -4,20 +4,21 @@ ...@@ -4,20 +4,21 @@
#include "content/public/browser/gpu_utils.h" #include "content/public/browser/gpu_utils.h"
#include <string>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_process_host.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/service_utils.h" #include "gpu/command_buffer/service/service_utils.h"
#include "gpu/config/gpu_switches.h"
#include "media/media_buildflags.h" #include "media/media_buildflags.h"
#include "ui/gl/gl_switches.h"
namespace { namespace {
#if defined(OS_WIN)
bool GetUintFromSwitch(const base::CommandLine* command_line, bool GetUintFromSwitch(const base::CommandLine* command_line,
const base::StringPiece& switch_string, const base::StringPiece& switch_string,
uint32_t* value) { uint32_t* value) {
...@@ -26,6 +27,7 @@ bool GetUintFromSwitch(const base::CommandLine* command_line, ...@@ -26,6 +27,7 @@ bool GetUintFromSwitch(const base::CommandLine* command_line,
std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); std::string switch_value(command_line->GetSwitchValueASCII(switch_string));
return base::StringToUint(switch_value, value); return base::StringToUint(switch_value, value);
} }
#endif // defined(OS_WIN)
void RunTaskOnTaskRunner( void RunTaskOnTaskRunner(
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
...@@ -49,7 +51,8 @@ const gpu::GpuPreferences GetGpuPreferencesFromCommandLine() { ...@@ -49,7 +51,8 @@ const gpu::GpuPreferences GetGpuPreferencesFromCommandLine() {
DCHECK(base::CommandLine::InitializedForCurrentProcess()); DCHECK(base::CommandLine::InitializedForCurrentProcess());
const base::CommandLine* command_line = const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess(); base::CommandLine::ForCurrentProcess();
gpu::GpuPreferences gpu_preferences; gpu::GpuPreferences gpu_preferences =
gpu::gles2::ParseGpuPreferences(command_line);
gpu_preferences.single_process = gpu_preferences.single_process =
command_line->HasSwitch(switches::kSingleProcess); command_line->HasSwitch(switches::kSingleProcess);
gpu_preferences.in_process_gpu = gpu_preferences.in_process_gpu =
...@@ -78,50 +81,6 @@ const gpu::GpuPreferences GetGpuPreferencesFromCommandLine() { ...@@ -78,50 +81,6 @@ const gpu::GpuPreferences GetGpuPreferencesFromCommandLine() {
command_line->HasSwitch(switches::kDisableSoftwareRasterizer); command_line->HasSwitch(switches::kDisableSoftwareRasterizer);
gpu_preferences.log_gpu_control_list_decisions = gpu_preferences.log_gpu_control_list_decisions =
command_line->HasSwitch(switches::kLogGpuControlListDecisions); command_line->HasSwitch(switches::kLogGpuControlListDecisions);
gpu_preferences.compile_shader_always_succeeds =
command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds);
gpu_preferences.disable_gl_error_limit =
command_line->HasSwitch(switches::kDisableGLErrorLimit);
gpu_preferences.disable_glsl_translator =
command_line->HasSwitch(switches::kDisableGLSLTranslator);
gpu_preferences.disable_shader_name_hashing =
command_line->HasSwitch(switches::kDisableShaderNameHashing);
gpu_preferences.enable_gpu_command_logging =
command_line->HasSwitch(switches::kEnableGPUCommandLogging);
gpu_preferences.enable_gpu_debugging =
command_line->HasSwitch(switches::kEnableGPUDebugging);
gpu_preferences.enable_gpu_service_logging_gpu =
command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU);
gpu_preferences.enable_gpu_driver_debug_logging =
command_line->HasSwitch(switches::kEnableGPUDriverDebugLogging);
gpu_preferences.disable_gpu_program_cache =
command_line->HasSwitch(switches::kDisableGpuProgramCache);
gpu_preferences.enforce_gl_minimums =
command_line->HasSwitch(switches::kEnforceGLMinimums);
if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb,
&gpu_preferences.force_gpu_mem_available)) {
gpu_preferences.force_gpu_mem_available *= 1024 * 1024;
}
if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb,
&gpu_preferences.gpu_program_cache_size)) {
gpu_preferences.gpu_program_cache_size *= 1024;
}
gpu_preferences.disable_gpu_shader_disk_cache =
command_line->HasSwitch(switches::kDisableGpuShaderDiskCache);
gpu_preferences.enable_threaded_texture_mailboxes =
command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes);
gpu_preferences.gl_shader_interm_output =
command_line->HasSwitch(switches::kGLShaderIntermOutput);
gpu_preferences.emulate_shader_precision =
command_line->HasSwitch(switches::kEmulateShaderPrecision);
gpu_preferences.enable_raster_decoder =
command_line->HasSwitch(switches::kEnableRasterDecoder);
gpu_preferences.enable_gpu_service_logging =
command_line->HasSwitch(switches::kEnableGPUServiceLogging);
gpu_preferences.enable_gpu_service_tracing =
command_line->HasSwitch(switches::kEnableGPUServiceTracing);
gpu_preferences.use_passthrough_cmd_decoder =
gpu::gles2::UsePassthroughCommandDecoder(command_line);
gpu_preferences.gpu_startup_dialog = gpu_preferences.gpu_startup_dialog =
command_line->HasSwitch(switches::kGpuStartupDialog); command_line->HasSwitch(switches::kGpuStartupDialog);
gpu_preferences.disable_gpu_watchdog = gpu_preferences.disable_gpu_watchdog =
...@@ -129,10 +88,6 @@ const gpu::GpuPreferences GetGpuPreferencesFromCommandLine() { ...@@ -129,10 +88,6 @@ const gpu::GpuPreferences GetGpuPreferencesFromCommandLine() {
(gpu_preferences.single_process || gpu_preferences.in_process_gpu); (gpu_preferences.single_process || gpu_preferences.in_process_gpu);
gpu_preferences.gpu_sandbox_start_early = gpu_preferences.gpu_sandbox_start_early =
command_line->HasSwitch(switches::kGpuSandboxStartEarly); command_line->HasSwitch(switches::kGpuSandboxStartEarly);
gpu_preferences.disable_gpu_driver_bug_workarounds =
command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds);
gpu_preferences.ignore_gpu_blacklist =
command_line->HasSwitch(switches::kIgnoreGpuBlacklist);
// Some of these preferences are set or adjusted in // Some of these preferences are set or adjusted in
// GpuDataManagerImplPrivate::AppendGpuCommandLine. // GpuDataManagerImplPrivate::AppendGpuCommandLine.
return gpu_preferences; return gpu_preferences;
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
#include "gpu/command_buffer/service/service_utils.h" #include "gpu/command_buffer/service/service_utils.h"
#include <string>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h" #include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/service/context_group.h" #include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/gpu_switches.h" #include "gpu/command_buffer/service/gpu_switches.h"
...@@ -18,6 +21,19 @@ ...@@ -18,6 +21,19 @@
namespace gpu { namespace gpu {
namespace gles2 { namespace gles2 {
namespace {
bool GetUintFromSwitch(const base::CommandLine* command_line,
const base::StringPiece& switch_string,
uint32_t* value) {
if (!command_line->HasSwitch(switch_string))
return false;
std::string switch_value(command_line->GetSwitchValueASCII(switch_string));
return base::StringToUint(switch_value, value);
}
} // namespace
gl::GLContextAttribs GenerateGLContextAttribs( gl::GLContextAttribs GenerateGLContextAttribs(
const ContextCreationAttribs& attribs_helper, const ContextCreationAttribs& attribs_helper,
const ContextGroup* context_group) { const ContextGroup* context_group) {
...@@ -90,7 +106,60 @@ bool PassthroughCommandDecoderSupported() { ...@@ -90,7 +106,60 @@ bool PassthroughCommandDecoderSupported() {
// The passthrough command buffer is only supported on top of ANGLE/EGL // The passthrough command buffer is only supported on top of ANGLE/EGL
return false; return false;
#endif // defined(USE_EGL) #endif // defined(USE_EGL)
} // namespace gles2 }
GpuPreferences ParseGpuPreferences(const base::CommandLine* command_line) {
GpuPreferences gpu_preferences;
gpu_preferences.compile_shader_always_succeeds =
command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds);
gpu_preferences.disable_gl_error_limit =
command_line->HasSwitch(switches::kDisableGLErrorLimit);
gpu_preferences.disable_glsl_translator =
command_line->HasSwitch(switches::kDisableGLSLTranslator);
gpu_preferences.disable_shader_name_hashing =
command_line->HasSwitch(switches::kDisableShaderNameHashing);
gpu_preferences.enable_gpu_command_logging =
command_line->HasSwitch(switches::kEnableGPUCommandLogging);
gpu_preferences.enable_gpu_debugging =
command_line->HasSwitch(switches::kEnableGPUDebugging);
gpu_preferences.enable_gpu_service_logging_gpu =
command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU);
gpu_preferences.enable_gpu_driver_debug_logging =
command_line->HasSwitch(switches::kEnableGPUDriverDebugLogging);
gpu_preferences.disable_gpu_program_cache =
command_line->HasSwitch(switches::kDisableGpuProgramCache);
gpu_preferences.enforce_gl_minimums =
command_line->HasSwitch(switches::kEnforceGLMinimums);
if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb,
&gpu_preferences.force_gpu_mem_available)) {
gpu_preferences.force_gpu_mem_available *= 1024 * 1024;
}
if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb,
&gpu_preferences.gpu_program_cache_size)) {
gpu_preferences.gpu_program_cache_size *= 1024;
}
gpu_preferences.disable_gpu_shader_disk_cache =
command_line->HasSwitch(switches::kDisableGpuShaderDiskCache);
gpu_preferences.enable_threaded_texture_mailboxes =
command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes);
gpu_preferences.gl_shader_interm_output =
command_line->HasSwitch(switches::kGLShaderIntermOutput);
gpu_preferences.emulate_shader_precision =
command_line->HasSwitch(switches::kEmulateShaderPrecision);
gpu_preferences.enable_raster_decoder =
command_line->HasSwitch(switches::kEnableRasterDecoder);
gpu_preferences.enable_gpu_service_logging =
command_line->HasSwitch(switches::kEnableGPUServiceLogging);
gpu_preferences.enable_gpu_service_tracing =
command_line->HasSwitch(switches::kEnableGPUServiceTracing);
gpu_preferences.use_passthrough_cmd_decoder =
gpu::gles2::UsePassthroughCommandDecoder(command_line);
gpu_preferences.disable_gpu_driver_bug_workarounds =
command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds);
gpu_preferences.ignore_gpu_blacklist =
command_line->HasSwitch(switches::kIgnoreGpuBlacklist);
return gpu_preferences;
}
} // namespace gles2 } // namespace gles2
} // namespace gpu } // namespace gpu
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
namespace gpu { namespace gpu {
struct ContextCreationAttribs; struct ContextCreationAttribs;
struct GpuPreferences;
namespace gles2 { namespace gles2 {
class ContextGroup; class ContextGroup;
...@@ -26,6 +27,9 @@ GPU_GLES2_EXPORT bool UsePassthroughCommandDecoder( ...@@ -26,6 +27,9 @@ GPU_GLES2_EXPORT bool UsePassthroughCommandDecoder(
// Returns true if the driver supports creating passthrough command decoders // Returns true if the driver supports creating passthrough command decoders
GPU_GLES2_EXPORT bool PassthroughCommandDecoderSupported(); GPU_GLES2_EXPORT bool PassthroughCommandDecoderSupported();
GPU_GLES2_EXPORT GpuPreferences
ParseGpuPreferences(const base::CommandLine* command_line);
} // namespace gles2 } // namespace gles2
} // namespace gpu } // namespace gpu
......
...@@ -102,9 +102,12 @@ class GpuInProcessThreadHolder : public base::Thread { ...@@ -102,9 +102,12 @@ class GpuInProcessThreadHolder : public base::Thread {
const scoped_refptr<InProcessCommandBuffer::Service>& GetGpuThreadService() { const scoped_refptr<InProcessCommandBuffer::Service>& GetGpuThreadService() {
if (!gpu_thread_service_) { if (!gpu_thread_service_) {
DCHECK(base::CommandLine::InitializedForCurrentProcess());
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
gpu_thread_service_ = base::MakeRefCounted<GpuInProcessThreadService>( gpu_thread_service_ = base::MakeRefCounted<GpuInProcessThreadService>(
task_runner(), sync_point_manager_.get(), nullptr, nullptr, task_runner(), sync_point_manager_.get(), nullptr, nullptr,
gpu_feature_info_, GpuPreferences()); gpu_feature_info_, gles2::ParseGpuPreferences(command_line));
} }
return gpu_thread_service_; return gpu_thread_service_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment