Skip to content

Commit 801ee2a

Browse files
Development/picky gpus (#929)
* Compositor: Only set the modifiers of the used planes * Compositor: Extend docs with how to enable debug in the gpu driver * Compositor: tweaked the tracing a bit * Compositor: replaced (f)printf by tracing * Update GBM.cpp --------- Co-authored-by: Pierre Wielders <pierre@wielders.net>
1 parent 9b9ee6a commit 801ee2a

File tree

10 files changed

+159
-38
lines changed

10 files changed

+159
-38
lines changed

Compositor/lib/Mesa/README.md

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,46 @@ grep "VSync.*called" /var/log/thunder.log | tail -10
283283
# CPU usage tracking
284284
top -p $(pidof Thunder)
285285
```
286+
## DRM Debug Commands
286287

287-
### Debug Commands
288+
### Enable Debug Logging
289+
290+
#### Check and Mount debugfs
291+
292+
```bash
293+
# Check if debugfs is mounted
294+
mount | grep debugfs
295+
296+
# Mount debugfs (if not already mounted)
297+
sudo mount -t debugfs none /sys/kernel/debug
298+
299+
# Make it persistent across reboots (optional)
300+
echo "debugfs /sys/kernel/debug debugfs defaults 0 0" | sudo tee -a /etc/fstab
301+
```
302+
303+
#### Enable DRM Kernel Debug Output
304+
305+
```bash
306+
# Enable DRM debug logging
307+
# Debug levels:
308+
# 0x01 - Core DRM
309+
# 0x02 - Driver-specific
310+
# 0x04 - KMS (mode setting)
311+
# 0x08 - Prime (buffer sharing)
312+
# 0x10 - Atomic
313+
# 0x1f - All common categories
314+
echo 0x1f | sudo tee /sys/module/drm/parameters/debug
315+
316+
# Watch kernel logs in real-time
317+
sudo dmesg -wH
318+
319+
# Disable debug logging when done
320+
echo 0 | sudo tee /sys/module/drm/parameters/debug
321+
```
322+
323+
### DRM Information Commands
324+
325+
#### Basic DRM Information
288326

289327
```bash
290328
# DRM connector info
@@ -293,9 +331,74 @@ modetest -M <gpu> -c
293331
# Display timing info
294332
modetest -M <gpu> -w <connector>:<property>:<value>
295333

334+
# Show all planes and their capabilities (including format/modifier support)
335+
modetest -M <gpu> -p
336+
337+
# List available DRM devices
338+
ls /sys/kernel/debug/dri/
339+
```
340+
341+
#### Detailed State Information
342+
343+
```bash
296344
# Buffer info
297345
cat /sys/kernel/debug/dri/0/framebuffer
346+
347+
# Full DRM state (connectors, CRTCs, planes, properties)
348+
sudo cat /sys/kernel/debug/dri/0/state
349+
350+
# Check specific VC4 info (Broadcom/Raspberry Pi)
351+
sudo cat /sys/kernel/debug/dri/0/vc4_*
352+
```
353+
354+
### Example: Debug Framebuffer Creation Issues
355+
356+
```bash
357+
# 1. Enable DRM debugging
358+
echo 0x1f | sudo tee /sys/module/drm/parameters/debug
359+
360+
# 2. Run your application in another terminal
361+
362+
# 3. Monitor kernel logs for DRM-specific messages
363+
sudo dmesg | grep -i drm
364+
365+
# 4. Look for specific errors
366+
sudo dmesg | grep -i "modifier\|addfb\|framebuffer"
367+
368+
# 5. Disable debugging when done
369+
echo 0 | sudo tee /sys/module/drm/parameters/debug
370+
```
371+
372+
### Common Issues and Their Debug Output
373+
374+
#### Modifier-related Issues
375+
376+
When you see errors like:
377+
```
378+
non-zero modifier for unused plane
379+
```
380+
381+
This indicates that modifiers are being set for unused planes. Only active planes should have non-zero modifiers.
382+
383+
#### Format Not Supported
384+
298385
```
386+
unsupported pixel format
387+
```
388+
389+
Use `modetest -M <gpu> -p` to check which formats and modifiers are supported by each plane.
390+
391+
#### Invalid Argument (EINVAL)
392+
393+
```
394+
ret=-22
395+
```
396+
397+
Common causes:
398+
- Incorrect modifier for unused planes
399+
- Format/modifier combination not supported by hardware
400+
- Invalid buffer dimensions or stride
401+
299402

300403
## 🤝 Contributing
301404

Compositor/lib/Mesa/backend/src/DRM/Atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace Compositor {
9494
ASSERT(_request != nullptr);
9595

9696
if (propertyId == DRM::InvalidIdentifier) {
97-
TRACE(Trace::Error, ("ObjectId[%u] property not found.", objectId));
97+
TRACE(Trace::Warning, ("ObjectId[%u] property not found.", objectId));
9898
} else {
9999
int presult(0);
100100

Compositor/lib/Mesa/buffer/src/GBM/GBM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ namespace {
5757
}
5858

5959
if (fmt == NULL) {
60-
fprintf(stderr, "unsupported format %" PRIu32 "\n", formatIn);
60+
TRACE_GLOBAL(Trace::Error, ("unsupported format %" PRIu32, formatIn));
6161
return;
6262
}
6363

6464
FILE* filePointer = fopen(filename.c_str(), "wb");
6565

6666
if (filePointer == NULL) {
67-
fprintf(stderr, "failed to open output file\n");
67+
TRACE_GLOBAL(Trace::Error, ("Failed to open output file"));
6868
return;
6969
}
7070

Compositor/lib/Mesa/drm/DRM.cpp

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,12 @@ namespace Compositor {
419419

420420
uint16_t nPlanes(0);
421421

422-
// buffer->Lock();
423-
424422
std::array<uint32_t, 4> handles = { 0, 0, 0, 0 };
425423
std::array<uint32_t, 4> pitches = { 0, 0, 0, 0 };
426424
std::array<uint32_t, 4> offsets = { 0, 0, 0, 0 };
427-
std::array<uint64_t, 4> modifiers;
425+
std::array<uint64_t, 4> modifiers = { 0, 0, 0, 0 };
428426

429-
modifiers.fill(buffer->Modifier());
427+
uint64_t bufferModifier = buffer->Modifier();
430428

431429
Exchange::IGraphicsBuffer::IIterator* planes = buffer->Acquire(Compositor::DefaultTimeoutMs);
432430
ASSERT(planes != nullptr);
@@ -435,50 +433,71 @@ namespace Compositor {
435433
ASSERT(planes->IsValid() == true);
436434

437435
if (drmPrimeFDToHandle(cardFd, planes->Descriptor(), &handles[nPlanes]) != 0) {
438-
TRACE_GLOBAL(Trace::Error, ("Failed to acquirer drm handle from plane accessor"));
436+
TRACE_GLOBAL(Trace::Error, ("Failed to acquire drm handle from plane accessor"));
439437
CloseDrmHandles(cardFd, handles);
440-
break;
438+
buffer->Relinquish();
439+
return 0;
441440
}
442441

443442
pitches[nPlanes] = planes->Stride();
444443
offsets[nPlanes] = planes->Offset();
444+
modifiers[nPlanes] = bufferModifier;
445445

446446
++nPlanes;
447447
}
448448

449449
buffer->Relinquish();
450450

451-
if (modifierSupported && buffer->Modifier() != DRM_FORMAT_MOD_INVALID) {
451+
TRACE_GLOBAL(Trace::Information, ("Attempting FB creation: %ux%u, format=0x%x, modifier=0x%" PRIX64 ", nPlanes=%u",
452+
buffer->Width(), buffer->Height(), buffer->Format(), buffer->Modifier(), nPlanes));
452453

453-
if (drmModeAddFB2WithModifiers(cardFd, buffer->Width(), buffer->Height(), buffer->Format(), handles.data(), pitches.data(), offsets.data(), modifiers.data(), &framebufferId, DRM_MODE_FB_MODIFIERS) != 0) {
454-
TRACE_GLOBAL(Trace::Error, ("Failed to allocate drm framebuffer with modifiers"));
455-
}
456-
} else {
457-
if (buffer->Modifier() != DRM_FORMAT_MOD_INVALID && buffer->Modifier() != DRM_FORMAT_MOD_LINEAR) {
458-
TRACE_GLOBAL(Trace::Error, ("Cannot import drm framebuffer with explicit modifier 0x%" PRIX64, buffer->Modifier()));
459-
return 0;
454+
if (modifierSupported && buffer->Modifier() != DRM_FORMAT_MOD_INVALID) {
455+
int ret = drmModeAddFB2WithModifiers(cardFd, buffer->Width(), buffer->Height(),
456+
buffer->Format(), handles.data(), pitches.data(),
457+
offsets.data(), modifiers.data(), &framebufferId,
458+
DRM_MODE_FB_MODIFIERS);
459+
460+
if (ret != 0) {
461+
TRACE_GLOBAL(Trace::Warning, ("Failed to allocate drm framebuffer with modifiers (error: %d, %s), falling back to drmModeAddFB2", ret, strerror(errno)));
462+
framebufferId = 0; // Reset in case it was partially set
463+
} else {
464+
TRACE_GLOBAL(Trace::Information, ("Successfully created framebuffer with modifiers"));
465+
CloseDrmHandles(cardFd, handles);
466+
return framebufferId;
460467
}
468+
}
469+
470+
if (buffer->Modifier() != DRM_FORMAT_MOD_INVALID && buffer->Modifier() != DRM_FORMAT_MOD_LINEAR) {
471+
TRACE_GLOBAL(Trace::Warning, ("Cannot import drm framebuffer with explicit modifier 0x%" PRIX64 " without modifier support, trying anyway", buffer->Modifier()));
472+
}
461473

462-
int ret = drmModeAddFB2(cardFd, buffer->Width(), buffer->Height(), buffer->Format(), handles.data(), pitches.data(), offsets.data(), &framebufferId, 0);
474+
int ret = drmModeAddFB2(cardFd, buffer->Width(), buffer->Height(), buffer->Format(), handles.data(), pitches.data(), offsets.data(), &framebufferId, 0);
463475

464-
if (ret != 0 && buffer->Format() == DRM_FORMAT_ARGB8888 /*&& nPlanes == 1*/ && offsets[0] == 0) {
465-
TRACE_GLOBAL(Trace::Error, ("Failed to allocate drm framebuffer (%s), falling back to old school drmModeAddFB", strerror(-ret)));
476+
if (ret != 0) {
477+
TRACE_GLOBAL(Trace::Warning, ("Failed to allocate drm framebuffer with drmModeAddFB2 (%s), trying legacy drmModeAddFB", strerror(-ret)));
466478

479+
// Last resort: old-school drmModeAddFB (only works for single-plane ARGB8888)
480+
if (buffer->Format() == DRM_FORMAT_ARGB8888 && nPlanes == 1 && offsets[0] == 0) {
467481
uint32_t depth = 32;
468482
uint32_t bpp = 32;
469483

470484
if (drmModeAddFB(cardFd, buffer->Width(), buffer->Height(), depth, bpp, pitches[0], handles[0], &framebufferId) != 0) {
471-
TRACE_GLOBAL(Trace::Error, ("Failed to allocate a drm framebuffer the old school way..."));
485+
TRACE_GLOBAL(Trace::Error, ("Failed to allocate a drm framebuffer with legacy method"));
486+
} else {
487+
TRACE_GLOBAL(Trace::Information, ("Successfully created framebuffer with legacy method"));
472488
}
473-
474-
} else if (ret != 0) {
475-
TRACE_GLOBAL(Trace::Error, ("Failed to allocate a drm framebuffer..."));
489+
} else {
490+
TRACE_GLOBAL(Trace::Error, ("Failed to allocate a drm framebuffer with all methods"));
476491
}
492+
} else {
493+
TRACE_GLOBAL(Trace::Information, ("Successfully created framebuffer without modifiers"));
477494
}
478495

479496
CloseDrmHandles(cardFd, handles);
480497

481-
TRACE_GLOBAL(Trace::Information, ("DRM framebuffer object %u allocated for buffer %p", framebufferId, buffer));
498+
if (framebufferId > 0) {
499+
TRACE_GLOBAL(Trace::Information, ("DRM framebuffer object %u allocated for buffer %p", framebufferId, buffer));
500+
}
482501

483502
return framebufferId;
484503
}

Compositor/lib/Mesa/renderer/test/BaseTest.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class BaseTest {
2222

2323
virtual void Presented(const Compositor::IOutput* output, const uint64_t sequence, const uint64_t time) override
2424
{
25-
std::cerr << "Presented!" << std::endl;
2625
_parent.HandleVSync(output, sequence, time);
2726
}
2827

Compositor/lib/Mesa/renderer/test/testclear.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ int main(int argc, char* argv[])
202202
const std::map<std::string, std::vector<std::string>> modules = {
203203
{ "CompositorRenderTest", { "" } },
204204
{ "CompositorBuffer", { "Error", "Information" } },
205-
{ "CompositorBackend", { "Error", "Information" } },
205+
{ "CompositorBackend", { "Error" } },
206206
{ "CompositorRenderer", { "Error", "Warning", "Information" } },
207-
{ "DRMCommon", { "Error", "Information" } }
207+
{ "DRMCommon", { "Error", "Warning", "Information" } }
208208
};
209209

210210
for (const auto& module_entry : modules) {

Compositor/lib/Mesa/renderer/test/testdmabuf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ int main(int argc, char* argv[])
282282
const std::map<std::string, std::vector<std::string>> modules = {
283283
{ "CompositorRenderTest", { "" } },
284284
{ "CompositorBuffer", { "Error", "Information" } },
285-
{ "CompositorBackend", { "Error", "Information" } },
285+
{ "CompositorBackend", { "Error" } },
286286
{ "CompositorRenderer", { "Error", "Warning", "Information" } },
287-
{ "DRMCommon", { "Error", "Information" } }
287+
{ "DRMCommon", { "Error", "Warning", "Information" } }
288288
};
289289

290290
for (const auto& module_entry : modules) {

Compositor/lib/Mesa/renderer/test/testquads.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ int main(int argc, char* argv[])
191191
const std::map<std::string, std::vector<std::string>> modules = {
192192
{ "CompositorRenderTest", { "" } },
193193
{ "CompositorBuffer", { "Error", "Information" } },
194-
{ "CompositorBackend", { "Error", "Information" } },
194+
{ "CompositorBackend", { "Error" } },
195195
{ "CompositorRenderer", { "Error", "Warning", "Information" } },
196-
{ "DRMCommon", { "Error", "Information" } }
196+
{ "DRMCommon", { "Error", "Warning", "Information" } }
197197
};
198198

199199
for (const auto& module_entry : modules) {

Compositor/lib/Mesa/renderer/test/testtexture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ int main(int argc, char* argv[])
209209
const std::map<std::string, std::vector<std::string>> modules = {
210210
{ "CompositorRenderTest", { "" } },
211211
{ "CompositorBuffer", { "Error", "Information" } },
212-
{ "CompositorBackend", { "Error", "Information" } },
212+
{ "CompositorBackend", { "Error" } },
213213
{ "CompositorRenderer", { "Error", "Warning", "Information" } },
214-
{ "DRMCommon", { "Error", "Information" } }
214+
{ "DRMCommon", { "Error", "Warning", "Information" } }
215215
};
216216

217217
for (const auto& module_entry : modules) {

Compositor/lib/Mesa/renderer/test/texturebuffer/DmaBuffer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ namespace Compositor {
133133
&_modifiers);
134134

135135
if (!queried) {
136-
printf("Failed to query EGL Image.\n");
136+
TRACE(Trace::Error, ("Failed to query EGL Image"));
137137
}
138138

139139
ASSERT(queried);
@@ -146,12 +146,12 @@ namespace Compositor {
146146
&_offset);
147147

148148
if (!exported) {
149-
printf("Failed to export EGL Image to a DMA buffer.\n");
149+
TRACE(Trace::Error, ("Failed to export EGL Image to a DMA buffer"));
150150
}
151151

152152
ASSERT(exported);
153153

154-
printf("DMA buffer available on descriptor %d.\n", _id);
154+
TRACE(Trace::Information, ("DMA buffer available on descriptor %d.", _id));
155155

156156
glBindTexture(_target, 0);
157157
}

0 commit comments

Comments
 (0)