neuwld

patched neuwld library (tracked)
git clone https://git.daat.foo/neuwld.git
Log | Files | Refs | README | LICENSE

batch.h (3147B)


      1 /* wld: intel/batch.h
      2  *
      3  * Copyright (c) 2013, 2014 Michael Forney
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a copy
      6  * of this software and associated documentation files (the "Software"), to deal
      7  * in the Software without restriction, including without limitation the rights
      8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9  * copies of the Software, and to permit persons to whom the Software is
     10  * furnished to do so, subject to the following conditions:
     11  *
     12  * The above copyright notice and this permission notice shall be included in
     13  * all copies or substantial portions of the Software.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21  * SOFTWARE.
     22  */
     23 
     24 #ifndef WLD_INTEL_BATCH_H
     25 #define WLD_INTEL_BATCH_H
     26 
     27 #include <intel_bufmgr.h>
     28 #include <stdarg.h>
     29 #include <stdbool.h>
     30 #include <stdint.h>
     31 
     32 #define INTEL_BATCH_MAX_COMMANDS (1 << 13)
     33 #define INTEL_BATCH_RESERVED_COMMANDS 2
     34 #define INTEL_BATCH_SIZE (INTEL_BATCH_MAX_COMMANDS << 2)
     35 
     36 enum intel_batch_result {
     37 	INTEL_BATCH_SUCCESS,
     38 	INTEL_BATCH_NO_SPACE
     39 };
     40 
     41 struct intel_device_info {
     42 	int gen;
     43 };
     44 
     45 #define GEN(b, m) ((b)->device_info->gen >= (m))
     46 
     47 struct intel_batch {
     48 	const struct intel_device_info *device_info;
     49 	drm_intel_bo *bo;
     50 	uint32_t commands[INTEL_BATCH_MAX_COMMANDS];
     51 	uint32_t command_count;
     52 };
     53 
     54 bool intel_batch_initialize(struct intel_batch *batch,
     55                             drm_intel_bufmgr *bufmgr);
     56 
     57 void intel_batch_finalize(struct intel_batch *batch);
     58 
     59 void intel_batch_flush(struct intel_batch *batch);
     60 
     61 static inline uint32_t
     62 intel_batch_check_space(struct intel_batch *batch,
     63                         uint32_t size)
     64 {
     65 	return (INTEL_BATCH_MAX_COMMANDS - INTEL_BATCH_RESERVED_COMMANDS
     66 	        - batch->command_count)
     67 	       >= size;
     68 }
     69 
     70 static inline void
     71 intel_batch_ensure_space(struct intel_batch *batch, uint32_t size)
     72 {
     73 	if (!intel_batch_check_space(batch, size))
     74 		intel_batch_flush(batch);
     75 }
     76 
     77 static inline void
     78 intel_batch_add_dword(struct intel_batch *batch,
     79                       uint32_t dword)
     80 {
     81 	batch->commands[batch->command_count++] = dword;
     82 }
     83 
     84 static inline void
     85 intel_batch_add_dwords_va(struct intel_batch *batch,
     86                           uint32_t count, va_list dwords)
     87 {
     88 	while (count--)
     89 		intel_batch_add_dword(batch, va_arg(dwords, uint32_t));
     90 }
     91 
     92 static inline void
     93 intel_batch_add_dwords(struct intel_batch *batch,
     94                        uint32_t count, ...)
     95 {
     96 	va_list dwords;
     97 	va_start(dwords, count);
     98 	intel_batch_add_dwords_va(batch, count, dwords);
     99 	va_end(dwords);
    100 }
    101 
    102 static inline uint32_t
    103 intel_batch_offset(struct intel_batch *batch,
    104                    uint32_t command_index)
    105 {
    106 	return (batch->command_count + command_index) << 2;
    107 }
    108 
    109 #endif