GART write flush error on SI w/ amdgpu
Subsystems (2)
Hi all,
I'm seeing some very strange errors on Verde with CPU readback from GART, and am pretty much out of ideas. Some help would be very much appreciated.
The error manifests with the GL45-CTS.gtf32.GL3Tests.packed_pixels.packed_pixels_pbo test on amdgpu, but *not* on radeon. Here's what the test does:
1. Upload a texture.
2. Read the texture back via a shader that uses shader buffer writes to write data to a buffer that is allocated in GART.
3. The CPU then reads from the buffer -- and sometimes gets stale data.
This sequence is repeated for many sub-tests. There are some sub-tests where the CPU reads stale data from the buffer, i.e. the shader writes simply don't make it to the CPU. The tests vary superficially, e.g. the first failing test is (almost?) always one where data is written in 16-bit words (but there are succeeding sub-tests with 16-bit writes as well).
The bug is *not* a timing issue. Adding even a 1sec delay (sleep(1);) between the fence wait and the return of glMapBuffer does not fix the problem. The data must be stuck in a cache somewhere.
Since the test runs okay with the radeon module, I tried some changes based on comparing the IB submit between radeon and amdgpu, and based on comparing register settings via scans obtained from umr. Some of the things I've tried:
- Set HDP_MISC_CNTL.FLUSH_INVALIDATE_CACHE to 1 (both radeon and amdgpu/gfx9 set this)
- Add SURFACE_SYNC packets preceded by setting CP_COHER_CNTL2 to the vmid (radeon does this)
- Change gfx_v6_0_ring_emit_hdp_invalidate: select ME engine instead of PFP (which seems more logical, and is done by gfx7+), or remove the corresponding WRITE_DATA entirely
None of these changes helped.
What *does* help is adding an artificial wait. Specifically, I'm adding a sequence of
- WRITE_DATA
- CACHE_FLUSH_AND_INV_TS_EVENT (BOTTOM_OF_PIPE_TS has same behavior)
- WAIT_REG_MEM
as can be seen in the attached patch. This works around the problem, but it makes no sense:
Adding the wait sequence *before* the SURFACE_SYNC in ring_emit_fence works around the problem. However(!) it does not actually cause the UMD to wait any longer than before. Without this change, the UMD immediately sees a signaled user fence (and never uses an ioctl to wait), and with this change, it *still* sees a signaled user fence.
Also, note that the way I've hacked the change, the wait sequence is only added for the user fence emit (and I'm using a modified UMD to ensure that there is enough memory to be used by the added wait sequence).
Adding the wait sequence *after* the SURFACE_SYNC *doesn't* work around the problem.
So for whatever reason, the added wait sequence *before* the SURFACE_SYNC encourages some part of the GPU to flush the data from wherever it's stuck, and that's just really bizarre. There must be something really simple I'm missing, and any pointers would be appreciated.
Thanks,
Nicolai
Signature · 2 lines
Lerne, wie die Welt wirklich ist, Aber vergiss niemals, wie sie sein sollte.
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +3 -0
@@ -226,20 +226,23 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,/* wrap the last IB with fence */ if (job && job->uf_addr) {amdgpu_ring_emit_fence (ring, job->vm_id, job->uf_addr, job->uf_sequence,AMDGPU_FENCE_FLAG_64BIT ); }if (patch_offset != ~0 && ring->funcs->patch_cond_exec)amdgpu_ring_patch_cond_exec (ring, patch_offset); +// if (job && ring->funcs->emit_hack) +// ring->funcs->emit_hack(ring, job->vm_id, job->uf_addr + 8); + ring->current_ctx = fence_ctx;if (vm && ring->funcs->emit_switch_buffer)amdgpu_ring_emit_switch_buffer (ring);amdgpu_ring_commit (ring);return 0 ; }/** * amdgpu_ib_pool_init - Init the IB (Indirect Buffer) pool *
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +54 -0
119 lines not on this page · raw message
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): c53a99e5-eea0-17d1-05e6-b6e66746d774-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 7 lines · Nicolai Hähnle
Hi all,
I'm seeing some very strange errors on Verde with CPU readback from GART, and am pretty much out of ideas. Some help would be very much appreciated.
The error manifests with the GL45-CTS.gtf32.GL3Tests.packed_pixels.packed_pixels_pbo test on amdgpu,
but
Quoted 8 lines
*not* on radeon. Here's what the test does:
1. Upload a texture.
2. Read the texture back via a shader that uses shader buffer writes to write data to a buffer that is allocated in GART.
3. The CPU then reads from the buffer -- and sometimes gets stale data.This sequence is repeated for many sub-tests. There are some sub-tests
where
Quoted 10 lines
the CPU reads stale data from the buffer, i.e. the shader writes simply don't make it to the CPU. The tests vary superficially, e.g. the first failing test is (almost?) always one where data is written in 16-bit words (but there are succeeding sub-tests with 16-bit writes as well).
The bug is *not* a timing issue. Adding even a 1sec delay (sleep(1);) between the fence wait and the return of glMapBuffer does not fix the problem. The data must be stuck in a cache somewhere.
Since the test runs okay with the radeon module, I tried some changes
based
Quoted 1 line
on comparing the IB submit between radeon and amdgpu, and based on
comparing
Quoted 4 lines
register settings via scans obtained from umr. Some of the things I've tried:
- Set HDP_MISC_CNTL.FLUSH_INVALIDATE_CACHE to 1 (both radeon and
amdgpu/gfx9
Quoted 4 lines
set this)
- AddSURFACE_SYNCpackets preceded by settingCP_COHER_CNTL2to the vmid (radeon does this)
- Changegfx_v6_0_ring_emit_hdp_invalidate: select ME engine instead of
PFP
Quoted 5 lines
(which seems more logical, and is done by gfx7+), or remove the corresponding
WRITE_DATAentirelyNone of these changes helped.
Quoted 8 lines
What *does* help is adding an artificial wait. Specifically, I'm adding a sequence of
-
WRITE_DATA
-CACHE_FLUSH_AND_INV_TS_EVENT(BOTTOM_OF_PIPE_TShas same behavior)
-WAIT_REG_MEMas can be seen in the attached patch. This works around the problem, but
it
Quoted 3 lines
makes no sense:
Adding the wait sequence *before* the
SURFACE_SYNCinring_emit_fence
works
Quoted 3 lines
around the problem. However(!) it does not actually cause the UMD to wait any longer than before. Without this change, the UMD immediately sees a signaled user fence (and never uses an ioctl to wait), and with this
change,
Quoted 7 lines
it *still* sees a signaled user fence.
Also, note that the way I've hacked the change, the wait sequence is only added for the user fence emit (and I'm using a modified UMD to ensure that there is enough memory to be used by the added wait sequence).
Adding the wait sequence *after* the
SURFACE_SYNC*doesn't* work around
the
Quoted 4 lines
problem.
So for whatever reason, the added wait sequence *before* the
SURFACE_SYNCencourages some part of the GPU to flush the data from wherever it's
stuck,
Quoted 2 lines
and that's just really bizarre. There must be something really simple I'm missing, and any pointers would be appreciated.
Have you tried this?
(quoted diff) +0 -0
b/src/gallium/drivers/radeonsi/si_hw_context.c
index 92c09cb..e6ac0ba 100644
src/gallium/drivers/radeonsi/si_hw_context.c +1 -1
@@ -133,7 +133,8 @@ void si_context_gfx_flush(void *context, unsigned flags,SI_CONTEXT_PS_PARTIAL_FLUSH ;/* DRM 3.1.0 doesn't flush TC for VI correctly. */ -if (ctx->b.chip_class ==VI && ctx->b.screen->info.drm_minor <=1 ) + if ((ctx->b.chip_class == VI && ctx->b.screen->info.drm_minor <= 1)
||
+ (ctx->b.chip_class == SI && ctx->b.screen->info.drm_major == 3))
ctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2 |
SI_CONTEXT_INV_VMEM_L1;One more cache flush there shouldn't hurt.
Also, Mesa uses PFP_SYNC_ME. It shouldn't be necessary, but it's worth a try.
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CAAxE2A7Q=qdxtm6HXF3Py9dYpARvA6+Z4ENkWTCEA572SdNEqw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
BTW, I noticed the flush sequence in the kernel is wrong. The correct flush sequence should be:
1) EVENT_WRITE_EOP - CACHE_FLUSH_AND_INV_TS - write a dword to memory, but no fence/interrupt.
2) WAIT_REG_MEM on the dword to wait for idle before SURFACE_SYNC.
3) SURFACE_SYNC (TC, K$, I$)
4) Write CP_COHER_CNTL2.
5) EVENT_WRITE_EOP - BOTTOM_OF_PIPE_TS - write the fence with the interrupt.
WAIT_REG_MEM wouldn't be needed if we were able to merge CACHE_FLUSH_AND_INV, SURFACE_SYNC, and CP_COHER_CNTL2 into one EOP event.
The main issue with the current flush sequence in radeon and amdgpu is that it doesn't wait for idle before writing CP_COHER_CNTL2 and SURFACE_SYNC. So far we've been able to avoid the bug by waiting for idle in userspace IBs.
Marek
Quoted 97 lines · Marek Olšák
Quoted 72 lines · Nicolai Hähnle
Hi all,
I'm seeing some very strange errors on Verde with CPU readback from GART, and am pretty much out of ideas. Some help would be very much appreciated.
The error manifests with the GL45-CTS.gtf32.GL3Tests.packed_pixels.packed_pixels_pbo test on amdgpu, but
*not* on radeon. Here's what the test does:1. Upload a texture.
2. Read the texture back via a shader that uses shader buffer writes to write data to a buffer that is allocated in GART.
3. The CPU then reads from the buffer -- and sometimes gets stale data.This sequence is repeated for many sub-tests. There are some sub-tests where
the CPU reads stale data from the buffer, i.e. the shader writes simply don't make it to the CPU. The tests vary superficially, e.g. the first failing test is (almost?) always one where data is written in 16-bit words (but there are succeeding sub-tests with 16-bit writes as well).The bug is *not* a timing issue. Adding even a 1sec delay (sleep(1);) between the fence wait and the return of glMapBuffer does not fix the problem. The data must be stuck in a cache somewhere.
Since the test runs okay with the radeon module, I tried some changes based
on comparing the IB submit between radeon and amdgpu, and based on comparing
register settings via scans obtained from umr. Some of the things I've tried:- Set HDP_MISC_CNTL.FLUSH_INVALIDATE_CACHE to 1 (both radeon and amdgpu/gfx9
set this)
- AddSURFACE_SYNCpackets preceded by settingCP_COHER_CNTL2to the vmid (radeon does this)
- Changegfx_v6_0_ring_emit_hdp_invalidate: select ME engine instead of PFP
(which seems more logical, and is done by gfx7+), or remove the correspondingWRITE_DATAentirelyNone of these changes helped.
What *does* help is adding an artificial wait. Specifically, I'm adding a sequence of
-
WRITE_DATA
-CACHE_FLUSH_AND_INV_TS_EVENT(BOTTOM_OF_PIPE_TShas same behavior)
-WAIT_REG_MEMas can be seen in the attached patch. This works around the problem, but it
makes no sense:Adding the wait sequence *before* the
SURFACE_SYNCinring_emit_fenceworks
around the problem. However(!) it does not actually cause the UMD to wait any longer than before. Without this change, the UMD immediately sees a signaled user fence (and never uses an ioctl to wait), and with this change,
it *still* sees a signaled user fence.Also, note that the way I've hacked the change, the wait sequence is only added for the user fence emit (and I'm using a modified UMD to ensure that there is enough memory to be used by the added wait sequence).
Adding the wait sequence *after* the
SURFACE_SYNC*doesn't* work around the
problem.Quoted 5 lines
So for whatever reason, the added wait sequence *before* the
SURFACE_SYNCencourages some part of the GPU to flush the data from wherever it's stuck,
and that's just really bizarre. There must be something really simple I'm missing, and any pointers would be appreciated.Have you tried this?
src/gallium/drivers/radeonsi/si_hw_context.c +1
-1@@ -133,7 +133,8 @@ void si_context_gfx_flush(void *context, unsigned flags,SI_CONTEXT_PS_PARTIAL_FLUSH ;/* DRM 3.1.0 doesn't flush TC for VI correctly. */ -if (ctx->b.chip_class ==VI && ctx->b.screen->info.drm_minor <=1 ) + if ((ctx->b.chip_class == VI && ctx->b.screen->info.drm_minor <= 1)|| + (ctx->b.chip_class == SI && ctx->b.screen->info.drm_major == 3)) ctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2 | SI_CONTEXT_INV_VMEM_L1;
Quoted 6 lines
One more cache flush there shouldn't hurt.
Also, Mesa uses
PFP_SYNC_ME. It shouldn't be necessary, but it's worth a try.Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CAAxE2A7ZApX2aO1nJKwbqMWWjX4ZL6zTdtsCbEA946J2CmtjrQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Am 20.06.2017 um 12:34 schrieb Marek Olšák:
Quoted 10 lines
BTW, I noticed the flush sequence in the kernel is wrong. The correct flush sequence should be:
1)
EVENT_WRITE_EOP-CACHE_FLUSH_AND_INV_TS- write a dword to memory, but no fence/interrupt.
2)WAIT_REG_MEMon the dword to wait for idle beforeSURFACE_SYNC.
3)SURFACE_SYNC(TC, K$, I$)
4) WriteCP_COHER_CNTL2.
5)EVENT_WRITE_EOP-BOTTOM_OF_PIPE_TS- write the fence with the interrupt.
Quoted 8 lines
WAIT_REG_MEMwouldn't be needed if we were able to mergeCACHE_FLUSH_AND_INV,SURFACE_SYNC, andCP_COHER_CNTL2into one EOP event.The main issue with the current flush sequence in radeon and amdgpu is that it doesn't wait for idle before writing
CP_COHER_CNTL2andSURFACE_SYNC. So far we've been able to avoid the bug by waiting for idle in userspace IBs.
Well not waiting for idle between IBs is an explicit requirement, because it is rather bad for performance to do so.
David Zhou, Monk and I worked quite a lot on this to avoid both possible hazard and performance drop.
Christian.
Quoted 103 lines
Marek
Quoted 98 lines · Marek Olšák
Quoted 72 lines · Nicolai Hähnle
Hi all,
I'm seeing some very strange errors on Verde with CPU readback from GART, and am pretty much out of ideas. Some help would be very much appreciated.
The error manifests with the GL45-CTS.gtf32.GL3Tests.packed_pixels.packed_pixels_pbo test on amdgpu, but
*not* on radeon. Here's what the test does:1. Upload a texture.
2. Read the texture back via a shader that uses shader buffer writes to write data to a buffer that is allocated in GART.
3. The CPU then reads from the buffer -- and sometimes gets stale data.This sequence is repeated for many sub-tests. There are some sub-tests where
the CPU reads stale data from the buffer, i.e. the shader writes simply don't make it to the CPU. The tests vary superficially, e.g. the first failing test is (almost?) always one where data is written in 16-bit words (but there are succeeding sub-tests with 16-bit writes as well).The bug is *not* a timing issue. Adding even a 1sec delay (sleep(1);) between the fence wait and the return of glMapBuffer does not fix the problem. The data must be stuck in a cache somewhere.
Since the test runs okay with the radeon module, I tried some changes based
on comparing the IB submit between radeon and amdgpu, and based on comparing
register settings via scans obtained from umr. Some of the things I've tried:- Set HDP_MISC_CNTL.FLUSH_INVALIDATE_CACHE to 1 (both radeon and amdgpu/gfx9
set this)
- AddSURFACE_SYNCpackets preceded by settingCP_COHER_CNTL2to the vmid (radeon does this)
- Changegfx_v6_0_ring_emit_hdp_invalidate: select ME engine instead of PFP
(which seems more logical, and is done by gfx7+), or remove the correspondingWRITE_DATAentirelyNone of these changes helped.
What *does* help is adding an artificial wait. Specifically, I'm adding a sequence of
-
WRITE_DATA
-CACHE_FLUSH_AND_INV_TS_EVENT(BOTTOM_OF_PIPE_TShas same behavior)
-WAIT_REG_MEMas can be seen in the attached patch. This works around the problem, but it
makes no sense:Adding the wait sequence *before* the
SURFACE_SYNCinring_emit_fenceworks
around the problem. However(!) it does not actually cause the UMD to wait any longer than before. Without this change, the UMD immediately sees a signaled user fence (and never uses an ioctl to wait), and with this change,
it *still* sees a signaled user fence.Also, note that the way I've hacked the change, the wait sequence is only added for the user fence emit (and I'm using a modified UMD to ensure that there is enough memory to be used by the added wait sequence).
Adding the wait sequence *after* the
SURFACE_SYNC*doesn't* work around the
problem.Quoted 5 lines
So for whatever reason, the added wait sequence *before* the
SURFACE_SYNCencourages some part of the GPU to flush the data from wherever it's stuck,
and that's just really bizarre. There must be something really simple I'm missing, and any pointers would be appreciated.Have you tried this?
src/gallium/drivers/radeonsi/si_hw_context.c +1
-1@@ -133,7 +133,8 @@ void si_context_gfx_flush(void *context, unsigned flags,SI_CONTEXT_PS_PARTIAL_FLUSH ;/* DRM 3.1.0 doesn't flush TC for VI correctly. */ -if (ctx->b.chip_class ==VI && ctx->b.screen->info.drm_minor <=1 ) + if ((ctx->b.chip_class == VI && ctx->b.screen->info.drm_minor <= 1)|| + (ctx->b.chip_class == SI && ctx->b.screen->info.drm_major == 3)) ctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2 | SI_CONTEXT_INV_VMEM_L1;One more cache flush there shouldn't hurt.
Quoted 8 lines
Quoted 4 lines
Also, Mesa uses
PFP_SYNC_ME. It shouldn't be necessary, but it's worth a try.Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): aeec0bc1-4814-ee82-8e59-d460e74a8ba3-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 23 lines · Christian König
Am 20.06.2017 um 12:34 schrieb Marek Olšák:
Quoted 12 lines
BTW, I noticed the flush sequence in the kernel is wrong. The correct flush sequence should be:
1)
EVENT_WRITE_EOP-CACHE_FLUSH_AND_INV_TS- write a dword to memory, but no fence/interrupt.
2)WAIT_REG_MEMon the dword to wait for idle beforeSURFACE_SYNC.
3)SURFACE_SYNC(TC, K$, I$)
4) WriteCP_COHER_CNTL2.
5)EVENT_WRITE_EOP-BOTTOM_OF_PIPE_TS- write the fence with the interrupt.Quoted 8 lines
WAIT_REG_MEMwouldn't be needed if we were able to mergeCACHE_FLUSH_AND_INV,SURFACE_SYNC, andCP_COHER_CNTL2into one EOP event.The main issue with the current flush sequence in radeon and amdgpu is that it doesn't wait for idle before writing
CP_COHER_CNTL2andSURFACE_SYNC. So far we've been able to avoid the bug by waiting for idle in userspace IBs.
Quoted 5 lines
Well not waiting for idle between IBs is an explicit requirement, because it is rather bad for performance to do so.
David Zhou, Monk and I worked quite a lot on this to avoid both possible hazard and performance drop.
I guess the requirement was ignored for SI. If you don't do the TC flush as part the EOP event, you have to wait for idle before SURFACE_SYNC, because SURFACE_SYNC doesn't wait for idle. It's kinda useless to flush TC when shaders are still in flight.
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CAAxE2A5xuq59iWP=b+8=tCHNm81CGz4piY3EheSfLnVV6tXZLg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 29 lines · Marek Olšák
Quoted 26 lines · Christian König
Am 20.06.2017 um 12:34 schrieb Marek Olšák:
Quoted 12 lines
BTW, I noticed the flush sequence in the kernel is wrong. The correct flush sequence should be:
1)
EVENT_WRITE_EOP-CACHE_FLUSH_AND_INV_TS- write a dword to memory, but no fence/interrupt.
2)WAIT_REG_MEMon the dword to wait for idle beforeSURFACE_SYNC.
3)SURFACE_SYNC(TC, K$, I$)
4) WriteCP_COHER_CNTL2.
5)EVENT_WRITE_EOP-BOTTOM_OF_PIPE_TS- write the fence with the interrupt.Quoted 8 lines
WAIT_REG_MEMwouldn't be needed if we were able to mergeCACHE_FLUSH_AND_INV,SURFACE_SYNC, andCP_COHER_CNTL2into one EOP event.The main issue with the current flush sequence in radeon and amdgpu is that it doesn't wait for idle before writing
CP_COHER_CNTL2andSURFACE_SYNC. So far we've been able to avoid the bug by waiting for idle in userspace IBs.Well not waiting for idle between IBs is an explicit requirement, because it is rather bad for performance to do so.
Quoted 7 lines
Quoted 2 lines
David Zhou, Monk and I worked quite a lot on this to avoid both possible hazard and performance drop.
I guess the requirement was ignored for SI. If you don't do the TC flush as part the EOP event, you have to wait for idle before
SURFACE_SYNC, becauseSURFACE_SYNCdoesn't wait for idle. It's kinda useless to flush TC when shaders are still in flight.
I've been chasing Verde wierdness, did this issue ever get resolved?
Dave.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 10 lines · Marek Olšák
BTW, I noticed the flush sequence in the kernel is wrong. The correct flush sequence should be:
1)
EVENT_WRITE_EOP-CACHE_FLUSH_AND_INV_TS- write a dword to memory, but no fence/interrupt.
2)WAIT_REG_MEMon the dword to wait for idle beforeSURFACE_SYNC.
3)SURFACE_SYNC(TC, K$, I$)
4) WriteCP_COHER_CNTL2.
5)EVENT_WRITE_EOP-BOTTOM_OF_PIPE_TS- write the fence with the interrupt.
Quoted 8 lines
WAIT_REG_MEMwouldn't be needed if we were able to mergeCACHE_FLUSH_AND_INV,SURFACE_SYNC, andCP_COHER_CNTL2into one EOP event.The main issue with the current flush sequence in radeon and amdgpu is that it doesn't wait for idle before writing
CP_COHER_CNTL2andSURFACE_SYNC. So far we've been able to avoid the bug by waiting for idle in userspace IBs.
This is gfx9-only though, right?
Cheers,
Nicolai
Quoted 108 lines
Marek
Quoted 103 lines · Marek Olšák
Quoted 72 lines · Nicolai Hähnle
Hi all,
I'm seeing some very strange errors on Verde with CPU readback from GART, and am pretty much out of ideas. Some help would be very much appreciated.
The error manifests with the GL45-CTS.gtf32.GL3Tests.packed_pixels.packed_pixels_pbo test on amdgpu, but
*not* on radeon. Here's what the test does:1. Upload a texture.
2. Read the texture back via a shader that uses shader buffer writes to write data to a buffer that is allocated in GART.
3. The CPU then reads from the buffer -- and sometimes gets stale data.This sequence is repeated for many sub-tests. There are some sub-tests where
the CPU reads stale data from the buffer, i.e. the shader writes simply don't make it to the CPU. The tests vary superficially, e.g. the first failing test is (almost?) always one where data is written in 16-bit words (but there are succeeding sub-tests with 16-bit writes as well).The bug is *not* a timing issue. Adding even a 1sec delay (sleep(1);) between the fence wait and the return of glMapBuffer does not fix the problem. The data must be stuck in a cache somewhere.
Since the test runs okay with the radeon module, I tried some changes based
on comparing the IB submit between radeon and amdgpu, and based on comparing
register settings via scans obtained from umr. Some of the things I've tried:- Set HDP_MISC_CNTL.FLUSH_INVALIDATE_CACHE to 1 (both radeon and amdgpu/gfx9
set this)
- AddSURFACE_SYNCpackets preceded by settingCP_COHER_CNTL2to the vmid (radeon does this)
- Changegfx_v6_0_ring_emit_hdp_invalidate: select ME engine instead of PFP
(which seems more logical, and is done by gfx7+), or remove the correspondingWRITE_DATAentirelyNone of these changes helped.
What *does* help is adding an artificial wait. Specifically, I'm adding a sequence of
-
WRITE_DATA
-CACHE_FLUSH_AND_INV_TS_EVENT(BOTTOM_OF_PIPE_TShas same behavior)
-WAIT_REG_MEMas can be seen in the attached patch. This works around the problem, but it
makes no sense:Adding the wait sequence *before* the
SURFACE_SYNCinring_emit_fenceworks
around the problem. However(!) it does not actually cause the UMD to wait any longer than before. Without this change, the UMD immediately sees a signaled user fence (and never uses an ioctl to wait), and with this change,
it *still* sees a signaled user fence.Also, note that the way I've hacked the change, the wait sequence is only added for the user fence emit (and I'm using a modified UMD to ensure that there is enough memory to be used by the added wait sequence).
Adding the wait sequence *after* the
SURFACE_SYNC*doesn't* work around the
problem.Quoted 5 lines
So for whatever reason, the added wait sequence *before* the
SURFACE_SYNCencourages some part of the GPU to flush the data from wherever it's stuck,
and that's just really bizarre. There must be something really simple I'm missing, and any pointers would be appreciated.Have you tried this?
src/gallium/drivers/radeonsi/si_hw_context.c +1
-1@@ -133,7 +133,8 @@ void si_context_gfx_flush(void *context, unsigned flags,SI_CONTEXT_PS_PARTIAL_FLUSH ;/* DRM 3.1.0 doesn't flush TC for VI correctly. */ -if (ctx->b.chip_class ==VI && ctx->b.screen->info.drm_minor <=1 ) + if ((ctx->b.chip_class == VI && ctx->b.screen->info.drm_minor <= 1)|| + (ctx->b.chip_class == SI && ctx->b.screen->info.drm_major == 3)) ctx->b.flags |= SI_CONTEXT_INV_GLOBAL_L2 | SI_CONTEXT_INV_VMEM_L1;One more cache flush there shouldn't hurt.
Also, Mesa uses
PFP_SYNC_ME. It shouldn't be necessary, but it's worth a try.Marek
Signature · 6 lines
Lerne, wie die Welt wirklich ist, Aber vergiss niemals, wie sie sein sollte. _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): ed0120b2-f34e-6f95-379f-d038574ec346-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 17 lines · Nicolai Hähnle
Quoted 16 lines · Marek Olšák
BTW, I noticed the flush sequence in the kernel is wrong. The correct flush sequence should be:
1)
EVENT_WRITE_EOP-CACHE_FLUSH_AND_INV_TS- write a dword to memory, but no fence/interrupt.
2)WAIT_REG_MEMon the dword to wait for idle beforeSURFACE_SYNC.
3)SURFACE_SYNC(TC, K$, I$)
4) WriteCP_COHER_CNTL2.
5)EVENT_WRITE_EOP-BOTTOM_OF_PIPE_TS- write the fence with the interrupt.
WAIT_REG_MEMwouldn't be needed if we were able to mergeCACHE_FLUSH_AND_INV,SURFACE_SYNC, andCP_COHER_CNTL2into one EOP event.
Quoted 7 lines
Quoted 4 lines
The main issue with the current flush sequence in radeon and amdgpu is that it doesn't wait for idle before writing
CP_COHER_CNTL2andSURFACE_SYNC. So far we've been able to avoid the bug by waiting for idle in userspace IBs.This is gfx9-only though, right?
No, I'm only talking about SI.
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx