Home | History | Annotate | Download | only in i965
      1 /*
      2  * Copyright 2005 VMware, 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
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sublicense, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * The above copyright notice and this permission notice (including the
     14  * next paragraph) shall be included in all copies or substantial portions
     15  * of the Software.
     16  *
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     20  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
     21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     24  */
     25 
     26 #ifndef INTEL_BUFFEROBJ_H
     27 #define INTEL_BUFFEROBJ_H
     28 
     29 #include "main/mtypes.h"
     30 
     31 struct brw_context;
     32 struct gl_buffer_object;
     33 
     34 
     35 /**
     36  * Intel vertex/pixel buffer object, derived from Mesa's gl_buffer_object.
     37  */
     38 struct intel_buffer_object
     39 {
     40    struct gl_buffer_object Base;
     41    drm_intel_bo *buffer;     /* the low-level buffer manager's buffer handle */
     42 
     43    drm_intel_bo *range_map_bo[MAP_COUNT];
     44 
     45    /**
     46     * Alignment offset from the range_map_bo temporary mapping to the returned
     47     * obj->Pointer (caused by GL_ARB_map_buffer_alignment).
     48     */
     49    unsigned map_extra[MAP_COUNT];
     50 
     51    /** @{
     52     * Tracking for what range of the BO may currently be in use by the GPU.
     53     *
     54     * Users often want to either glBufferSubData() or glMapBufferRange() a
     55     * buffer object where some subset of it is busy on the GPU, without either
     56     * stalling or doing an extra blit (since our blits are extra expensive,
     57     * given that we have to reupload most of the 3D state when switching
     58     * rings).  We wish they'd just use glMapBufferRange() with the
     59     * UNSYNC|INVALIDATE_RANGE flag or the INVALIDATE_BUFFER flag, but lots
     60     * don't.
     61     *
     62     * To work around apps, we track what range of the BO we might have used on
     63     * the GPU as vertex data, tranform feedback output, buffer textures, etc.,
     64     * and just do glBufferSubData() with an unsynchronized map when they're
     65     * outside of that range.
     66     *
     67     * If gpu_active_start > gpu_active_end, then the GPU is not currently
     68     * accessing the BO (and we can map it without synchronization).
     69     */
     70    uint32_t gpu_active_start;
     71    uint32_t gpu_active_end;
     72 
     73    /**
     74     * If we've avoided stalls/blits using the active tracking, flag the buffer
     75     * for (occasional) stalling in the future to avoid getting stuck in a
     76     * cycle of blitting on buffer wraparound.
     77     */
     78    bool prefer_stall_to_blit;
     79    /** @} */
     80 };
     81 
     82 
     83 /* Get the bm buffer associated with a GL bufferobject:
     84  */
     85 drm_intel_bo *intel_bufferobj_buffer(struct brw_context *brw,
     86                                      struct intel_buffer_object *obj,
     87                                      uint32_t offset,
     88                                      uint32_t size);
     89 
     90 void intel_upload_data(struct brw_context *brw,
     91                        const void *data,
     92                        uint32_t size,
     93                        uint32_t alignment,
     94                        drm_intel_bo **out_bo,
     95                        uint32_t *out_offset);
     96 
     97 void *intel_upload_space(struct brw_context *brw,
     98                          uint32_t size,
     99                          uint32_t alignment,
    100                          drm_intel_bo **out_bo,
    101                          uint32_t *out_offset);
    102 
    103 void intel_upload_finish(struct brw_context *brw);
    104 
    105 /* Hook the bufferobject implementation into mesa:
    106  */
    107 void intelInitBufferObjectFuncs(struct dd_function_table *functions);
    108 
    109 static inline struct intel_buffer_object *
    110 intel_buffer_object(struct gl_buffer_object *obj)
    111 {
    112    return (struct intel_buffer_object *) obj;
    113 }
    114 
    115 #endif
    116