]> gitweb.factorcode.org Git - factor.git/blob - extra/gpu/buffers/buffers-docs.factor
factor: trim using lists
[factor.git] / extra / gpu / buffers / buffers-docs.factor
1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien byte-arrays destructors help.markup help.syntax
4 math ;
5 IN: gpu.buffers
6
7 HELP: <buffer-ptr>
8 { $values
9     { "buffer" buffer } { "offset" integer }
10     { "buffer-ptr" buffer-ptr }
11 }
12 { $description "Constructs a " { $link buffer-ptr } " tuple." } ;
13
14 HELP: <buffer-range>
15 { $values
16     { "buffer" buffer } { "offset" integer } { "size" integer }
17     { "buffer-range" buffer-range }
18 }
19 { $description "Constructs a " { $link buffer-range } " tuple." } ;
20
21 HELP: <buffer>
22 { $values
23     { "upload" buffer-upload-pattern }
24     { "usage" buffer-usage-pattern }
25     { "kind" buffer-kind }
26     { "size" integer }
27     { "initial-data" { $maybe c-ptr } }
28     { "buffer" buffer }
29 }
30 { $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." } ;
31
32 HELP: allocate-buffer
33 { $values
34     { "buffer" buffer } { "size" integer } { "initial-data" { $maybe c-ptr } }
35 }
36 { $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." } ;
37
38 HELP: allocate-byte-array
39 { $values
40     { "buffer" buffer } { "byte-array" byte-array }
41 }
42 { $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." } ;
43
44 HELP: buffer
45 { $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 } ":"
46 { $list
47 { { $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." }
48 { { $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." }
49 { { $snippet "kind" } " is one of the " { $link buffer-kind } " values and indicates the primary purpose of the buffer." }
50 }
51 "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."
52 } ;
53
54 HELP: buffer-access-mode
55 { $class-description "A " { $snippet "buffer-access-mode" } " value is passed to " { $link with-mapped-buffer } " to control access to the mapped address space." }
56 { $list
57 { { $link read-access } " permits the mapped address space only to be read from." }
58 { { $link write-access } " permits the mapped address space only to be written to." }
59 { { $link read-write-access } " permits full access to the mapped address space." }
60 } ;
61
62 HELP: buffer-kind
63 { $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."
64 { $list
65 { "A " { $link vertex-buffer } " is used to store vertex attribute data to be rendered as part of a vertex array." }
66 { "An " { $link index-buffer } " is used to store indexes into a vertex array." }
67 { "A " { $link pixel-unpack-buffer } " is used as a source for updating texture image data." }
68 { "A " { $link pixel-pack-buffer } " is used as a destination for reading texture or framebuffer image data." }
69 { "A " { $link transform-feedback-buffer } " is used as a destination for transform feedback output from a vertex shader." }
70 } }
71 { $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." } ;
72
73 HELP: buffer-ptr
74 { $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:"
75 { $list
76 { { $snippet "buffer" } " is the " { $link buffer } " object being referenced." }
77 { { $snippet "offset" } " is an integer offset from the beginning of the buffer." }
78 } } ;
79
80 HELP: buffer-ptr>range
81 { $values
82     { "buffer-ptr" buffer-ptr }
83     { "buffer-range" buffer-range }
84 }
85 { $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 } "." } ;
86
87 HELP: buffer-range
88 { $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:"
89 { $list
90 { { $snippet "buffer" } " is the " { $link buffer } " object being referenced." }
91 { { $snippet "offset" } " is an integer offset from the beginning of the buffer to the beginning of the referenced range." }
92 { { $snippet "size" } " is the integer length from the beginning offset to the end of the referenced range." }
93 } } ;
94
95 { buffer-ptr buffer-range } related-words
96
97 HELP: buffer-size
98 { $values
99     { "buffer" buffer }
100     { "size" integer }
101 }
102 { $description "Returns the size in bytes of the memory currently allocated for a " { $link buffer } " object." } ;
103
104 HELP: buffer-upload-pattern
105 { $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."
106 { $list
107 { { $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 } "." }
108 { { $link static-upload } " declares that the buffer data will be provided once and accessed frequently without modification." }
109 { { $link dynamic-upload } " declares that the buffer data will be frequently modified." }
110 }
111 "A " { $snippet "buffer-upload-pattern" } " is only a declaration and does not actually control access to the underlying buffer data." } ;
112
113 HELP: buffer-usage-pattern
114 { $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."
115 { $list
116 { { $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." }
117 { { $link read-usage } " declares that the buffer will be supplied with data from other GPU resources and read from primarily by the CPU." }
118 { { $link copy-usage } " declares that the buffer will both receive and supply data primarily for other GPU resources." }
119 }
120 "A " { $snippet "buffer-usage-pattern" } " is only a declaration and does not actually control access to the underlying buffer data." } ;
121
122 { buffer-kind buffer-upload-pattern buffer-usage-pattern } related-words
123
124 HELP: byte-array>buffer
125 { $values
126     { "byte-array" byte-array }
127     { "upload" buffer-upload-pattern }
128     { "usage" buffer-usage-pattern }
129     { "kind" buffer-kind }
130     { "buffer" buffer }
131 }
132 { $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." } ;
133
134 HELP: copy-buffer
135 { $values
136     { "to-buffer-ptr" buffer-ptr } { "from-buffer-ptr" buffer-ptr } { "size" integer }
137 }
138 { $description "Instructs the GPU to asynchronously copy " { $snippet "size" } " bytes from " { $snippet "from-buffer-ptr" } " into " { $snippet "to-buffer-ptr" } "." }
139 { $notes "This word requires that the graphics context support OpenGL 3.1 or the " { $snippet "GL_ARB_copy_buffer" } " extension." } ;
140
141 HELP: copy-usage
142 { $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." } ;
143
144 HELP: draw-usage
145 { $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." } ;
146
147 HELP: dynamic-upload
148 { $class-description "This " { $link buffer-upload-pattern } " declares that a " { $link buffer } " object's data store will be updated frequently during its lifetime." } ;
149
150 HELP: gpu-data-ptr
151 { $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." } ;
152
153 HELP: grow-buffer
154 { $values { "buffer" buffer } { "target-size" integer } }
155 { $description "If the " { $link buffer-size } " of the given " { $link buffer } " is less than " { $snippet "target-size" } ", reallocates the buffer to a size large enough to accommodate " { $snippet "target-size" } " bytes. If the buffer is reallocated, the original contents are lost." } ;
156
157 HELP: index-buffer
158 { $class-description "This " { $link buffer-kind } " declares that a " { $link buffer } "'s primary use will be to index vertex arrays." } ;
159
160 HELP: pixel-pack-buffer
161 { $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." }
162 { $notes "This word requires OpenGL 2.1 or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ;
163
164 HELP: pixel-unpack-buffer
165 { $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." }
166 { $notes "This word requires OpenGL 2.1 or the " { $snippet "GL_ARB_pixel_buffer_object" } " extension." } ;
167
168 HELP: read-access
169 { $class-description "This " { $link buffer-access-mode } " value requests read-only access when mapping a " { $link buffer } " object through " { $link with-mapped-buffer } "." } ;
170
171 HELP: read-buffer
172 { $values
173     { "buffer-ptr" buffer-ptr } { "size" integer }
174     { "data" byte-array }
175 }
176 { $description "Reads " { $snippet "size" } " bytes from " { $snippet "buffer" } " into a new " { $link byte-array } "." } ;
177
178 HELP: read-usage
179 { $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." } ;
180
181 { copy-usage draw-usage read-usage } related-words
182
183 HELP: read-write-access
184 { $class-description "This " { $link buffer-access-mode } " value requests full access when mapping a buffer object through " { $link with-mapped-buffer } "." } ;
185
186 HELP: static-upload
187 { $class-description "This " { $link buffer-upload-pattern } " declares that a " { $link buffer } " object's data store will be read from frequently and modified infrequently." } ;
188
189 HELP: stream-upload
190 { $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." } ;
191
192 { dynamic-upload static-upload stream-upload } related-words
193
194 HELP: transform-feedback-buffer
195 { $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." }
196 { $notes "Transform feedback requires OpenGL 3.0 or one of the " { $snippet "GL_EXT_transform_feedback" } " or " { $snippet "GL_ARB_transform_feedback" } " extensions." } ;
197
198 HELP: update-buffer
199 { $values
200     { "buffer-ptr" buffer-ptr } { "size" integer } { "data" { $maybe c-ptr } }
201 }
202 { $description "Replaces " { $snippet "size" } " bytes of data in the " { $link buffer } " referenced by " { $snippet "buffer-ptr" } " with data from " { $snippet "data" } "." } ;
203
204 HELP: vertex-buffer
205 { $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." } ;
206
207 { index-buffer pixel-pack-buffer pixel-unpack-buffer vertex-buffer transform-feedback-buffer } related-words
208
209 HELP: with-mapped-buffer
210 { $values
211     { "buffer" buffer } { "access" buffer-access-mode } { "quot" { $quotation ( ..a alien -- ..b ) } }
212 }
213 { $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." } ;
214
215 HELP: with-mapped-buffer-array
216 { $values
217     { "buffer" buffer } { "access" buffer-access-mode } { "c-type" "a C type" } { "quot" { $quotation ( ..a array -- ..b ) } }
218 }
219 { $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" } "." }
220 { $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." } ;
221
222 { allocate-buffer allocate-byte-array buffer-size update-buffer read-buffer copy-buffer with-mapped-buffer } related-words
223
224 HELP: write-access
225 { $class-description "This " { $link buffer-access-mode } " value requests write-only access when mapping a buffer object through " { $link with-mapped-buffer } "." } ;
226
227 { read-access read-write-access write-access } related-words
228
229 ARTICLE: "gpu.buffers" "Buffer objects"
230 "The " { $vocab-link "gpu.buffers" } " vocabulary provides words for creating, allocating, updating, and reading GPU data buffers."
231 { $subsections
232     buffer
233     <buffer>
234     byte-array>buffer
235 }
236 "Declaring buffer usage:"
237 { $subsections
238     buffer-kind
239     buffer-upload-pattern
240     buffer-usage-pattern
241 }
242 "Referencing buffer data:"
243 { $subsections
244     buffer-ptr
245     buffer-range
246 }
247 "Manipulating buffer data:"
248 { $subsections
249     allocate-buffer
250     allocate-byte-array
251     grow-buffer
252     update-buffer
253     read-buffer
254     copy-buffer
255     with-mapped-buffer
256     with-mapped-buffer-array
257 } ;
258
259 ABOUT: "gpu.buffers"