Back to index

libdrm  2.4.37
radeon_cs.h
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2008 Nicolai Haehnle
00003  * Copyright © 2008 Jérôme Glisse
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
00017  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
00018  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
00019  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
00020  * USE OR OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * The above copyright notice and this permission notice (including the
00023  * next paragraph) shall be included in all copies or substantial portions
00024  * of the Software.
00025  */
00026 /*
00027  * Authors:
00028  *      Aapo Tahkola <aet@rasterburn.org>
00029  *      Nicolai Haehnle <prefect_@gmx.net>
00030  *      Jérôme Glisse <glisse@freedesktop.org>
00031  */
00032 #ifndef RADEON_CS_H
00033 #define RADEON_CS_H
00034 
00035 #include <stdint.h>
00036 #include <string.h>
00037 #include "drm.h"
00038 #include "radeon_drm.h"
00039 #include "radeon_bo.h"
00040 
00041 struct radeon_cs_reloc {
00042     struct radeon_bo    *bo;
00043     uint32_t            read_domain;
00044     uint32_t            write_domain;
00045     uint32_t            flags;
00046 };
00047 
00048 
00049 #define RADEON_CS_SPACE_OK 0
00050 #define RADEON_CS_SPACE_OP_TO_BIG 1
00051 #define RADEON_CS_SPACE_FLUSH 2
00052 
00053 struct radeon_cs {
00054     uint32_t *packets;
00055     unsigned cdw;
00056     unsigned ndw;
00057     unsigned                    section_ndw;
00058     unsigned                    section_cdw;
00059 };
00060 
00061 #define MAX_SPACE_BOS (32)
00062 
00063 struct radeon_cs_manager;
00064 
00065 extern struct radeon_cs *radeon_cs_create(struct radeon_cs_manager *csm,
00066                                           uint32_t ndw);
00067 
00068 extern int radeon_cs_begin(struct radeon_cs *cs,
00069                            uint32_t ndw,
00070                            const char *file,
00071                            const char *func, int line);
00072 extern int radeon_cs_end(struct radeon_cs *cs,
00073                          const char *file,
00074                          const char *func,
00075                          int line);
00076 extern int radeon_cs_emit(struct radeon_cs *cs);
00077 extern int radeon_cs_destroy(struct radeon_cs *cs);
00078 extern int radeon_cs_erase(struct radeon_cs *cs);
00079 extern int radeon_cs_need_flush(struct radeon_cs *cs);
00080 extern void radeon_cs_print(struct radeon_cs *cs, FILE *file);
00081 extern void radeon_cs_set_limit(struct radeon_cs *cs, uint32_t domain, uint32_t limit);
00082 extern void radeon_cs_space_set_flush(struct radeon_cs *cs, void (*fn)(void *), void *data);
00083 extern int radeon_cs_write_reloc(struct radeon_cs *cs,
00084                                  struct radeon_bo *bo,
00085                                  uint32_t read_domain,
00086                                  uint32_t write_domain,
00087                                  uint32_t flags);
00088 extern uint32_t radeon_cs_get_id(struct radeon_cs *cs);
00089 /*
00090  * add a persistent BO to the list
00091  * a persistent BO is one that will be referenced across flushes,
00092  * i.e. colorbuffer, textures etc.
00093  * They get reset when a new "operation" happens, where an operation
00094  * is a state emission with a color/textures etc followed by a bunch of vertices.
00095  */
00096 void radeon_cs_space_add_persistent_bo(struct radeon_cs *cs,
00097                                        struct radeon_bo *bo,
00098                                        uint32_t read_domains,
00099                                        uint32_t write_domain);
00100 
00101 /* reset the persistent BO list */
00102 void radeon_cs_space_reset_bos(struct radeon_cs *cs);
00103 
00104 /* do a space check with the current persistent BO list */
00105 int radeon_cs_space_check(struct radeon_cs *cs);
00106 
00107 /* do a space check with the current persistent BO list and a temporary BO
00108  * a temporary BO is like a DMA buffer, which  gets flushed with the
00109  * command buffer */
00110 int radeon_cs_space_check_with_bo(struct radeon_cs *cs,
00111                                   struct radeon_bo *bo,
00112                                   uint32_t read_domains,
00113                                   uint32_t write_domain);
00114 
00115 static inline void radeon_cs_write_dword(struct radeon_cs *cs, uint32_t dword)
00116 {
00117     cs->packets[cs->cdw++] = dword;
00118     if (cs->section_ndw) {
00119         cs->section_cdw++;
00120     }
00121 }
00122 
00123 static inline void radeon_cs_write_qword(struct radeon_cs *cs, uint64_t qword)
00124 {
00125     memcpy(cs->packets + cs->cdw, &qword, sizeof(uint64_t));
00126     cs->cdw += 2;
00127     if (cs->section_ndw) {
00128         cs->section_cdw += 2;
00129     }
00130 }
00131 
00132 static inline void radeon_cs_write_table(struct radeon_cs *cs,
00133                                          const void *data, uint32_t size)
00134 {
00135     memcpy(cs->packets + cs->cdw, data, size * 4);
00136     cs->cdw += size;
00137     if (cs->section_ndw) {
00138         cs->section_cdw += size;
00139     }
00140 }
00141 #endif