]> gitweb.factorcode.org Git - factor.git/blob - extra/gpu/buffers/buffers-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor into propagation
[factor.git] / extra / gpu / buffers / buffers-docs.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: alien alien.data byte-arrays destructors help.markup help.syntax
3 kernel math quotations ;
4 IN: gpu.buffers
5
6 HELP: <buffer-ptr>
7 { $values
8     { "buffer" buffer } { "offset" integer }
9     { "buffer-ptr" buffer-ptr }
10 }
11 { $description "Constructs a " { $link buffer-ptr } " tuple." } ;
12
13 HELP: <buffer-range>
14 { $values
15     { "buffer" buffer } { "offset" integer } { "size" integer }
16     { "buffer-range" buffer-range }
17 }
18 { $description "Constructs a " { $link buffer-range } " tuple." } ;
19
20 HELP: <buffer>
21 { $values
22     { "upload" buffer-upload-pattern }
23     { "usage" buffer-usage-pattern }
24     { "kind" buffer-kind }
25     { "size" integer }
26     { "initial-data" { $maybe c-ptr } }
27     { "buffer" buffer }
28 }
29 { $description "Allocates a new " { $link buffer } " object of " { $snippet "size" } " bytes. If " { $snippet "initial-data" } " is not " { $link f } ", " { $snippet "size" } " bytes are copied from " { $snippet "initial-data" } " into the buffer to initialize it; otherwise, the buffer content is left uninitialized. " { $snippet "upload" } ", " { $snippet "usage" } ", and " { $snippet "kind" } " provide hints to the implementation about the expected usage pattern of the buffer as documented in the " { $link buffer } " class documentation." } ;
30
31 HELP: allocate-buffer
32 { $values
33     { "buffer" buffer } { "size" integer } { "initial-data" { $maybe c-ptr } }
34 }
35 { $description "Discards any memory currently held by " { $snippet "buffer" } " and reallocates a new memory block of " { $snippet "size" } " bytes for it. If " { $snippet "initial-data" } " is not " { $link f } ", " { $snippet "size" } " bytes are copied from " { $snippet "initial-data" } " into the buffer to initialize it; otherwise, the buffer content is left uninitialized." } ;
36
37 HELP: allocate-byte-array
38 { $values
39     { "buffer" buffer } { "byte-array" byte-array }
40 }
41 { $description "Discards any memory currently held by " { $snippet "buffer" } " and reallocates a new memory block large enough to store " { $snippet "byte-array" } ". The contents of " { $snippet "byte-array" } " are then copied into the buffer." } ;
42
43 HELP: buffer
44 { $class-description "Objects of this class represent GPU-accessible memory buffers. Buffer objects can be used to store vertex data and to update or read pixel data from textures and framebuffers without CPU involvement. The data inside buffer objects may be resident in main memory or different parts of GPU memory; the graphics driver will choose a location for a buffer based on usage hints specified when the buffer object is constructed with " { $link <buffer> } " or " { $link byte-array>buffer } ":"
45 { $list
46 { { $snippet "upload-pattern" } " is one of the " { $link buffer-upload-pattern } " values and indicates how frequently the data in the buffer will be updated with new data from CPU memory." }
47 { { $snippet "usage-pattern" } " is one of the " { $link buffer-usage-pattern } " values and indicates how frequently the data in the buffer will be updated with new data from CPU memory." }
48 { { $snippet "kind" } " is one of the " { $link buffer-kind } " values and indicates the primary purpose of the buffer." }
49 }
50 "These settings are only performance hints and do not restrict the usage of the buffer in any way. For example, a buffer constructed as a " { $link vertex-buffer } " with " { $link static-upload } " can still receive pixel data as though it were a " { $link pixel-pack-buffer } ", and can still be updated with " { $link copy-buffer } " or " { $link update-buffer } ". However, performance may be worse when actual usage conflicts with declared usage."
51 } ;
52
53 HELP: buffer-access-mode
54 { $class-description "A " { $snippet "buffer-access-mode" } " value is passed to " { $link with-mapped-buffer } " to control access to the mapped address space." }
55 { $list
56 { { $link read-access } " permits the mapped address space only to be read from." }
57 { { $link write-access } " permits the mapped address space only to be written to." }
58 { { $link read-write-access } " permits full access to the mapped address space." }
59 } ;
60
61 HELP: buffer-kind
62 { $class-description { $snippet "buffer-kind" } " values tell the graphics driver what the primary application of a " { $link buffer } " object will be. Note that any buffer can be used for any purpose; however, performance may be improved if a buffer object is constructed as the same kind as its primary use case."
63 { $list
64 { "A " { $link vertex-buffer } " is used to store vertex attribute data to be rendered as part of a vertex array." }
65 { "An " { $link index-buffer } " is used to store indexes into a vertex array." }
66 { "A " { $link pixel-unpack-buffer } " is used as a source for updating texture image data." }
67 { "A " { $link pixel-pack-buffer } " is used as a destination for reading texture or framebuffer image data." }
68 { "A " { $link transform-feedback-buffer } " is used as a destination for transform feedback output from a vertex shader." }
69 } }
70 { $notes "The " { $snippet "pixel-unpack-buffer" } " and " { $snippet "pixel-pack-buffer" } " kinds require OpenGL 2.1 or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ;
71
72 HELP: buffer-ptr
73 { $class-description "A " { $snippet "buffer-ptr" } " references a memory location inside a " { $link buffer } " object. " { $snippet "buffer-ptr" } "s are tuples with the following slots:"
74 { $list
75 { { $snippet "buffer" } " is the " { $link buffer } " object being referenced." }
76 { { $snippet "offset" } " is an integer offset from the beginning of the buffer." }
77 } } ;
78
79 HELP: buffer-ptr>range
80 { $values
81     { "buffer-ptr" buffer-ptr }
82     { "buffer-range" buffer-range }
83 }
84 { $description "Converts a " { $link buffer-ptr } " into a " { $link buffer-range } " spanning from the " { $snippet "offset" } " referenced by the " { $snippet "buffer-ptr" } " to the end of the underlying " { $link buffer } "." } ;
85
86 HELP: buffer-range
87 { $class-description "A " { $snippet "buffer-range" } " references a subset of a " { $link buffer } " object's memory. " { $snippet "buffer-range" } "s are tuples with the following slots:"
88 { $list
89 { { $snippet "buffer" } " is the " { $link buffer } " object being referenced." }
90 { { $snippet "offset" } " is an integer offset from the beginning of the buffer to the beginning of the referenced range." }
91 { { $snippet "size" } " is the integer length from the beginning offset to the end of the referenced range." }
92 } } ;
93
94 { buffer-ptr buffer-range } related-words
95
96 HELP: buffer-size
97 { $values
98     { "buffer" buffer }
99     { "size" integer }
100 }
101 { $description "Returns the size in bytes of the memory currently allocated for a " { $link buffer } " object." } ;
102
103 HELP: buffer-upload-pattern
104 { $class-description { $snippet "buffer-upload-pattern" } " values aid the graphics driver in optimizing access to " { $link buffer } " objects by declaring the frequency with which the buffer will be supplied new data."
105 { $list
106 { { $link stream-upload } " declares that the buffer data will only be used a few times before being deallocated by " { $link dispose } " or replaced by " { $link allocate-buffer } "." }
107 { { $link static-upload } " declares that the buffer data will be provided once and accessed frequently without modification." } 
108 { { $link dynamic-upload } " declares that the buffer data will be frequently modified." }
109 }
110 "A " { $snippet "buffer-upload-pattern" } " is only a declaration and does not actually control access to the underlying buffer data." } ;
111
112 HELP: buffer-usage-pattern
113 { $class-description { $snippet "buffer-usage-pattern" } " values aid the graphics driver in optimizing access to " { $link buffer } " objects by declaring the primary provider and consumer of data for the buffer."
114 { $list
115 { { $link draw-usage } " declares that the buffer will be supplied with data from CPU memory and read from by the GPU for vertex or texture image data." }
116 { { $link read-usage } " declares that the buffer will be supplied with data from other GPU resources and read from primarily by the CPU." }
117 { { $link copy-usage } " declares that the buffer will both receive and supply data primarily for other GPU resources." } 
118 }
119 "A " { $snippet "buffer-usage-pattern" } " is only a declaration and does not actually control access to the underlying buffer data." } ;
120
121 { buffer-kind buffer-upload-pattern buffer-usage-pattern } related-words
122
123 HELP: byte-array>buffer
124 { $values
125     { "byte-array" byte-array }
126     { "upload" buffer-upload-pattern }
127     { "usage" buffer-usage-pattern }
128     { "kind" buffer-kind }
129     { "buffer" buffer }
130 }
131 { $description "Allocates a new " { $link buffer } " object with the size and contents of " { $snippet "byte-array" } ". " { $snippet "upload" } ", " { $snippet "usage" } ", and " { $snippet "kind" } " provide hints to the implementation about the expected usage pattern of the buffer as documented in the " { $link buffer } " class documentation." } ;
132
133 HELP: copy-buffer
134 { $values
135     { "to-buffer-ptr" buffer-ptr } { "from-buffer-ptr" buffer-ptr } { "size" integer }
136 }
137 { $description "Instructs the GPU to asynchronously copy " { $snippet "size" } " bytes from " { $snippet "from-buffer-ptr" } " into " { $snippet "to-buffer-ptr" } "." }
138 { $notes "This word requires that the graphics context support OpenGL 3.1 or the " { $snippet "GL_ARB_copy_buffer" } " extension." } ;
139
140 HELP: copy-usage
141 { $class-description "This " { $link buffer-usage-pattern } " declares that a " { $link buffer } " object will be primarily read from and written to by other GPU resources." } ;
142
143 HELP: draw-usage
144 { $class-description "This " { $link buffer-usage-pattern } " declares that a " { $link buffer } " object will be primarily read from by the GPU and written to by the CPU." } ;
145
146 HELP: dynamic-upload
147 { $class-description "This " { $link buffer-upload-pattern } " declares that a " { $link buffer } " object's data store will be updated frequently during its lifetime." } ;
148
149 HELP: gpu-data-ptr
150 { $class-description "This class is a union of the " { $link c-ptr } " and " { $link buffer-ptr } " classes. It represents a value that can be supplied either from CPU or GPU memory." } ;
151
152 HELP: index-buffer
153 { $class-description "This " { $link buffer-kind } " declares that a " { $link buffer } "'s primary use will be to index vertex arrays." } ;
154
155 HELP: pixel-pack-buffer
156 { $class-description "This " { $link buffer-kind } " declares that a " { $link buffer } "'s primary use will be as a destination for receiving image data from textures or framebuffers." }
157 { $notes "This word requires OpenGL 2.1 or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ;
158
159 HELP: pixel-unpack-buffer
160 { $class-description "This " { $link buffer-kind } " declares that a " { $link buffer } "'s primary use will be as a source for supplying image data to textures." }
161 { $notes "This word requires OpenGL 2.1 or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ;
162
163 HELP: read-access
164 { $class-description "This " { $link buffer-access-mode } " value requests read-only access when mapping a " { $link buffer } " object through " { $link with-mapped-buffer } "." } ;
165
166 HELP: read-buffer
167 { $values
168     { "buffer-ptr" buffer-ptr } { "size" integer }
169     { "data" byte-array }
170 }
171 { $description "Reads " { $snippet "size" } " bytes from " { $snippet "buffer" } " into a new " { $link byte-array } "." } ;
172
173 HELP: read-usage
174 { $class-description "This " { $link buffer-usage-pattern } " declares that a " { $link buffer } " object will be primarily read from by the CPU and written to by the GPU." } ;
175
176 { copy-usage draw-usage read-usage } related-words
177
178 HELP: read-write-access
179 { $class-description "This " { $link buffer-access-mode } " value requests full access when mapping a buffer object through " { $link with-mapped-buffer } "." } ;
180
181 HELP: static-upload
182 { $class-description "This " { $link buffer-upload-pattern } " declares that a " { $link buffer } " object's data store will be read from frequently and modified infrequently." } ;
183
184 HELP: stream-upload
185 { $var-description "This " { $link buffer-upload-pattern } " declares that a " { $link buffer } " object's data store will be used only a handful of times before being deallocated or replaced." } ;
186
187 { dynamic-upload static-upload stream-upload } related-words
188
189 HELP: transform-feedback-buffer
190 { $class-description "This " { $link buffer-kind } " declares that a " { $link buffer } "'s primary use will be to receive transform feedback output from a render job." }
191 { $notes "Transform feedback requires OpenGL 3.0 or one of the " { $snippet "GL_EXT_transform_feedback" } " or " { $snippet "GL_ARB_transform_feedback" } " extensions." } ;
192
193 HELP: update-buffer
194 { $values
195     { "buffer-ptr" buffer-ptr } { "size" integer } { "data" { $maybe c-ptr } }
196 }
197 { $description "Replaces " { $snippet "size" } " bytes of data in the " { $link buffer } " referenced by " { $snippet "buffer-ptr" } " with data from " { $snippet "data" } "." } ;
198
199 HELP: vertex-buffer
200 { $class-description "This " { $link buffer-kind } " declares that a " { $link buffer } "'s primary use will be to provide vertex attribute information to a vertex array." } ;
201
202 { index-buffer pixel-pack-buffer pixel-unpack-buffer vertex-buffer transform-feedback-buffer } related-words
203
204 HELP: with-mapped-buffer
205 { $values
206     { "buffer" buffer } { "access" buffer-access-mode } { "quot" { $quotation "( ..a alien -- ..b )" } }
207 }
208 { $description "Maps " { $snippet "buffer" } " into CPU address space with " { $snippet "access" } " for the dynamic extent of " { $snippet "quot" } ". " { $snippet "quot" } " is called with a pointer to the mapped memory on top of the stack." } ;
209
210 HELP: with-mapped-buffer-array
211 { $values
212     { "buffer" buffer } { "access" buffer-access-mode } { "c-type" "a C type" } { "quot" { $quotation "( ..a array -- ..b )" } }
213 }
214 { $description "Maps " { $snippet "buffer" } " into CPU address space with " { $snippet "access" } " for the dynamic extent of " { $snippet "quot" } ". " { $snippet "quot" } " is called with the pointer to the mapped memory wrapped in a specialized array of " { $snippet "c-type" } "." }
215 { $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." } ;
216
217 { allocate-buffer allocate-byte-array buffer-size update-buffer read-buffer copy-buffer with-mapped-buffer } related-words
218
219 HELP: write-access
220 { $class-description "This " { $link buffer-access-mode } " value requests write-only access when mapping a buffer object through " { $link with-mapped-buffer } "." } ;
221
222 { read-access read-write-access write-access } related-words
223
224 ARTICLE: "gpu.buffers" "Buffer objects"
225 "The " { $vocab-link "gpu.buffers" } " vocabulary provides words for creating, allocating, updating, and reading GPU data buffers."
226 { $subsections
227     buffer
228     <buffer>
229     byte-array>buffer
230 }
231 "Declaring buffer usage:"
232 { $subsections
233     buffer-kind
234     buffer-upload-pattern
235     buffer-usage-pattern
236 }
237 "Referencing buffer data:"
238 { $subsections
239     buffer-ptr
240     buffer-range
241 }
242 "Manipulating buffer data:"
243 { $subsections
244     allocate-buffer
245     allocate-byte-array
246     update-buffer
247     read-buffer
248     copy-buffer
249     with-mapped-buffer
250     with-mapped-buffer-array
251 } ;
252
253 ABOUT: "gpu.buffers"