13464ebd5Sriastradh#ifndef __NOUVEAU_BUFFER_H__ 23464ebd5Sriastradh#define __NOUVEAU_BUFFER_H__ 33464ebd5Sriastradh 4af69d88dSmrg#include "util/u_range.h" 53464ebd5Sriastradh#include "util/u_transfer.h" 601e04c3fSmrg#include "util/list.h" 73464ebd5Sriastradh 83464ebd5Sriastradhstruct pipe_resource; 93464ebd5Sriastradhstruct nouveau_context; 103464ebd5Sriastradhstruct nouveau_bo; 113464ebd5Sriastradh 123464ebd5Sriastradh/* DIRTY: buffer was (or will be after the next flush) written to by GPU and 133464ebd5Sriastradh * resource->data has not been updated to reflect modified VRAM contents 143464ebd5Sriastradh * 153464ebd5Sriastradh * USER_MEMORY: resource->data is a pointer to client memory and may change 163464ebd5Sriastradh * between GL calls 177ec681f3Smrg * 187ec681f3Smrg * USER_PTR: bo is backed by user memory mapped into the GPUs VM 193464ebd5Sriastradh */ 203464ebd5Sriastradh#define NOUVEAU_BUFFER_STATUS_GPU_READING (1 << 0) 213464ebd5Sriastradh#define NOUVEAU_BUFFER_STATUS_GPU_WRITING (1 << 1) 22af69d88dSmrg#define NOUVEAU_BUFFER_STATUS_DIRTY (1 << 2) 237ec681f3Smrg#define NOUVEAU_BUFFER_STATUS_USER_PTR (1 << 6) 243464ebd5Sriastradh#define NOUVEAU_BUFFER_STATUS_USER_MEMORY (1 << 7) 253464ebd5Sriastradh 26af69d88dSmrg#define NOUVEAU_BUFFER_STATUS_REALLOC_MASK NOUVEAU_BUFFER_STATUS_USER_MEMORY 27af69d88dSmrg 283464ebd5Sriastradh/* Resources, if mapped into the GPU's address space, are guaranteed to 293464ebd5Sriastradh * have constant virtual addresses (nv50+). 303464ebd5Sriastradh * 313464ebd5Sriastradh * The address of a resource will lie within the nouveau_bo referenced, 323464ebd5Sriastradh * and this bo should be added to the memory manager's validation list. 333464ebd5Sriastradh */ 343464ebd5Sriastradhstruct nv04_resource { 353464ebd5Sriastradh struct pipe_resource base; 363464ebd5Sriastradh 37af69d88dSmrg uint64_t address; /* virtual address (nv50+) */ 38af69d88dSmrg 39af69d88dSmrg uint8_t *data; /* resource's contents, if domain == 0, or cached */ 403464ebd5Sriastradh struct nouveau_bo *bo; 41af69d88dSmrg uint32_t offset; /* offset into the data/bo */ 423464ebd5Sriastradh 433464ebd5Sriastradh uint8_t status; 443464ebd5Sriastradh uint8_t domain; 453464ebd5Sriastradh 4601e04c3fSmrg uint16_t cb_bindings[6]; /* per-shader per-slot bindings */ 4701e04c3fSmrg 483464ebd5Sriastradh struct nouveau_fence *fence; 493464ebd5Sriastradh struct nouveau_fence *fence_wr; 503464ebd5Sriastradh 513464ebd5Sriastradh struct nouveau_mm_allocation *mm; 52af69d88dSmrg 53af69d88dSmrg /* buffer range that has been initialized */ 54af69d88dSmrg struct util_range valid_buffer_range; 553464ebd5Sriastradh}; 563464ebd5Sriastradh 573464ebd5Sriastradhvoid 583464ebd5Sriastradhnouveau_buffer_release_gpu_storage(struct nv04_resource *); 593464ebd5Sriastradh 60af69d88dSmrgvoid 61af69d88dSmrgnouveau_copy_buffer(struct nouveau_context *, 62af69d88dSmrg struct nv04_resource *dst, unsigned dst_pos, 63af69d88dSmrg struct nv04_resource *src, unsigned src_pos, unsigned size); 643464ebd5Sriastradh 6501e04c3fSmrgbool 663464ebd5Sriastradhnouveau_buffer_migrate(struct nouveau_context *, 673464ebd5Sriastradh struct nv04_resource *, unsigned domain); 683464ebd5Sriastradh 69af69d88dSmrgvoid * 70af69d88dSmrgnouveau_resource_map_offset(struct nouveau_context *, struct nv04_resource *, 71af69d88dSmrg uint32_t offset, uint32_t flags); 723464ebd5Sriastradh 737ec681f3Smrgvoid 747ec681f3Smrgnouveau_buffer_destroy(struct pipe_screen *pscreen, 757ec681f3Smrg struct pipe_resource *presource); 767ec681f3Smrg 777ec681f3Smrgvoid 787ec681f3Smrgnouveau_buffer_transfer_flush_region(struct pipe_context *pipe, 797ec681f3Smrg struct pipe_transfer *transfer, 807ec681f3Smrg const struct pipe_box *box); 817ec681f3Smrg 8201e04c3fSmrgstatic inline void 833464ebd5Sriastradhnouveau_resource_unmap(struct nv04_resource *res) 843464ebd5Sriastradh{ 853464ebd5Sriastradh /* no-op */ 863464ebd5Sriastradh} 873464ebd5Sriastradh 8801e04c3fSmrgstatic inline struct nv04_resource * 893464ebd5Sriastradhnv04_resource(struct pipe_resource *resource) 903464ebd5Sriastradh{ 913464ebd5Sriastradh return (struct nv04_resource *)resource; 923464ebd5Sriastradh} 933464ebd5Sriastradh 943464ebd5Sriastradh/* is resource mapped into the GPU's address space (i.e. VRAM or GART) ? */ 9501e04c3fSmrgstatic inline bool 963464ebd5Sriastradhnouveau_resource_mapped_by_gpu(struct pipe_resource *resource) 973464ebd5Sriastradh{ 983464ebd5Sriastradh return nv04_resource(resource)->domain != 0; 993464ebd5Sriastradh} 1003464ebd5Sriastradh 1013464ebd5Sriastradhstruct pipe_resource * 1023464ebd5Sriastradhnouveau_buffer_create(struct pipe_screen *pscreen, 1033464ebd5Sriastradh const struct pipe_resource *templ); 1043464ebd5Sriastradh 1057ec681f3Smrgstruct pipe_resource * 1067ec681f3Smrgnouveau_buffer_create_from_user(struct pipe_screen *pscreen, 1077ec681f3Smrg const struct pipe_resource *templ, 1087ec681f3Smrg void *user_ptr); 1097ec681f3Smrg 1103464ebd5Sriastradhstruct pipe_resource * 1113464ebd5Sriastradhnouveau_user_buffer_create(struct pipe_screen *screen, void *ptr, 1123464ebd5Sriastradh unsigned bytes, unsigned usage); 1133464ebd5Sriastradh 11401e04c3fSmrgbool 115af69d88dSmrgnouveau_user_buffer_upload(struct nouveau_context *, struct nv04_resource *, 116af69d88dSmrg unsigned base, unsigned size); 117af69d88dSmrg 11801e04c3fSmrgvoid 11901e04c3fSmrgnouveau_buffer_invalidate(struct pipe_context *pipe, 12001e04c3fSmrg struct pipe_resource *resource); 12101e04c3fSmrg 122af69d88dSmrg/* Copy data to a scratch buffer and return address & bo the data resides in. 123af69d88dSmrg * Returns 0 on failure. 124af69d88dSmrg */ 125af69d88dSmrguint64_t 126af69d88dSmrgnouveau_scratch_data(struct nouveau_context *, 127af69d88dSmrg const void *data, unsigned base, unsigned size, 128af69d88dSmrg struct nouveau_bo **); 1293464ebd5Sriastradh 1307ec681f3Smrgvoid * 1317ec681f3Smrgnouveau_buffer_transfer_map(struct pipe_context *pipe, 1327ec681f3Smrg struct pipe_resource *resource, 1337ec681f3Smrg unsigned level, unsigned usage, 1347ec681f3Smrg const struct pipe_box *box, 1357ec681f3Smrg struct pipe_transfer **ptransfer); 1367ec681f3Smrg 1377ec681f3Smrgvoid 1387ec681f3Smrgnouveau_buffer_transfer_unmap(struct pipe_context *pipe, 1397ec681f3Smrg struct pipe_transfer *transfer); 1407ec681f3Smrg 1413464ebd5Sriastradh#endif 142