radeonsi: move internal TGSI shaders into si_shaderlib_tgsi.c
[mesa.git] / src / gallium / drivers / radeonsi / si_test_clearbuffer.c
1 /*
2 * Copyright 2018 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
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:
11 *
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
14 * Software.
15 *
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
22 * SOFTWARE.
23 *
24 */
25
26 /* This file implements tests on the si_clearbuffer function. */
27
28 #include "si_pipe.h"
29
30 #define CLEARBUF_MIN 32
31 #define CLEARBUF_COUNT 16
32 #define CLEARBUF_MEMSZ 1024
33
34 static uint64_t
35 measure_clearbuf_time(struct pipe_context *ctx,
36 uint64_t memory_size)
37 {
38 struct pipe_query *query_te;
39 union pipe_query_result qresult;
40 struct pipe_resource *buf;
41
42 struct si_context *sctx = (struct si_context*)ctx;
43 struct pipe_screen *screen = ctx->screen;
44
45 buf = pipe_buffer_create(screen, 0, PIPE_USAGE_DEFAULT, memory_size);
46
47 query_te = ctx->create_query(ctx, PIPE_QUERY_TIME_ELAPSED, 0);
48
49 ctx->begin_query(ctx, query_te);
50 /* operation */
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);
55
56 /* Cleanup. */
57 ctx->destroy_query(ctx, query_te);
58 pipe_resource_reference(&buf, NULL);
59
60 /* Report Results */
61 return qresult.u64;
62 }
63
64 /**
65 * @brief Analyze rate of clearing a 1K Buffer averaged over 16 iterations
66 * @param ctx Context of pipe to perform analysis on
67 */
68 static void
69 analyze_clearbuf_perf_avg(struct pipe_context *ctx)
70 {
71 uint index = 0;
72 uint64_t result[CLEARBUF_COUNT];
73 uint64_t sum = 0;
74 long long int rate_kBps;
75
76 /* Run Tests. */
77 for (index = 0 ; index < CLEARBUF_COUNT ; index++) {
78 result[index] = measure_clearbuf_time(ctx, CLEARBUF_MEMSZ);
79 sum += result[index];
80 }
81
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;
86 rate_kBps /= sum;
87
88 /* Display Results. */
89 printf("CP DMA clear_buffer performance (buffer %lu ,repeat %u ):",
90 (uint64_t)CLEARBUF_MEMSZ,
91 CLEARBUF_COUNT );
92 printf(" %llu kB/s\n", rate_kBps );
93 }
94
95 /**
96 * @brief Analyze rate of clearing a range of Buffer sizes
97 * @param ctx Context of pipe to perform analysis on
98 */
99 static void
100 analyze_clearbuf_perf_rng(struct pipe_context *ctx)
101 {
102 uint index = 0;
103 uint64_t result[CLEARBUF_COUNT];
104 uint64_t mem_size;
105 long long int rate_kBps;
106
107 /* Run Tests. */
108 mem_size = CLEARBUF_MIN;
109 for (index = 0 ; index < CLEARBUF_COUNT ; index++ ) {
110 result[index] = measure_clearbuf_time(ctx, mem_size);
111 mem_size <<= 1;
112 }
113
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];
121
122 printf("CP DMA clear_buffer performance (buffer %lu):",
123 mem_size );
124 printf(" %llu kB/s\n", rate_kBps );
125
126 mem_size <<= 1;
127 }
128 }
129
130 void si_test_clearbuffer_perf(struct si_screen *sscreen)
131 {
132 struct pipe_screen *screen = &sscreen->b;
133 struct pipe_context *ctx = screen->context_create(screen, NULL, 0);
134
135 analyze_clearbuf_perf_avg(ctx);
136 analyze_clearbuf_perf_rng(ctx);
137
138 exit(0);
139 }