hk: lock device-wide scratch access

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30981>
This commit is contained in:
Alyssa Rosenzweig
2024-09-02 10:55:41 -04:00
committed by Marge Bot
parent 505fd350bc
commit 22347eb0e9
3 changed files with 30 additions and 4 deletions

View File

@@ -583,21 +583,19 @@ hk_reserve_scratch(struct hk_cmd_buffer *cmd, struct hk_cs *cs,
unsigned preamble_size = (s->b.info.preamble_scratch_size > 0) ? 1 : 0;
/* XXX: need to lock around agx_scratch_alloc... */
/* Note: this uses the hardware stage, not the software stage */
hk_device_alloc_scratch(dev, s->b.info.stage, max_scratch_size);
switch (s->b.info.stage) {
case PIPE_SHADER_FRAGMENT:
agx_scratch_alloc(&dev->scratch.fs, max_scratch_size, 0);
cs->scratch.fs.main = true;
cs->scratch.fs.preamble = MAX2(cs->scratch.fs.preamble, preamble_size);
break;
case PIPE_SHADER_VERTEX:
agx_scratch_alloc(&dev->scratch.vs, max_scratch_size, 0);
cs->scratch.vs.main = true;
cs->scratch.vs.preamble = MAX2(cs->scratch.vs.preamble, preamble_size);
break;
default:
agx_scratch_alloc(&dev->scratch.cs, max_scratch_size, 0);
cs->scratch.cs.main = true;
cs->scratch.cs.preamble = MAX2(cs->scratch.cs.preamble, preamble_size);
break;

View File

@@ -421,6 +421,7 @@ hk_CreateDevice(VkPhysicalDevice physicalDevice,
*pDevice = hk_device_to_handle(dev);
simple_mtx_init(&dev->scratch.lock, mtx_plain);
agx_scratch_init(&dev->dev, &dev->scratch.vs);
agx_scratch_init(&dev->dev, &dev->scratch.fs);
agx_scratch_init(&dev->dev, &dev->scratch.cs);
@@ -475,6 +476,7 @@ hk_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator)
agx_scratch_fini(&dev->scratch.vs);
agx_scratch_fini(&dev->scratch.fs);
agx_scratch_fini(&dev->scratch.cs);
simple_mtx_destroy(&dev->scratch.lock);
hk_destroy_sampler_heap(dev, &dev->samplers);
hk_descriptor_table_finish(dev, &dev->images);

View File

@@ -8,6 +8,7 @@
#pragma once
#include "asahi/lib/agx_device.h"
#include "util/simple_mtx.h"
#include "agx_bg_eot.h"
#include "agx_pack.h"
#include "agx_scratch.h"
@@ -102,6 +103,7 @@ struct hk_device {
struct {
struct agx_scratch vs, fs, cs;
simple_mtx_t lock;
} scratch;
};
@@ -121,3 +123,27 @@ VkResult hk_sampler_heap_add(struct hk_device *dev,
struct hk_rc_sampler **out);
void hk_sampler_heap_remove(struct hk_device *dev, struct hk_rc_sampler *rc);
static inline struct agx_scratch *
hk_device_scratch_locked(struct hk_device *dev, enum pipe_shader_type stage)
{
simple_mtx_assert_locked(&dev->scratch.lock);
switch (stage) {
case PIPE_SHADER_FRAGMENT:
return &dev->scratch.fs;
case PIPE_SHADER_VERTEX:
return &dev->scratch.vs;
default:
return &dev->scratch.cs;
}
}
static inline void
hk_device_alloc_scratch(struct hk_device *dev, enum pipe_shader_type stage,
unsigned size)
{
simple_mtx_lock(&dev->scratch.lock);
agx_scratch_alloc(hk_device_scratch_locked(dev, stage), size, 0);
simple_mtx_unlock(&dev->scratch.lock);
}