Module: Mesa
Branch: main
Commit: e2fa6ec73b7423092abc958022cfecc7afb659f3
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e2fa6ec73b7423092abc958022cfecc7afb659f3

Author: Dave Airlie <[email protected]>
Date:   Thu May 25 11:31:44 2023 +1000

radv/video: rework stream handle generation.

This shouldn't change anything, except move some calcs to an
earlier spot to avoid redoing them

Reviewed-by: Lynne <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23227>

---

 src/amd/vulkan/radv_private.h |  2 ++
 src/amd/vulkan/radv_video.c   | 20 ++++++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 99307f46b0b..88068fc4a05 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -376,6 +376,8 @@ struct radv_physical_device {
    } vid_dec_reg;
    enum amd_ip_type vid_decode_ip;
    uint32_t vid_addr_gfx_mode;
+   uint32_t stream_handle_base;
+   uint32_t stream_handle_counter;
 };
 
 uint32_t radv_find_memory_index(const struct radv_physical_device *pdevice, 
VkMemoryPropertyFlags flags);
diff --git a/src/amd/vulkan/radv_video.c b/src/amd/vulkan/radv_video.c
index 6745f4acd59..983a6b1fbf4 100644
--- a/src/amd/vulkan/radv_video.c
+++ b/src/amd/vulkan/radv_video.c
@@ -97,17 +97,12 @@ radv_vcn_sq_tail(struct radeon_cmdbuf *cs,
 }
 
 /* generate an stream handle */
-static unsigned si_vid_alloc_stream_handle()
+static
+unsigned si_vid_alloc_stream_handle(struct radv_physical_device *pdevice)
 {
-   static unsigned counter = 0;
-   unsigned stream_handle = 0;
-   unsigned pid = getpid();
-   int i;
+   unsigned stream_handle = pdevice->stream_handle_base;
 
-   for (i = 0; i < 32; ++i)
-      stream_handle |= ((pid >> i) & 1) << (31 - i);
-
-   stream_handle ^= ++counter;
+   stream_handle ^= ++pdevice->stream_handle_counter;
    return stream_handle;
 }
 
@@ -122,6 +117,11 @@ radv_init_physical_device_decoder(struct 
radv_physical_device *pdevice)
    else
       pdevice->vid_decode_ip = AMD_IP_VCN_DEC;
 
+   pdevice->stream_handle_counter = 0;
+   pdevice->stream_handle_base = 0;
+
+   pdevice->stream_handle_base = util_bitreverse(getpid());
+
    pdevice->vid_addr_gfx_mode = RDECODE_ARRAY_MODE_LINEAR;
 
    switch (pdevice->rad_info.family) {
@@ -297,7 +297,7 @@ radv_CreateVideoSessionKHR(VkDevice _device,
       return VK_ERROR_FEATURE_NOT_PRESENT;
    }
 
-   vid->stream_handle = si_vid_alloc_stream_handle();
+   vid->stream_handle = si_vid_alloc_stream_handle(device->physical_device);
    vid->dbg_frame_cnt = 0;
    vid->db_alignment = (device->physical_device->rad_info.family >= 
CHIP_RENOIR &&
                         vid->vk.max_coded.width > 32 &&

Reply via email to