~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/gallium/auxiliary/pipebuffer/pb_cache.h

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**************************************************************************
2
 
 *
3
 
 * Copyright 2007-2008 VMware, Inc.
4
 
 * Copyright 2015 Advanced Micro Devices, Inc.
5
 
 * All Rights Reserved.
6
 
 *
7
 
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 
 * copy of this software and associated documentation files (the
9
 
 * "Software"), to deal in the Software without restriction, including
10
 
 * without limitation the rights to use, copy, modify, merge, publish,
11
 
 * distribute, sub license, and/or sell copies of the Software, and to
12
 
 * permit persons to whom the Software is furnished to do so, subject to
13
 
 * the following conditions:
14
 
 *
15
 
 * The above copyright notice and this permission notice (including the
16
 
 * next paragraph) shall be included in all copies or substantial portions
17
 
 * of the Software.
18
 
 *
19
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22
 
 * IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
23
 
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
 
 *
27
 
 **************************************************************************/
28
 
 
29
 
#ifndef PB_CACHE_H
30
 
#define PB_CACHE_H
31
 
 
32
 
#include "pb_buffer.h"
33
 
#include "util/simple_mtx.h"
34
 
#include "util/list.h"
35
 
#include "os/os_thread.h"
36
 
 
37
 
/**
38
 
 * Statically inserted into the driver-specific buffer structure.
39
 
 */
40
 
struct pb_cache_entry
41
 
{
42
 
   struct list_head head;
43
 
   struct pb_buffer *buffer; /**< Pointer to the structure this is part of. */
44
 
   struct pb_cache *mgr;
45
 
   int64_t start, end; /**< Caching time interval */
46
 
   unsigned bucket_index;
47
 
};
48
 
 
49
 
struct pb_cache
50
 
{
51
 
   /* The cache is divided into buckets for minimizing cache misses.
52
 
    * The driver controls which buffer goes into which bucket.
53
 
    */
54
 
   struct list_head *buckets;
55
 
 
56
 
   simple_mtx_t mutex;
57
 
   void *winsys;
58
 
   uint64_t cache_size;
59
 
   uint64_t max_cache_size;
60
 
   unsigned num_heaps;
61
 
   unsigned usecs;
62
 
   unsigned num_buffers;
63
 
   unsigned bypass_usage;
64
 
   float size_factor;
65
 
 
66
 
   void (*destroy_buffer)(void *winsys, struct pb_buffer *buf);
67
 
   bool (*can_reclaim)(void *winsys, struct pb_buffer *buf);
68
 
};
69
 
 
70
 
void pb_cache_add_buffer(struct pb_cache_entry *entry);
71
 
struct pb_buffer *pb_cache_reclaim_buffer(struct pb_cache *mgr, pb_size size,
72
 
                                          unsigned alignment, unsigned usage,
73
 
                                          unsigned bucket_index);
74
 
void pb_cache_release_all_buffers(struct pb_cache *mgr);
75
 
void pb_cache_init_entry(struct pb_cache *mgr, struct pb_cache_entry *entry,
76
 
                         struct pb_buffer *buf, unsigned bucket_index);
77
 
void pb_cache_init(struct pb_cache *mgr, uint num_heaps,
78
 
                   uint usecs, float size_factor,
79
 
                   unsigned bypass_usage, uint64_t maximum_cache_size,
80
 
                   void *winsys,
81
 
                   void (*destroy_buffer)(void *winsys, struct pb_buffer *buf),
82
 
                   bool (*can_reclaim)(void *winsys, struct pb_buffer *buf));
83
 
void pb_cache_deinit(struct pb_cache *mgr);
84
 
 
85
 
#endif