Files
godot-docs-l10n/sphinx/templates/tutorials/shaders/compute_shaders.pot
2025-09-08 16:20:52 +02:00

233 lines
13 KiB
Plaintext

# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0)
# This file is distributed under the same license as the Godot Engine package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Godot Engine latest\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../../docs/tutorials/shaders/compute_shaders.rst:4
msgid "Using compute shaders"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:6
msgid "This tutorial will walk you through the process of creating a minimal compute shader. But first, a bit of background on compute shaders and how they work with Godot."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:12
msgid "This tutorial assumes you are familiar with shaders generally. If you are new to shaders please read :ref:`doc_introduction_to_shaders` and :ref:`your first shader <toc-your-first-shader>` before proceeding with this tutorial."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:16
msgid "A compute shader is a special type of shader program that is orientated towards general purpose programming. In other words, they are more flexible than vertex shaders and fragment shaders as they don't have a fixed purpose (i.e. transforming vertices or writing colors to an image). Unlike fragment shaders and vertex shaders, compute shaders have very little going on behind the scenes. The code you write is what the GPU runs and very little else. This can make them a very useful tool to offload heavy calculations to the GPU."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:24
msgid "Now let's get started by creating a short compute shader."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:26
msgid "First, in the **external** text editor of your choice, create a new file called ``compute_example.glsl`` in your project folder. When you write compute shaders in Godot, you write them in GLSL directly. The Godot shader language is based on GLSL. If you are familiar with normal shaders in Godot, the syntax below will look somewhat familiar."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:34
msgid "Compute shaders can only be used from RenderingDevice-based renderers (the Forward+ or Mobile renderer). To follow along with this tutorial, ensure that you are using the Forward+ or Mobile renderer. The setting for which is located in the top right-hand corner of the editor."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:39
msgid "Note that compute shader support is generally poor on mobile devices (due to driver bugs), even if they are technically supported."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:42
msgid "Let's take a look at this compute shader code:"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:64
msgid "This code takes an array of floats, multiplies each element by 2 and store the results back in the buffer array. Now let's look at it line-by-line."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:72
msgid "These two lines communicate two things:"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:74
msgid "The following code is a compute shader. This is a Godot-specific hint that is needed for the editor to properly import the shader file."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:75
msgid "The code is using GLSL version 450."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:77
msgid "You should never have to change these two lines for your custom compute shaders."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:84
msgid "Next, we communicate the number of invocations to be used in each workgroup. Invocations are instances of the shader that are running within the same workgroup. When we launch a compute shader from the CPU, we tell it how many workgroups to run. Workgroups run in parallel to each other. While running one workgroup, you cannot access information in another workgroup. However, invocations in the same workgroup can have some limited access to other invocations."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:91
msgid "Think about workgroups and invocations as a giant nested ``for`` loop."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:111
msgid "Workgroups and invocations are an advanced topic. For now, remember that we will be running two invocations per workgroup."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:122
msgid "Here we provide information about the memory that the compute shader will have access to. The ``layout`` property allows us to tell the shader where to look for the buffer, we will need to match these ``set`` and ``binding`` positions from the CPU side later."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:127
msgid "The ``restrict`` keyword tells the shader that this buffer is only going to be accessed from one place in this shader. In other words, we won't bind this buffer in another ``set`` or ``binding`` index. This is important as it allows the shader compiler to optimize the shader code. Always use ``restrict`` when you can."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:133
msgid "This is an *unsized* buffer, which means it can be any size. So we need to be careful not to read from an index larger than the size of the buffer."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:144
msgid "Finally, we write the ``main`` function which is where all the logic happens. We access a position in the storage buffer using the ``gl_GlobalInvocationID`` built-in variables. ``gl_GlobalInvocationID`` gives you the global unique ID for the current invocation."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:149
msgid "To continue, write the code above into your newly created ``compute_example.glsl`` file."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:153
msgid "Create a local RenderingDevice"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:155
msgid "To interact with and execute a compute shader, we need a script. Create a new script in the language of your choice and attach it to any Node in your scene."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:159
msgid "Now to execute our shader we need a local :ref:`class_RenderingDevice` which can be created using the :ref:`class_RenderingServer`:"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:173
msgid "After that, we can load the newly created shader file ``compute_example.glsl`` and create a precompiled version of it using this:"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:193
msgid "Local RenderingDevices cannot be debugged using tools such as `RenderDoc <https://renderdoc.org/>`__."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:197
msgid "Provide input data"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:199
msgid "As you might remember, we want to pass an input array to our shader, multiply each element by 2 and get the results."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:202
msgid "We need to create a buffer to pass values to a compute shader. We are dealing with an array of floats, so we will use a storage buffer for this example. A storage buffer takes an array of bytes and allows the CPU to transfer data to and from the GPU."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:207
msgid "So let's initialize an array of floats and create a storage buffer:"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:231
msgid "With the buffer in place we need to tell the rendering device to use this buffer. To do that we will need to create a uniform (like in normal shaders) and assign it to a uniform set which we can pass to our shader later."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:258
msgid "Defining a compute pipeline"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:260
msgid "The next step is to create a set of instructions our GPU can execute. We need a pipeline and a compute list for that."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:263
msgid "The steps we need to do to compute our result are:"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:265
msgid "Create a new pipeline."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:266
msgid "Begin a list of instructions for our GPU to execute."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:267
msgid "Bind our compute list to our pipeline"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:268
msgid "Bind our buffer uniform to our pipeline"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:269
msgid "Specify how many workgroups to use"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:270
msgid "End the list of instructions"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:293
msgid "Note that we are dispatching the compute shader with 5 work groups in the X axis, and one in the others. Since we have 2 local invocations in the X axis (specified in our shader), 10 compute shader invocations will be launched in total. If you read or write to indices outside of the range of your buffer, you may access memory outside of your shaders control or parts of other variables which may cause issues on some hardware."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:301
msgid "Execute a compute shader"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:303
msgid "After all of this we are almost done, but we still need to execute our pipeline. So far we have only recorded what we would like the GPU to do; we have not actually run the shader program."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:307
msgid "To execute our compute shader we need to submit the pipeline to the GPU and wait for the execution to finish:"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:323
msgid "Ideally, you would not call ``sync()`` to synchronize the RenderingDevice right away as it will cause the CPU to wait for the GPU to finish working. In our example, we synchronize right away because we want our data available for reading right away. In general, you will want to wait *at least* 2 or 3 frames before synchronizing so that the GPU is able to run in parallel with the CPU."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:331
msgid "Long computations can cause Windows graphics drivers to \"crash\" due to :abbr:`TDR (Timeout Detection and Recovery)` being triggered by Windows. This is a mechanism that reinitializes the graphics driver after a certain amount of time has passed without any activity from the graphics driver (usually 5 to 10 seconds)."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:337
msgid "Depending on the duration your compute shader takes to execute, you may need to split it into multiple dispatches to reduce the time each dispatch takes and reduce the chances of triggering a TDR. Given TDR is time-dependent, slower GPUs may be more prone to TDRs when running a given compute shader compared to a faster GPU."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:344
msgid "Retrieving results"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:346
msgid "You may have noticed that, in the example shader, we modified the contents of the storage buffer. In other words, the shader read from our array and stored the data in the same array again so our results are already there. Let's retrieve the data and print the results to our console."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:370
msgid "Freeing memory"
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:372
msgid "The ``buffer``, ``pipeline``, and ``uniform_set`` variables we've been using are each an :ref:`class_RID`. Because RenderingDevice is meant to be a lower-level API, RIDs aren't freed automatically. This means that once you're done using ``buffer`` or any other RID, you are responsible for freeing its memory manually using the RenderingDevice's :ref:`free_rid()<class_RenderingDevice_method_free_rid>` method."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:379
msgid "With that, you have everything you need to get started working with compute shaders."
msgstr ""
#: ../../docs/tutorials/shaders/compute_shaders.rst:384
msgid "The demo projects repository contains a `Compute Shader Heightmap demo <https://github.com/godotengine/godot-demo-projects/tree/master/compute/heightmap>`__ This project performs heightmap image generation on the CPU and GPU separately, which lets you compare how a similar algorithm can be implemented in two different ways (with the GPU implementation being faster in most cases)."
msgstr ""