From b1aef3198de3bc0c06263a507542ef8c380cec83 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 13 Jan 2022 15:04:18 -0800 Subject: [PATCH] update docs for upload ABI break --- content/Graphics/CommandBuffer/_index.md | 9 +++++++++ content/Graphics/Resources/Buffer.md | 8 +++++--- content/Graphics/Resources/Texture.md | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/content/Graphics/CommandBuffer/_index.md b/content/Graphics/CommandBuffer/_index.md index 08b6b96..7640949 100644 --- a/content/Graphics/CommandBuffer/_index.md +++ b/content/Graphics/CommandBuffer/_index.md @@ -16,6 +16,15 @@ var myCommandBuffer = GraphicsDevice.AcquireCommandBuffer(); Note that it is an **error** to use the same command buffer on multiple threads. If you want to do multithreaded draw calls, acquire one command buffer per thread. +## Uploading data + +You can upload data to buffers and textures using a command buffer. Uploads are guaranteed to be thread-safe. Note that it is an **error** to upload data in the middle of a render pass. + +```cs +myCommandBuffer.SetTextureData(myTexture, myPixels); +myCommandBuffer.SetBufferData(myBuffer, myData); +``` + ## Beginning the render pass All bindings and draw calls must be made within a render pass. You should think of a render pass as being a set of draw calls made to the same group of render targets. diff --git a/content/Graphics/Resources/Buffer.md b/content/Graphics/Resources/Buffer.md index 623264f..2463dc4 100644 --- a/content/Graphics/Resources/Buffer.md +++ b/content/Graphics/Resources/Buffer.md @@ -19,18 +19,20 @@ To create a buffer, you do this: This creates a 64-byte buffer intended for use as an [index buffer](https://vulkan-tutorial.com/Vertex_buffers/Index_buffer). Index buffers allow the renderer to reuse vertices when drawing in 3D so you don't need to put a bunch of redundant data in your vertex buffer. Every 3D model format and exporter will give you index data along with vertex data. -To upload data to a buffer, you use the `SetData` method. +To upload data to a buffer, you must use the `SetBufferData` method on a command buffer. We'll get to command buffers later, just know that you must upload data via command buffer so that you can safely use multithreading. ```cs var myVertices = new VertexPositionNormalTexture[128]; var vertexSizeInBytes = Marshal.SizeOf(); -// set vertex data here +// set your vertex data here! var myVertexBuffer = new Buffer(GraphicsDevice, BufferUsageFlags.Vertex, 128 * vertexSizeInBytes); -myVertexBuffer.SetData(myVertices); + +myCommandBuffer.SetBufferData(myVertexBuffer, myVertices); ``` + To get data from a buffer, you use the `GetData` method. ```cs diff --git a/content/Graphics/Resources/Texture.md b/content/Graphics/Resources/Texture.md index 11f2f59..1ef4198 100644 --- a/content/Graphics/Resources/Texture.md +++ b/content/Graphics/Resources/Texture.md @@ -37,7 +37,7 @@ var pixels = new Color[width * height]; myCommandBuffer.SetTextureData(myTexture, pixels); ``` -We'll get to command buffers later, just know that you must upload data via command buffer so that you safely use multithreading. This can speed up load times greatly. +We'll get to command buffers later, just know that you must upload data via command buffer so that you can safely use multithreading. This can speed up load times greatly. Of course, having to fill in all this data every time is kind of cumbersome, so we have some shortcut methods for common texture usages.