Skip to contentSkip to conversation

drm/fourcc: introduce DRM_FOURCC_STANDALONE guard

PATCH Superseded Emil Velikov 3 participants 15 messages Feb 2, 2021 – Feb 4, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/fourcc: introduce DRM_FOURCC_STANDALONE guard

Currently, the drm_fourcc.h header depends on drm.h for __u32 and __u64. At the same time drm.h pulls a lot of unneeded symbols.

Add new guard DRM_FOURCC_STANDALONE, which when set will use local declaration of said symbols.

When used on linux - this is a trivial but only when building in strict c99 mode. One is welcome to ignore the warning, silence it or use c11. If neither of the three is an option, then do _not_ set the new guard.

Cc James Park <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Simon Ser <[email protected]>

---
As mentioned before - there's little point in having yet another header since keeping those in sync has been a PITA in the past.

---
 include/uapi/drm/drm_fourcc.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
include/uapi/drm/drm_fourcc.h +19 -0
index 6f0628eb13a6..c1522902f6c9 100644
@@ -24,7 +24,26 @@
 #ifndef DRM_FOURCC_H
 #define DRM_FOURCC_H
 
+/*
+ * Define DRM_FOURCC_STANDALONE you're interested only FOURCC and do not want
+ * to pull drm.h into your application.
+ */
+#ifdef DRM_FOURCC_STANDALONE
+#if defined(__linux__)
+
+#include <linux/types.h>
+
+#else /* One of the BSDs */
+
+#include <stdint.h>
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+
+#endif /* __linux __ */
+
+#else
 #include "drm.h"
+#endif /* DRM_FOURCC_STANDALONE */
 
 #if defined(__cplusplus)
 extern "C" {
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 54 lines · Emil Velikov

Currently, the drm_fourcc.h header depends on drm.h for __u32 and __u64. At the same time drm.h pulls a lot of unneeded symbols.

Add new guard DRM_FOURCC_STANDALONE, which when set will use local declaration of said symbols.

When used on linux - this is a trivial but only when building in strict c99 mode. One is welcome to ignore the warning, silence it or use c11. If neither of the three is an option, then do _not_ set the new guard.

Cc James Park <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Simon Ser <[email protected]>

---
As mentioned before - there's little point in having yet another header since keeping those in sync has been a PITA in the past.

---
 include/uapi/drm/drm_fourcc.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
include/uapi/drm/drm_fourcc.h +19 -1
index 6f0628eb13a6..c1522902f6c9 100644
@@ -24,7 +24,26 @@
 #ifndef DRM_FOURCC_H
 #define DRM_FOURCC_H
 
+/*
+ * Define DRM_FOURCC_STANDALONE you're interested only FOURCC and do not want
+ * to pull drm.h into your application.
+ */
+#ifdef DRM_FOURCC_STANDALONE
+#if defined(__linux__)
+
+#include <linux/types.h>
+
+#else /* One of the BSDs */
+
+#include <stdint.h>
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+
+#endif /* __linux __ */
+
+#else
 #include "drm.h"
+#endif /* DRM_FOURCC_STANDALONE */
 
 #if defined(__cplusplus)
 extern "C" {
--
Quoted 2 lines

2.30.0

One of my earlier solutions similarly would have forced people to deal with duplicate typedefs, and we arrived at the current solution because we didn't want to burden anyone with that. I feel like having the extra include-guarded file is the lesser of evils. If it helps the patch go through, then I'd drop my preference but I really think the current solution is better.

- James
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
Quoted 53 lines · James Park
Quoted 51 lines · Emil Velikov

Currently, the drm_fourcc.h header depends on drm.h for __u32 and __u64. At the same time drm.h pulls a lot of unneeded symbols.

Add new guard DRM_FOURCC_STANDALONE, which when set will use local declaration of said symbols.

When used on linux - this is a trivial but only when building in strict c99 mode. One is welcome to ignore the warning, silence it or use c11. If neither of the three is an option, then do _not_ set the new guard.

Cc James Park <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Simon Ser <[email protected]>

---
As mentioned before - there's little point in having yet another header since keeping those in sync has been a PITA in the past.

---
 include/uapi/drm/drm_fourcc.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
include/uapi/drm/drm_fourcc.h +19 -0
index 6f0628eb13a6..c1522902f6c9 100644
@@ -24,7 +24,26 @@
 #ifndef DRM_FOURCC_H
 #define DRM_FOURCC_H
 
+/*
+ * Define DRM_FOURCC_STANDALONE you're interested only FOURCC and do not want
+ * to pull drm.h into your application.
+ */
+#ifdef DRM_FOURCC_STANDALONE
+#if defined(__linux__)
+
+#include <linux/types.h>
+
+#else /* One of the BSDs */
+
+#include <stdint.h>
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+
+#endif /* __linux __ */
+
+#else
 #include "drm.h"
+#endif /* DRM_FOURCC_STANDALONE */
 
Quoted 9 lines
Quoted 5 lines
include/uapi/drm/drm_fourcc.h +0 -1
 #if defined(__cplusplus)
 extern "C" {
--

2.30.0

One of my earlier solutions similarly would have forced people to deal with duplicate typedefs, and we arrived at the current solution because we didn't want to burden anyone with that.

As summed in the commit message the burden is only applicable when all of the following are set:
- non-linux
- force DRM_FOURCC_STANDALONE
- c99 -pedantic

Even then, we're talking about a compilation warning. So yeah - let's keep things short and sweet.

Side note: AFAICT MSVC will not trigger a warning so your logs should be clean.

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 77 lines · Emil Velikov
Quoted 2 lines · James Park

On Tue, Feb 2, 2021 at 2:47 PM Emil Velikov <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

Currently, the drm_fourcc.h header depends on drm.h for __u32 and

__u64.

Quoted 6 lines
Quoted 6 lines

At the same time drm.h pulls a lot of unneeded symbols.

Add new guard DRM_FOURCC_STANDALONE, which when set will use local declaration of said symbols.

When used on linux - this is a trivial but only when building in

strict c99

Quoted 1 line
Quoted 1 line

mode. One is welcome to ignore the warning, silence it or use c11. If

neither

Quoted 13 lines
Quoted 13 lines

of the three is an option, then do _not_ set the new guard.

Cc James Park <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Simon Ser <[email protected]>

---
As mentioned before - there's little point in having yet another header since keeping those in sync has been a PITA in the past.

---
 include/uapi/drm/drm_fourcc.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/include/uapi/drm/drm_fourcc.h

Quoted 9 lines

include/uapi/drm/drm_fourcc.h line 28

Quoted 9 lines

index 6f0628eb13a6..c1522902f6c9 100644

include/uapi/drm/drm_fourcc.h +2 -0
@@ -24,7 +24,26 @@
 #ifndef DRM_FOURCC_H
 #define DRM_FOURCC_H
 
+/*
+ * Define DRM_FOURCC_STANDALONE you're interested only FOURCC and do

not want

Quoted 19 lines
Quoted 19 lines
include/uapi/drm/drm_fourcc.h +17 -0
+ * to pull drm.h into your application.
+ */
+#ifdef DRM_FOURCC_STANDALONE
+#if defined(__linux__)
+
+#include <linux/types.h>
+
+#else /* One of the BSDs */
+
+#include <stdint.h>
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+
+#endif /* __linux __ */
+
+#else
 #include "drm.h"
+#endif /* DRM_FOURCC_STANDALONE */
 
Quoted 9 lines
Quoted 5 lines
include/uapi/drm/drm_fourcc.h +0 -1
 #if defined(__cplusplus)
 extern "C" {
--

2.30.0

One of my earlier solutions similarly would have forced people to deal with duplicate typedefs, and we arrived at the current solution because we didn't want to burden anyone with that.

As summed in the commit message the burden is only applicable when all of the following are set:
- non-linux
- force DRM_FOURCC_STANDALONE
- c99 -pedantic

Quoted 8 lines

Even then, we're talking about a compilation warning. So yeah - let's keep things short and sweet.

Side note: AFAICT MSVC will not trigger a warning so your logs should be clean.

-Emil

I'm having trouble reading your commit message, this sentence in
particular: "When used on linux - this is a trivial but only when building in strict c99 mode."

This asymmetric copy/paste grosses me out so much. I don't think a patch like this should be opinionated about someone's build settings. Am I alone? Doesn't this bother anyone else?

- James

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
In reply to Emil Velikov
Quoted 8 lines · Emil Velikov

As summed in the commit message the burden is only applicable when all of the following are set:
- non-linux
- force DRM_FOURCC_STANDALONE
- c99 -pedantic

Even then, we're talking about a compilation warning. So yeah - let's keep things short and sweet.

Sorry, I don't think this is acceptable. Regardless of your personal preference some projects have -Werror -pendantic, and we shouldn't make them fail the build because of a libdrm header.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 5 lines · On Wednesday, February 3rd, 2021 at 1:56 AM, Emil Velikov…

As summed in the commit message the burden is only applicable when all of the following are set:
- non-linux
- force DRM_FOURCC_STANDALONE
- c99 -pedantic

Oh, and FWIW, this is not a theoretical situation at all. All of these conditions happen to be true on my compositor. It has FreeBSD CI, -Werror, and will use DRM_FOURCC_STANDALONE when available.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
Quoted 9 lines · Simon Ser
Quoted 5 lines · On Wednesday, February 3rd, 2021 at 1:56 AM, Emil Velikov…

As summed in the commit message the burden is only applicable when all of the following are set:
- non-linux
- force DRM_FOURCC_STANDALONE
- c99 -pedantic

Quoted 3 lines

Oh, and FWIW, this is not a theoretical situation at all. All of these conditions happen to be true on my compositor. It has FreeBSD CI, -Werror, and will use DRM_FOURCC_STANDALONE when available.

There are ways to disable [1] or silence [2] this - are you intentionally ignoring them?
Or the goal here is to 'fix' the kernel for a very uncommon non-linux use-case?

-Emil

[1] pragma GCC diagnostic warning "-Wpedantic"
[2] pragma GCC diagnostic ignored or -std=c11
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
Quoted 10 lines · Emil Velikov
Quoted 9 lines · Simon Ser
Quoted 5 lines · On Wednesday, February 3rd, 2021 at 1:56 AM, Emil Velikov…

As summed in the commit message the burden is only applicable when all of the following are set:
- non-linux
- force DRM_FOURCC_STANDALONE
- c99 -pedantic

Quoted 6 lines
Quoted 3 lines

Oh, and FWIW, this is not a theoretical situation at all. All of these conditions happen to be true on my compositor. It has FreeBSD CI, -Werror, and will use DRM_FOURCC_STANDALONE when available.

There are ways to disable [1] or silence [2] this - are you intentionally ignoring them?

We have a policy against pragma. However we already use -std=c11, so in fact wouldn't be affected by this change.

Quoted 1 line

Or the goal here is to 'fix' the kernel for a very uncommon non-linux use-case?

If the kernel doesn't care about non-Linux, why is there an #ifdef __linux__ in the first place?

Quoted 2 lines

[1] pragma GCC diagnostic warning "-Wpedantic"
[2] pragma GCC diagnostic ignored or -std=c11

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw
Quoted 17 lines · Simon Ser
Quoted 14 lines · Emil Velikov
Quoted 12 lines · Simon Ser
Quoted 5 lines · On Wednesday, February 3rd, 2021 at 1:56 AM, Emil Velikov…

As summed in the commit message the burden is only applicable when all of the following are set:
- non-linux
- force DRM_FOURCC_STANDALONE
- c99 -pedantic

Oh, and FWIW, this is not a theoretical situation at all. All of these conditions happen to be true on my compositor. It has FreeBSD CI, -Werror, and will use DRM_FOURCC_STANDALONE when available.

Quoted 6 lines
Quoted 2 lines

There are ways to disable [1] or silence [2] this - are you intentionally ignoring them?

We have a policy against pragma. However we already use -std=c11, so in fact wouldn't be affected by this change.

No issue then, great. Let's merge this trivial solution and move on to other things.

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw
Quoted 8 lines · Simon Ser
Quoted 2 lines · Emil Velikov

No issue then, great. Let's merge this trivial solution and move on to other things.

Just because one compositor isn't affected isn't an excuse for the kernel to force its users to use a specific C standard.

As said before, there are multiple ways to handle this _without_ introducing yet another UAPI header. I don't see why you're dismissing all of them, can you elaborate?

Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw
Quoted 3 lines · Emil Velikov

As said before, there are multiple ways to handle this without introducing yet another UAPI header. I don't see why you're dismissing all of them, can you elaborate?

Because I hate it when I have to adjust my compiler flags because of some third-party header.

Can you explain what were the past issues with introducing a new header?
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw

Apologies for anything I've said so far that has been harsh. I'd like this discussion to be civil.

I'm not sure if Simon is still on board with a patch given his thumbs up to Erik's comment on the Mesa merge request (which I responded to), but I would also like to know why adding another header file is problematic. I would prefer to keep the definitions deduplicated and make the code robust even for edge cases unless there's a good reason not to. Avoiding an extra file doesn't seem like a good enough reason to me, but I also don't have to maintain codebases that rely on these headers, so maybe there's something I'm overlooking.

Thanks,
James

Quoted 7 lines · Simon Ser
Quoted 3 lines · Emil Velikov

As said before, there are multiple ways to handle this without introducing yet another UAPI header. I don't see why you're dismissing all of them, can you elaborate?

Quoted 5 lines

Because I hate it when I have to adjust my compiler flags because of some third-party header.

Can you explain what were the past issues with introducing a new header?

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#13 lore raw
Quoted 13 lines · James Park

Apologies for anything I've said so far that has been harsh. I'd like this discussion to be civil.

I'm not sure if Simon is still on board with a patch given his thumbs up to Erik's comment on the Mesa merge request (which I responded to), but I would also like to know why adding another header file is problematic. I would prefer to keep the definitions deduplicated and make the code robust even for edge cases unless there's a good reason not to. Avoiding an extra file doesn't seem like a good enough reason to me, but I also don't have to maintain codebases that rely on these headers, so maybe there's something I'm overlooking.

Quoted 16 lines

Thanks,
James

Quoted 12 lines · Simon Ser
Quoted 3 lines · Emil Velikov

As said before, there are multiple ways to handle this without introducing yet another UAPI header. I don't see why you're dismissing all of them, can you elaborate?

Because I hate it when I have to adjust my compiler flags because of some third-party header.

Can you explain what were the past issues with introducing a new header?

And sorry for top-posting. Gmail habits.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#14 lore raw
In reply to Simon Ser
Quoted 10 lines · Simon Ser
Quoted 3 lines · Emil Velikov

As said before, there are multiple ways to handle this without introducing yet another UAPI header. I don't see why you're dismissing all of them, can you elaborate?

Because I hate it when I have to adjust my compiler flags because of some third-party header.

Mentioned it over IRC, but adding here for posterity:
I think it's perfectly normal to be unhappy, angry, etc but please mention that upfront so that we know what we're working with.

In this case, one gets to deal with the warning, if they _explicitly_ opts-in. That said, v2 should be warnings free in virtually any permutation.

Quoted 2 lines

Can you explain what were the past issues with introducing a new header?

Few that come to mind:
- distros shipping partial header set
- mixing headers, be that any of:
- distros shipping kernel headers, as well as libdrm
- system libdrm and local - be that imported or installed to /usr/local/

A bigger annoyance that just came to mind - having the same header name/guard within your project as the one introduced.

So while it may seem like bikeshed, there are many subtle ways where things can go bad :-\

HTH
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel