Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Korean translate#359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
diskhkme wants to merge49 commits intoOverv:main
base:main
Choose a base branch
Loading
fromdiskhkme:kr_translate
Open
Changes from1 commit
Commits
Show all changes
49 commits
Select commitHold shift + click to select a range
5a4e2c2
kr translate, 00 and 01
diskhkmeSep 17, 2023
f2d96bd
kr translate 02 (except MacOS part)
diskhkmeSep 18, 2023
fff7580
kr translate 03-00-00 base code
diskhkmeSep 19, 2023
95c8ead
kr translate 03-00-01 instance
diskhkmeSep 19, 2023
603a24c
kr translate 03-00-02 validation layerr, backup
diskhkmeSep 27, 2023
a725ed0
kr translate 03-00-02 validation layer, finish
diskhkmeOct 12, 2023
5a8e529
kr translate 03-00-03 physical device
diskhkmeOct 12, 2023
806aa59
kr translate 03-00-04 logical device
diskhkmeOct 14, 2023
ad2d13f
kr translate 03-00-04 logical device, final
diskhkmeOct 14, 2023
dfdb3d2
kr translate update links of 03-00-02, 03
diskhkmeOct 14, 2023
c705993
kr translate 03-01-00 window surface
diskhkmeOct 14, 2023
a1e53f2
kr translate 03-01-01 swap chain
diskhkmeOct 15, 2023
7455fa4
kr translate 03-01-02 image view
diskhkmeOct 15, 2023
9fa6af7
kr translate 03-02-00 graphics pipeline, intro
diskhkmeOct 16, 2023
5b79abf
kr translate 03-02-01 shader modules
diskhkmeOct 17, 2023
a5d2faf
kr translate fixed mardown errors and links
diskhkmeOct 17, 2023
28d4c5c
kr translate 03-02-02 fixed functions
diskhkmeOct 18, 2023
fc35393
kr translate 03-02-03 render passes
diskhkmeOct 19, 2023
a0e18f4
kr translate 03-02-03 pipeline, conclusion
diskhkmeOct 19, 2023
8a05a13
kr translate 03-03-00 framebuffers
diskhkmeOct 21, 2023
81cee13
kr translate 03-03-01 drawing, framebuffers
diskhkmeOct 23, 2023
f9317ab
kr translate 03-03-02 drawing, command buffers
diskhkmeOct 23, 2023
2c9b387
kr translate fix typo
diskhkmeFeb 5, 2024
0b4c98c
kr translate fix typo
diskhkmeFeb 6, 2024
26cfdc5
kr translate fix typo
diskhkmeFeb 6, 2024
03ea8d3
kr translate 03-03-02 rendering and presentation
diskhkmeFeb 7, 2024
de9ddfa
Merge branch 'kr_translate' of https://github.com/diskhkme/VulkanTuto…
diskhkmeFeb 9, 2024
dc891b9
kr translate 03-03-03 frames in flight
diskhkmeFeb 9, 2024
b0b49f2
kr translate 03-03-04 swap chain recreation
diskhkmeFeb 9, 2024
36cc8e0
kr translate 04-00 vertex input desciption
diskhkmeFeb 9, 2024
896d406
kr translate 04-01 vertex buffer creation
diskhkmeFeb 12, 2024
2211065
kr translate 04-02 staging buffer
diskhkmeFeb 12, 2024
9aae27a
kr translate 04-03 index buffer
diskhkmeFeb 13, 2024
4808eb1
kr translate 05-00 descriptor layout and buffer
diskhkmeFeb 15, 2024
ecce6c6
kr translate fix newline inconsistency
diskhkmeFeb 15, 2024
5d456ab
kr translate add Korean glossary, fix terms
diskhkmeFeb 15, 2024
191faaa
kr translate 05-01 descriptor pool and sets
diskhkmeFeb 15, 2024
0378f74
kr translate 06-00 images (needs improvement)
diskhkmeFeb 17, 2024
d8d8401
kr translate 06-00 image view and sampler
diskhkmeFeb 19, 2024
16261a0
kr translate change translation
diskhkmeFeb 20, 2024
bbcb64f
kr translate 06-02 combined image sampler
diskhkmeFeb 20, 2024
39c8196
kr translate 07 depth buffering
diskhkmeFeb 28, 2024
eca0c50
kr translate 08 loading models
diskhkmeMar 4, 2024
69c5920
kr translate 09 generating mipmaps
diskhkmeMar 5, 2024
a7b5555
kr translate 10 multisampling
diskhkmeMar 11, 2024
e07abd6
kr translate 11 compute shader
diskhkmeMar 20, 2024
db544d4
kr translate 90 faq
diskhkmeMar 20, 2024
5dea1a4
Merge branch 'Overv:main' into kr_translate
diskhkmeMar 20, 2024
990a8f9
kr translate sync up to date
diskhkmeMar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
kr translate 04-00 vertex input desciption
  • Loading branch information
@diskhkme
diskhkme committedFeb 9, 2024
commit36cc8e02d73f070543a45720afc14a9aa42f2a58
161 changes: 67 additions & 94 deletionskr/04_Vertex_buffers/00_Vertex_input_description.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
##Introduction
##개요

In the next few chapters, we're going to replace the hardcoded vertex data in
the vertex shader with a vertex buffer in memory. We'll start with the easiest
approach of creating a CPU visible buffer and using `memcpy` to copy the vertex
data into it directly, and after that we'll see how to use a staging buffer to
copy the vertex data to high performance memory.
다음 몇 챕터동안 정점 셰이더에 하드코딩된 정점 데이터를 메모리의 정점 버퍼(vertex buffer)로 바꾸어 보겠습니다.
먼저 가장 손쉬운 방법인 CPU에서 보이는(visible) 버퍼를 만든 뒤 `memcpy`를 통해 정점 데이터를 직접 복사하는 방법을 알아볼 것이고, 이후에 스테이징 버퍼(staging buffer)를 사용해 정점 데이터를 고성능 메모리에 복사하는 방법을 알아볼 것입니다.

##Vertex shader
##정점 셰이더

First change the vertex shader to no longer include the vertex data in the
shader code itself. The vertex shader takes input from a vertex buffer using the
`in` keyword.
먼저 정점 셰이더가 정점 데이터를 코드로 포함하지 않도록 수정할 것입니다.
정점 셰이더는 `in` 키워드로 정점 버퍼에서 입력을 받을 것입니다.

```glsl
#version 450
Expand All@@ -26,36 +22,32 @@ void main() {
}
```

The `inPosition` and `inColor` variables are *vertex attributes*. They're
properties that are specified per-vertex in the vertex buffer, just like we
manually specified a position and color per vertex using the two arrays. Make
sure to recompile the vertex shader!
`inPosition`와 `inColor` 변수는 *정점 어트리뷰트(vertex attribute)*입니다.
이는 정점 버퍼에 명시된 정점별 속성이며, 기존처럼 위치와 속성 데이터 입니다.
정점 셰이더를 수정한 뒤 다시 컴파일하는 것을 잊지 마세요!

Just like `fragColor`, the `layout(location = x)` annotations assign indices to
the inputs that we can later use to reference them. It is important to know that
some types, like `dvec3` 64 bit vectors, use multiple *slots*. That means that
the index after it must be at least 2 higher:
`fragColor`처럼, `layout(location = x)`는 입력에 대해 나중에 참조하기 위한 인덱스를 할당하는 것입니다.
예를들어 `dvec3`와 같은 64비트 벡터는 여러 *슬롯(slot)*을 사용한다는 사실을 중요하게 알아두셔야 합니다.
이러한 경우 그 다음으로 오는 인덱스는 2 이상 큰 인덱스여야 합니다:

```glsl
layout(location = 0) in dvec3 inPosition;
layout(location = 2) in vec3 inColor;
```

You can find more info about the layoutqualifier in the[OpenGL wiki](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)).
레이아웃 한정자(qualifier)에 대해서는[OpenGL wiki](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL))에서 자세한 정보를 찾아 볼 수 있습니다.

##Vertex data
##정점 데이터

We're moving the vertex data from the shader code to an array in the code of our
program. Start by including the GLM library, which provides us with linear
algebra related types like vectors and matrices. We're going to use these types
to specify the position and color vectors.
정점 데이터를 셰이더 코드에서 우리 프로그램의 배열로 옮길 예정입니다.
먼저 벡터와 행렬 같은 선형대수 관련 자료형을 제공해 주는 GLM 라이브러를 include 하는 것 부터 시작합니다.
이 자료형들을 사용해 위치와 색상 벡터를 명시할 것입니다.

```c++
#include <glm/glm.hpp>
```

Create a new structure called `Vertex` with the two attributes that we're going
to use in the vertex shader inside it:
우리가 정점 셰이더에서 사용할 두 어트리뷰트를 포함하는 `Vertex` 구조체를 만듭니다:

```c++
struct Vertex {
Expand All@@ -64,8 +56,7 @@ struct Vertex {
};
```

GLM conveniently provides us with C++ types that exactly match the vector types
used in the shader language.
GLM은 셰이더 언어에서 사용되는 벡터 자료형과 정확히 매치되는 C++ 자료형을 제공해 줍니다:

```c++
const std::vector<Vertex> vertices = {
Expand All@@ -75,18 +66,16 @@ const std::vector<Vertex> vertices = {
};
```

Now use the`Vertex`structure to specify an array of vertex data. We're using
exactly the same position and color values as before, but now they're combined
into one array of vertices. This is known as *interleaving* vertex attributes.
이제`Vertex`구조체를 사용해 정점 데이터를 명시합니다.
이전과 완전히 동일한 위치와 색상값을 사용하지만 이제는 정점에 대한 배열 하나에 모두 포함해 두었습니다.
이러한 방식을 정점 어트리뷰트의 *interleving*이라고 합니다.

## Binding descriptions
##바인딩 명세(Binding descriptions)

The next step is to tell Vulkan how to pass this data format to the vertex
shader once it's been uploaded into GPU memory. There are two types of
structures needed to convey this information.
다음 단계는 GPU 메모리에 업로드된 데이터를 정점 셰이더로 어떻게 전달할지를 Vulkan에 알려주는 것입니다.
이러한 정보를 전달하기 위한 두 종류의 구조체가 필요합니다.

The first structure is `VkVertexInputBindingDescription` and we'll add a member
function to the `Vertex` struct to populate it with the right data.
첫 구조체는 `VkVertexInputBindingDescription`이고 `Vertex` 구조체에 멤버 함수를 추가하여 적절한 데이터를 생성할 수 있도록 합니다.

```c++
struct Vertex {
Expand All@@ -101,9 +90,8 @@ struct Vertex {
};
```

A vertex binding describes at which rate to load data from memory throughout the
vertices. It specifies the number of bytes between data entries and whether to
move to the next data entry after each vertex or after each instance.
정점 바인딩은 정점에 대해 얼만큼의 데이터를 메모리로부터 로드할 것인지를 명시합니다.
각 데이터별 바이트의 크기, 그리고 각 정점에 대해 다음 데이터로 넘어갈지, 아니면 다음 인스턴스에서 널어갈지를 포함합니다.

```c++
VkVertexInputBindingDescription bindingDescription{};
Expand All@@ -112,23 +100,20 @@ bindingDescription.stride = sizeof(Vertex);
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
```

All of our per-vertex data is packed together in one array, so we're only going
to have one binding. The `binding` parameter specifies the index of the binding
in the array of bindings. The `stride` parameter specifies the number of bytes
from one entry to the next, and the `inputRate` parameter can have one of the
following values:
우리의 정점별 데이터는 하나의 배열에 포장되어(packed) 있으니 바인딩은 하나만 있으면 됩니다.
`binding` 매개변수는 바인딩 배열의 바인딩할 인덱스를 명시합니다.
`stride` 매개변수는 한 요소와 다음 요소 사이의 바이트 크기입니다.
`inputRate` 매개변수는 아래와 같은 값 중 하나를 가집니다:

* `VK_VERTEX_INPUT_RATE_VERTEX`: Move to the next data entry after each vertex
* `VK_VERTEX_INPUT_RATE_INSTANCE`: Move to the next data entry after each
instance
* `VK_VERTEX_INPUT_RATE_VERTEX`: 각 정점에 대해 다음 데이터 요소로 이동함
* `VK_VERTEX_INPUT_RATE_INSTANCE`: 각 인스턴스에 대해 다음 데이터 요소로 넘어감

We're not going to use instanced rendering, so we'll stick to per-vertex data.
인스턴스 렌더링을 한 것은 아니므로 정점별 데이터로 해 두겠습니다.

##Attribute descriptions
##어트리뷰트 명세

The second structure that describes how to handle vertex input is
`VkVertexInputAttributeDescription`. We're going to add another helper function
to `Vertex` to fill in these structs.
정점 입력을 처리하는 방법을 설명하기 위한 두 번째 구조체는 `VkVertexInputAttributeDescription`입니다.
이 구조체를 채우기 위해 또 다른 헬퍼 함수를 `Vertex`에 추가하겠습니다.

```c++
#include <array>
Expand All@@ -142,11 +127,9 @@ static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions
}
```

As the function prototype indicates, there are going to be two of these
structures. An attribute description struct describes how to extract a vertex
attribute from a chunk of vertex data originating from a binding description. We
have two attributes, position and color, so we need two attribute description
structs.
함수 프로토타입에서 알 수 있듯, 두 개의 구조체를 사용할 것입니다.
어트리뷰트 명세를 위한 구조체는 바인딩 명세를 활용해 얻어진 정점 데이터 덩어리로부터 정점 어트리뷰트를 어떻게 추출할지를 알려줍니다.
우리는 위치와 색상 두 개의 어트리뷰트가 있으니 두 개의 어트리뷰트 명세 구조체가 필요합니다.

```c++
attributeDescriptions[0].binding = 0;
Expand All@@ -155,39 +138,32 @@ attributeDescriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
attributeDescriptions[0].offset = offsetof(Vertex, pos);
```

The `binding` parameter tells Vulkan from which binding the per-vertex data
comes. The `location` parameter references the `location` directive of the
input in the vertex shader. The input in the vertex shader with location `0` is
the position, which has two 32-bit float components.
`binding` 매개변수는 어떤 바인딩에서 정점별 데이터를 얻어올 것인지를 Vulkan에 알려줍니다.
`location` 매개변수는 정점 셰이더의 `location` 지시자에 대한 참조입니다.
정점 셰이더의 location `0`에 대한 입력이 위치값에 해당하고, 이는 두 개의 32비트 부동소수점으로 이루어져 있습니다.

The`format`parameter describes the type of data for the attribute. A bit
confusingly, the formats are specified using the same enumeration as color
formats. The following shader types and formats are commonly used together:
`format`매개변수는 어트리뷰트의 데이터 자료형을 알려줍니다.
약간 헷갈리는 점은 이러한 포맷이 색상 포맷과 동일한 열거자로 명시된다는 점입니다.
아래와 같은 셰이더 자료형에 따르는 포맷이 사용됩니다:

* `float`: `VK_FORMAT_R32_SFLOAT`
* `vec2`: `VK_FORMAT_R32G32_SFLOAT`
* `vec3`: `VK_FORMAT_R32G32B32_SFLOAT`
* `vec4`: `VK_FORMAT_R32G32B32A32_SFLOAT`

As you can see, you should use the format where the amount of color channels
matches the number of components in the shader data type. It is allowed to use
more channels than the number of components in the shader, but they will be
silently discarded. If the number of channels is lower than the number of
components, then the BGA components will use default values of `(0, 0, 1)`. The
color type (`SFLOAT`, `UINT`, `SINT`) and bit width should also match the type
of the shader input. See the following examples:

* `ivec2`: `VK_FORMAT_R32G32_SINT`, a 2-component vector of 32-bit signed
integers
* `uvec4`: `VK_FORMAT_R32G32B32A32_UINT`, a 4-component vector of 32-bit
unsigned integers
* `double`: `VK_FORMAT_R64_SFLOAT`, a double-precision (64-bit) float

The `format` parameter implicitly defines the byte size of attribute data and
the `offset` parameter specifies the number of bytes since the start of the
per-vertex data to read from. The binding is loading one `Vertex` at a time and
the position attribute (`pos`) is at an offset of `0` bytes from the beginning
of this struct. This is automatically calculated using the `offsetof` macro.
보다시피 색상 채널의 수와 일치하는 요소 숫자를 갖는 셰이더 자료형의 포맷을 사용해야 합니다.
셰이더의 요소 숫자보다 더 많은 채널을 사용하는 것도 허용되지만 남는 값은 무시됩니다.
요소 숫자보다 채널 수가 적으면 BGA 요소의 기본값인 `(0, 0, 1)`가 사용됩니다.
색상 타입인 (`SFLOAT`, `UINT`, `SINT`)와 비트 너비 또한 셰이더 입력의 자료형과 일치해야 합니다.
예시는 다음과 같습니다:

* `ivec2`: `VK_FORMAT_R32G32_SINT`, 32비트 부호 있는 정수 2개 요소를 갖는 벡터
* `uvec4`: `VK_FORMAT_R32G32B32A32_UINT`, 32비트 부호 없는 정수 4개의 요소를 갖는 벡터
* `double`: `VK_FORMAT_R64_SFLOAT`, 64비트 double 부동소수점

`format` 매개변수는 어트리뷰트 데이터의 바이트 크기를 암시적으로 정의하며 `offset` 매개변수는 정점별 데이터를 읽어올 시작 바이트를 명시합니다.
바인딩은 한 번에 하나의 `Vertex`를 읽어오며 위치 어트리뷰트(`pos`)는 `0` 바이트, 즉 처음부터 읽어옵니다.
`offsetof` 매크로를 사용하면 자동으로 계산됩니다.

```c++
attributeDescriptions[1].binding = 0;
Expand All@@ -196,13 +172,12 @@ attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[1].offset = offsetof(Vertex, color);
```

The color attribute is described in much the same way.
색상 어트리뷰트도 동일한 방식으로 기술됩니다.

##Pipeline vertex input
##파이프라인 정점 입력

We now need to set up the graphics pipeline to accept vertex data in this format
by referencing the structures in `createGraphicsPipeline`. Find the
`vertexInputInfo` struct and modify it to reference the two descriptions:
이제 `createGraphicsPipeline` 안의 구조체를 참조하여 정점 데이터를 위와 같은 포맷으로 받아들이도록 그래픽스 파이프라인을 설정해야 합니다.
`vertexInputInfo` 구조체를 찾아 두 명세를 참조하도록 수정합니다:

```c++
auto bindingDescription = Vertex::getBindingDescription();
Expand All@@ -214,11 +189,9 @@ vertexInputInfo.pVertexBindingDescriptions = &bindingDescription;
vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
```

The pipeline is now ready to accept vertex data in the format of the `vertices`
container and pass it on to our vertex shader. If you run the program now with
validation layers enabled, you'll see that it complains that there is no vertex
buffer bound to the binding. The next step is to create a vertex buffer and move
the vertex data to it so the GPU is able to access it.
이제 이 파이프라인은 `vertices` 컨테이너의 정점 데이터를 받아들이고 정점 셰이더로 넘길 준비가 되었습니다.
검증 레이어를 활성화 한 상태에서 프로그램을 실행하면 바인딩된 정점 버퍼가 없다는 오류 메시지를 보시게 될겁니다.
다음 단계는 정점 버퍼를 만들고 정점 데이터를 버퍼에 넘겨 GPU가 접근할 수 있도록 하는 것입니다.

[C++ code](/code/18_vertex_input.cpp) /
[Vertex shader](/code/18_shader_vertexbuffer.vert) /
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp