Skip to content

Commit e775278

Browse files
kaydenllucasdemarchi
authored andcommitted
drm/xe: Invalidate L3 read-only cachelines for geometry streams too
Historically, the Vertex Fetcher unit has not been an L3 client. That meant that, when a buffer containing vertex data was written to, it was necessary to issue a PIPE_CONTROL::VF Cache Invalidate to invalidate any VF L2 cachelines associated with that buffer, so the new value would be properly read from memory. Since Tigerlake and later, VERTEX_BUFFER_STATE and 3DSTATE_INDEX_BUFFER have included an "L3 Bypass Enable" bit which userspace drivers can set to request that the vertex fetcher unit snoop L3. However, unlike most true L3 clients, the "VF Cache Invalidate" bit continues to only invalidate the VF L2 cache - and not any associated L3 lines. To handle that, PIPE_CONTROL has a new "L3 Read Only Cache Invalidation Bit", which according to the docs, "controls the invalidation of the Geometry streams cached in L3 cache at the top of the pipe." In other words, the vertex and index buffer data that gets cached in L3 when "L3 Bypass Disable" is set. Mesa always sets L3 Bypass Disable so that the VF unit snoops L3, and whenever it issues a VF Cache Invalidate, it also issues a L3 Read Only Cache Invalidate so that both L2 and L3 vertex data is invalidated. xe is issuing VF cache invalidates too (which handles cases like CPU writes to a buffer between GPU batches). Because userspace may enable L3 snooping, it needs to issue an L3 Read Only Cache Invalidate as well. Fixes significant flickering in Firefox on Meteorlake, which was writing to vertex buffers via the CPU between batches; the missing L3 Read Only invalidates were causing the vertex fetcher to read stale data from L3. Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/4460 Fixes: 6ef3bb6 ("drm/xe: enable lite restore") Cc: stable@vger.kernel.org # v6.13+ Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Link: https://lore.kernel.org/r/20250330165923.56410-1-rodrigo.vivi@intel.com Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com> (cherry picked from commit 6167280) Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent dac2d70 commit e775278

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

drivers/gpu/drm/xe/instructions/xe_gpu_commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#define GFX_OP_PIPE_CONTROL(len) ((0x3<<29)|(0x3<<27)|(0x2<<24)|((len)-2))
4343

44+
#define PIPE_CONTROL0_L3_READ_ONLY_CACHE_INVALIDATE BIT(10) /* gen12 */
4445
#define PIPE_CONTROL0_HDC_PIPELINE_FLUSH BIT(9) /* gen12 */
4546

4647
#define PIPE_CONTROL_COMMAND_CACHE_INVALIDATE (1<<29)

drivers/gpu/drm/xe/xe_ring_ops.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ emit_pipe_control(u32 *dw, int i, u32 bit_group_0, u32 bit_group_1, u32 offset,
137137
static int emit_pipe_invalidate(u32 mask_flags, bool invalidate_tlb, u32 *dw,
138138
int i)
139139
{
140-
u32 flags = PIPE_CONTROL_CS_STALL |
140+
u32 flags0 = 0;
141+
u32 flags1 = PIPE_CONTROL_CS_STALL |
141142
PIPE_CONTROL_COMMAND_CACHE_INVALIDATE |
142143
PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
143144
PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
@@ -148,11 +149,15 @@ static int emit_pipe_invalidate(u32 mask_flags, bool invalidate_tlb, u32 *dw,
148149
PIPE_CONTROL_STORE_DATA_INDEX;
149150

150151
if (invalidate_tlb)
151-
flags |= PIPE_CONTROL_TLB_INVALIDATE;
152+
flags1 |= PIPE_CONTROL_TLB_INVALIDATE;
152153

153-
flags &= ~mask_flags;
154+
flags1 &= ~mask_flags;
154155

155-
return emit_pipe_control(dw, i, 0, flags, LRC_PPHWSP_FLUSH_INVAL_SCRATCH_ADDR, 0);
156+
if (flags1 & PIPE_CONTROL_VF_CACHE_INVALIDATE)
157+
flags0 |= PIPE_CONTROL0_L3_READ_ONLY_CACHE_INVALIDATE;
158+
159+
return emit_pipe_control(dw, i, flags0, flags1,
160+
LRC_PPHWSP_FLUSH_INVAL_SCRATCH_ADDR, 0);
156161
}
157162

158163
static int emit_store_imm_ppgtt_posted(u64 addr, u64 value,

0 commit comments

Comments
 (0)