1From b59ec731c8c7e084b289e4ea92938faaebcc389d Mon Sep 17 00:00:00 2001
2From: Alexandros Frantzis <alexandros.frantzis@collabora.com>
3Date: Wed, 1 Nov 2023 13:43:00 +0200
4Subject: [PATCH] GLVisualConfig: By default don't care about the stencil
5 config component
6
7Our benchmarks don't use a stencil buffer, but its presence doesn't hurt
8either, so don't mark configs that have one as unacceptable. Our scoring
9still favors configs without one, unless the user explicitly specifies
10otherwise with --visual-config.
11
12Upstream-Status: Backport [https://github.com/glmark2/glmark2/commit/5f23d540342ba69e12afeb6a1ac4f6fd36747975]
13---
14 doc/glmark2.1.in         | 2 +-
15 src/gl-visual-config.cpp | 9 ++++++---
16 src/gl-visual-config.h   | 2 +-
17 src/options.cpp          | 6 +++---
18 4 files changed, 11 insertions(+), 8 deletions(-)
19
20diff --git a/doc/glmark2.1.in b/doc/glmark2.1.in
21index 015ba20..1f4a047 100644
22--- a/doc/glmark2.1.in
23+++ b/doc/glmark2.1.in
24@@ -38,7 +38,7 @@ Render to an off-screen surface
25 The visual configuration to use for the rendering target:
26 \'id=ID:red=R:green=G:blue=B:alpha=A:buffer=BUF:stencil=STENCIL:samples=SAMPLES'.
27 The parameters may be defined in any order, and any omitted parameters assume a
28-default value of '0' (id, stencil, samples) or '1' (red, green, blue, alpha, buffer).
29+default value of '0' (id, samples), -1 (stencil) or '1' (red, green, blue, alpha, buffer).
30 If 'id' is set to a non-zero value, all other parameters are ignored
31 .TP
32 \fB\-\-reuse\-context\fR
33diff --git a/src/gl-visual-config.cpp b/src/gl-visual-config.cpp
34index de92f93..665f53a 100644
35--- a/src/gl-visual-config.cpp
36+++ b/src/gl-visual-config.cpp
37@@ -26,7 +26,7 @@
38 #include <vector>
39
40 GLVisualConfig::GLVisualConfig(const std::string &s) :
41-    id(0), red(1), green(1), blue(1), alpha(1), depth(1), stencil(0), buffer(1), samples(0)
42+    GLVisualConfig()
43 {
44     std::vector<std::string> elems;
45
46@@ -85,7 +85,7 @@ GLVisualConfig::match_score(const GLVisualConfig &target) const
47     score += score_component(blue, target.blue, 4);
48     score += score_component(alpha, target.alpha, 4);
49     score += score_component(depth, target.depth, 1);
50-    score += score_component(stencil, target.stencil, 0);
51+    score += score_component(stencil, target.stencil, 1);
52     score += score_component(buffer, target.buffer, 1);
53     score += score_component(samples, target.samples, -1);
54
55@@ -135,11 +135,14 @@ GLVisualConfig::score_component(int component, int target, int scale) const
56          * score for all components ranges from [0,MAXIMUM_COMPONENT_SCORE).
57          * If scale > 0, we reward the largest positive difference from target,
58          * otherwise the smallest positive difference from target.
59+         * We also reward the smallest positive difference from the target,
60+         * if the target < 0, i.e., we don't care about this value.
61          */
62         int diff = std::abs(scale) * (component - target);
63         if (diff > 0)
64         {
65-            score = scale < 0 ? MAXIMUM_COMPONENT_SCORE - diff : diff;
66+            score = (scale < 0 || target < 0) ?
67+                    MAXIMUM_COMPONENT_SCORE - diff : diff;
68             score = std::min(MAXIMUM_COMPONENT_SCORE, score);
69             score = std::max(0, score);
70         }
71diff --git a/src/gl-visual-config.h b/src/gl-visual-config.h
72index b28473f..013ce14 100644
73--- a/src/gl-visual-config.h
74+++ b/src/gl-visual-config.h
75@@ -31,7 +31,7 @@ class GLVisualConfig
76 {
77 public:
78     GLVisualConfig():
79-        id(0), red(1), green(1), blue(1), alpha(1), depth(1), stencil(0), buffer(1), samples(0) {}
80+        id(0), red(1), green(1), blue(1), alpha(1), depth(1), stencil(-1), buffer(1), samples(0) {}
81     GLVisualConfig(const std::string &s);
82
83     /**
84diff --git a/src/options.cpp b/src/options.cpp
85index 8d1ec16..3a31d3d 100644
86--- a/src/options.cpp
87+++ b/src/options.cpp
88@@ -213,9 +213,9 @@ Options::print_help()
89            "                         target: 'id=ID:red=R:green=G:blue=B:alpha=A:buffer=BUF:\n"
90            "                         stencil=STENCIL:samples=SAMPLES'. The parameters may be\n"
91            "                         defined in any order, and any omitted parameters assume a\n"
92-           "                         default value of '0' (id, stencil, samples) or '1' (red,\n"
93-           "                         green, blue, alpha, buffer). If 'id' is set to a non-zero\n"
94-           "                         value, all other parameters are ignored\n"
95+           "                         default value of '0' (id, samples), '-1' (stencil) or\n"
96+           "                         '1' (red, green, blue, alpha, buffer). If 'id' is set to\n"
97+           "                         a non-zero value, all other parameters are ignored\n"
98            "      --reuse-context    Use a single context for all scenes\n"
99            "                         (by default, each scene gets its own context)\n"
100            "  -s, --size WxH         Size of the output window (default: 800x600)\n"
101--
1022.44.0
103
104