Path: blob/21.2-virgl/src/gallium/frontends/nine/buffer9.h
4561 views
/*1* Copyright 2011 Joakim Sindholt <[email protected]>2* Copyright 2015 Patrick Rudolph <[email protected]>3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE. */2223#ifndef _NINE_BUFFER9_H_24#define _NINE_BUFFER9_H_2526#include "device9.h"27#include "nine_buffer_upload.h"28#include "nine_state.h"29#include "resource9.h"30#include "pipe/p_context.h"31#include "pipe/p_defines.h"32#include "pipe/p_state.h"33#include "util/list.h"34#include "util/u_box.h"35#include "util/u_upload_mgr.h"3637struct pipe_screen;38struct pipe_context;39struct pipe_transfer;4041struct NineTransfer {42struct pipe_transfer *transfer;43bool is_pipe_secondary;44struct nine_subbuffer *buf; /* NULL unless subbuffer are used */45bool should_destroy_buf; /* If the subbuffer should be destroyed */46};4748struct NineBuffer949{50struct NineResource9 base;5152/* G3D */53struct NineTransfer *maps;54int nlocks, nmaps, maxmaps;55UINT size;5657int16_t bind_count; /* to Device9->state.stream */58/* Whether only discard and nooverwrite were used so far59* for this buffer. Allows some optimization. */60boolean discard_nooverwrite_only;61boolean need_sync_if_nooverwrite;62struct nine_subbuffer *buf;6364/* Specific to managed buffers */65struct {66void *data;67boolean dirty;68struct pipe_box dirty_box; /* region in the resource to update */69struct pipe_box upload_pending_regions; /* region with uploads pending */70struct list_head list; /* for update_buffers */71struct list_head list2; /* for managed_buffers */72unsigned pending_upload; /* for uploads */73/* SYSTEMMEM DYNAMIC */74bool can_unsynchronized; /* Whether the upload can use nooverwrite */75struct pipe_box valid_region; /* Region in the GPU buffer with valid content */76struct pipe_box required_valid_region; /* Region that needs to be valid right now. */77struct pipe_box filled_region; /* Region in the GPU buffer filled since last discard */78unsigned num_worker_thread_syncs;79unsigned frame_count_last_discard;80} managed;81};82static inline struct NineBuffer9 *83NineBuffer9( void *data )84{85return (struct NineBuffer9 *)data;86}8788HRESULT89NineBuffer9_ctor( struct NineBuffer9 *This,90struct NineUnknownParams *pParams,91D3DRESOURCETYPE Type,92DWORD Usage,93UINT Size,94D3DPOOL Pool );9596void97NineBuffer9_dtor( struct NineBuffer9 *This );9899struct pipe_resource *100NineBuffer9_GetResource( struct NineBuffer9 *This, unsigned *offset );101102HRESULT NINE_WINAPI103NineBuffer9_Lock( struct NineBuffer9 *This,104UINT OffsetToLock,105UINT SizeToLock,106void **ppbData,107DWORD Flags );108109HRESULT NINE_WINAPI110NineBuffer9_Unlock( struct NineBuffer9 *This );111112void113NineBuffer9_Upload( struct NineBuffer9 *This );114115static void inline116NineBindBufferToDevice( struct NineDevice9 *device,117struct NineBuffer9 **slot,118struct NineBuffer9 *buf )119{120struct NineBuffer9 *old = *slot;121122if (buf) {123if ((buf->managed.dirty) && list_is_empty(&buf->managed.list))124list_add(&buf->managed.list, &device->update_buffers);125buf->bind_count++;126}127if (old) {128old->bind_count--;129if (!old->bind_count && old->managed.dirty)130list_delinit(&old->managed.list);131}132133nine_bind(slot, buf);134}135136void137NineBuffer9_SetDirty( struct NineBuffer9 *This );138139#define BASEBUF_REGISTER_UPDATE(b) { \140if ((b)->managed.dirty && (b)->bind_count) \141if (list_is_empty(&(b)->managed.list)) \142list_add(&(b)->managed.list, &(b)->base.base.device->update_buffers); \143}144145#endif /* _NINE_BUFFER9_H_ */146147148