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
3 // found in the LICENSE file.
4
5 #include "gpu/config/gpu_driver_bug_workarounds.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10
11 namespace {
12 // Construct GpuDriverBugWorkarounds from a set of enabled workaround IDs.
IntSetToWorkarounds(const std::vector<int32_t> & enabled_workarounds,gpu::GpuDriverBugWorkarounds * workarounds)13 void IntSetToWorkarounds(const std::vector<int32_t>& enabled_workarounds,
14 gpu::GpuDriverBugWorkarounds* workarounds) {
15 DCHECK(workarounds);
16 for (auto ID : enabled_workarounds) {
17 switch (ID) {
18 #define GPU_OP(type, name) \
19 case gpu::type: \
20 workarounds->name = true; \
21 break;
22 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
23 #undef GPU_OP
24 default:
25 NOTIMPLEMENTED();
26 }
27 }
28 if (workarounds->max_texture_size_limit_4096)
29 workarounds->max_texture_size = 4096;
30
31 if (workarounds->max_copy_texture_chromium_size_1048576)
32 workarounds->max_copy_texture_chromium_size = 1048576;
33 if (workarounds->max_copy_texture_chromium_size_262144)
34 workarounds->max_copy_texture_chromium_size = 262144;
35
36 if (workarounds->max_3d_array_texture_size_1024)
37 workarounds->max_3d_array_texture_size = 1024;
38 }
39
LowerMax(GLint max0,GLint max1)40 GLint LowerMax(GLint max0, GLint max1) {
41 if (max0 > 0 && max1 > 0)
42 return std::min(max0, max1);
43 if (max0 > 0)
44 return max0;
45 return max1;
46 }
47
48 } // anonymous namespace
49
50 namespace gpu {
51
52 GpuDriverBugWorkarounds::GpuDriverBugWorkarounds() = default;
53
GpuDriverBugWorkarounds(const std::vector<int> & enabled_driver_bug_workarounds)54 GpuDriverBugWorkarounds::GpuDriverBugWorkarounds(
55 const std::vector<int>& enabled_driver_bug_workarounds) {
56 IntSetToWorkarounds(enabled_driver_bug_workarounds, this);
57 }
58
59 GpuDriverBugWorkarounds::GpuDriverBugWorkarounds(
60 const GpuDriverBugWorkarounds& other) = default;
61
62 GpuDriverBugWorkarounds::~GpuDriverBugWorkarounds() = default;
63
ToIntSet() const64 std::vector<int32_t> GpuDriverBugWorkarounds::ToIntSet() const {
65 std::vector<int32_t> result;
66 #define GPU_OP(type, name) \
67 if (name) \
68 result.push_back(type);
69 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
70 #undef GPU_OP
71 return result;
72 }
73
Append(const GpuDriverBugWorkarounds & extra)74 void GpuDriverBugWorkarounds::Append(const GpuDriverBugWorkarounds& extra) {
75 #define GPU_OP(type, name) name |= extra.name;
76 GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)
77 #undef GPU_OP
78
79 max_texture_size = LowerMax(max_texture_size, extra.max_texture_size);
80 max_copy_texture_chromium_size = LowerMax(
81 max_copy_texture_chromium_size, extra.max_copy_texture_chromium_size);
82 max_3d_array_texture_size =
83 LowerMax(max_3d_array_texture_size, extra.max_3d_array_texture_size);
84 }
85
86 } // namespace gpu
87