2 * Copyright 2018 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 /* This file implements tests on the si_clearbuffer function. */
30 #define CLEARBUF_MIN 32
31 #define CLEARBUF_COUNT 16
32 #define CLEARBUF_MEMSZ 1024
35 measure_clearbuf_time(struct pipe_context
*ctx
,
38 struct pipe_query
*query_te
;
39 union pipe_query_result qresult
;
40 struct pipe_resource
*buf
;
42 struct si_context
*sctx
= (struct si_context
*)ctx
;
43 struct pipe_screen
*screen
= ctx
->screen
;
45 buf
= pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
, memory_size
);
47 query_te
= ctx
->create_query(ctx
, PIPE_QUERY_TIME_ELAPSED
, 0);
49 ctx
->begin_query(ctx
, query_te
);
51 si_clear_buffer(sctx
, buf
, 0, memory_size
, 0x00,
52 SI_COHERENCY_SHADER
, SI_METHOD_CP_DMA
);
53 ctx
->end_query(ctx
, query_te
);
54 ctx
->get_query_result(ctx
, query_te
, true, &qresult
);
57 ctx
->destroy_query(ctx
, query_te
);
58 pipe_resource_reference(&buf
, NULL
);
65 * @brief Analyze rate of clearing a 1K Buffer averaged over 16 iterations
66 * @param ctx Context of pipe to perform analysis on
69 analyze_clearbuf_perf_avg(struct pipe_context
*ctx
)
72 uint64_t result
[CLEARBUF_COUNT
];
74 long long int rate_kBps
;
77 for (index
= 0 ; index
< CLEARBUF_COUNT
; index
++) {
78 result
[index
] = measure_clearbuf_time(ctx
, CLEARBUF_MEMSZ
);
82 /* Calculate Results. */
83 /* kBps = (size(bytes))/(1000) / (time(ns)/(1000*1000*1000)) */
84 rate_kBps
= CLEARBUF_COUNT
*CLEARBUF_MEMSZ
;
85 rate_kBps
*= 1000UL*1000UL;
88 /* Display Results. */
89 printf("CP DMA clear_buffer performance (buffer %lu ,repeat %u ):",
90 (uint64_t)CLEARBUF_MEMSZ
,
92 printf(" %llu kB/s\n", rate_kBps
);
96 * @brief Analyze rate of clearing a range of Buffer sizes
97 * @param ctx Context of pipe to perform analysis on
100 analyze_clearbuf_perf_rng(struct pipe_context
*ctx
)
103 uint64_t result
[CLEARBUF_COUNT
];
105 long long int rate_kBps
;
108 mem_size
= CLEARBUF_MIN
;
109 for (index
= 0 ; index
< CLEARBUF_COUNT
; index
++ ) {
110 result
[index
] = measure_clearbuf_time(ctx
, mem_size
);
114 /* Calculate & Display Results. */
115 /* kBps = (size(bytes))/(1000) / (time(ns)/(1000*1000*1000)) */
116 mem_size
= CLEARBUF_MIN
;
117 for (index
= 0 ; index
< CLEARBUF_COUNT
; index
++ ) {
118 rate_kBps
= mem_size
;
119 rate_kBps
*= 1000UL*1000UL;
120 rate_kBps
/= result
[index
];
122 printf("CP DMA clear_buffer performance (buffer %lu):",
124 printf(" %llu kB/s\n", rate_kBps
);
130 void si_test_clearbuffer_perf(struct si_screen
*sscreen
)
132 struct pipe_screen
*screen
= &sscreen
->b
;
133 struct pipe_context
*ctx
= screen
->context_create(screen
, NULL
, 0);
135 analyze_clearbuf_perf_avg(ctx
);
136 analyze_clearbuf_perf_rng(ctx
);