2023. 3. 5. 15:16ㆍ개발하다가
가만 생각하면 당연한 소리긴 한데,,, 간혹 틀린 말 하는 것만 아니었으면 월 10만 원도 안 아깝겠는데요. (대학교가 월 100만 원 넘었던 것만 생각해도)
Q1. dFdx가 이런 건가?
Is my understanding right for GLSL dfdx/dfdy? "2x2 areas are guaranteed to be executed simultaneously for shader, and dfdx and dfdy peeks the adjacent pixel. If A B | C D is one of the blocks, both dfdx in A invocation yields B - A"
A1. 응
Your understanding is mostly correct.
GLSL has a built-in derivative function called dFdx and dFdy, which are used to calculate the partial derivatives of a value with respect to the x and y directions, respectively. When used inside a shader program, the dFdx and dFdy functions are evaluated for each pixel in a 2x2 group of pixels, with each invocation corresponding to one of the four pixels in the group.
The dFdx function calculates the change in the value of a variable with respect to the x direction, and dFdy calculates the change in the value of a variable with respect to the y direction. When evaluating dFdx, the function looks at the difference between the value of the variable at the pixel to the right and the value of the variable at the current pixel. Similarly, when evaluating dFdy, the function looks at the difference between the value of the variable at the pixel above and the value of the variable at the current pixel.
In a 2x2 block of pixels, the dFdx function is evaluated for the left and right pixels, while the dFdy function is evaluated for the top and bottom pixels. So if you have a block like this:
A B
C D
The dFdx function evaluated at A will look at the difference between the value of the variable at B and the value of the variable at A. Similarly, the dFdx function evaluated at C will look at the difference between the value of the variable at D and the value of the variable at C. The value of the derivative function will be the same for both invocations, since they are evaluating the same 2x2 block of pixels.
Therefore, your statement that "both dFdx in A invocation yields B - A" is mostly correct, although it's important to note that this is true only for the left and right pixels in a 2x2 block, and not for all invocations of the dFdx function.
Q2. dFdx 가 이런 건가? (오타 수정)
Is my understanding right for GLSL dfdx/dfdy? "2x2 areas are guaranteed to be executed simultaneously for shader, and dfdx and dfdy peeks the adjacent pixel. If A B | C D is one of the blocks, both dfdx in A and B invocations yield B - A"
A2. ㅇ
Your revised statement is also mostly correct.
As I mentioned in my previous answer, in a 2x2 block of pixels, the dFdx function is evaluated for the left and right pixels, while the dFdy function is evaluated for the top and bottom pixels. So if you have a block like this:
A B
C D
The dFdx function evaluated at A and B will both look at the difference between the value of the variable at B and the value of the variable at A. The value of the derivative function will be the same for both invocations, since they are evaluating the same 2x2 block of pixels.
Therefore, your statement that "both dFdx in A and B invocations yield B - A" is mostly correct, and it's also important to note that this is true only for the left and right pixels in a 2x2 block, and not for all invocations of the dFdx function.
It's worth noting that the exact behavior of the dFdx and dFdy functions may depend on the specific graphics hardware and driver implementation, so the details may vary somewhat between different platforms.
Q3. 2x2 블록에 들지 않은 픽셀?
Is there any case that a pixel isn't in 2x2 blocks?
A3. 삼각형 하나에 화면 전체가 그려지진 않고 전체를 그려도 홀수거나 시저테스트 하거나..
In Vulkan and other graphics APIs, pixels are typically processed in 2x2 blocks called quads, which are groups of four adjacent pixels. However, there are some cases where a pixel may not be part of a full 2x2 block.
For example, if an image has dimensions that are not evenly divisible by 2, then the pixels at the edges of the image may not be part of a full 2x2 block. In this case, the dFdx and dFdy functions will still be evaluated for these pixels, but they will only have one adjacent pixel instead of two.
Additionally, in some cases, certain pixels may be excluded from processing altogether. For example, some graphics APIs support a "scissor test" that allows the developer to specify a rectangular region of the screen that should be rendered, while excluding the rest of the screen. In this case, any pixels outside the scissor region will not be processed, and will not be part of a 2x2 block.
In general, however, the vast majority of pixels in an image will be processed as part of a 2x2 block, since this is the most efficient way to process image data in parallel on modern graphics hardware.
Q4. Vulkan의 디바이스 로스트가 언제 일어나지?
In what cases the Vulkan device lost occurs? (cf. 저는 자원에 대한 허상 디스트립터 외에 로스트가 발생한 경우를 직접 본 적이 없습니다. 절전 모드를 켠다거나, DirectX9처럼 ctrl+alt+delete를 누르는 정도로는 로스트가 일어나지 않음)
A4. 하드웨어나 드라이버 이슈를 일으킬 만한 행동이 있어서
In Vulkan, a "device lost" error can occur when the graphics driver loses contact with the graphics hardware, typically due to a hardware failure, a driver bug, or an operating system issue. This error is similar to a "blue screen of death" on Windows, or a kernel panic on Linux.
When a device lost error occurs, the graphics driver is no longer able to communicate with the graphics hardware, which can result in the application crashing, freezing, or otherwise behaving unpredictably. To recover from a device lost error, the application typically needs to recreate the Vulkan device and any associated resources, such as command buffers, pipelines, and memory allocations.
There are several common reasons why a device lost error might occur:
- Hardware failure: If the graphics hardware itself has failed, either due to a manufacturing defect, a component failure, or wear and tear over time, this can cause the graphics driver to lose contact with the device. This can be difficult to diagnose and fix, and may require replacement of the hardware.
- Driver bug: If there is a bug in the graphics driver, either in the vendor-provided driver or in the operating system's built-in driver, this can cause the driver to crash or become unstable. In some cases, a driver update may fix the issue, but in other cases, the application may need to work around the issue or report it to the driver vendor.
- Overclocking: If the graphics hardware has been overclocked beyond its recommended limits, this can cause it to become unstable and generate device lost errors. To avoid this, it's important to follow the manufacturer's recommended specifications for clock speeds and voltage levels.
- Power issues: If the graphics hardware is not receiving sufficient power, either due to a faulty power supply or an overloaded circuit, this can cause it to become unstable and generate device lost errors. Ensuring that the hardware is properly powered and cooled can help prevent these issues.
- Resource exhaustion: If the application is using too much memory or other system resources, this can cause the graphics driver to run out of available resources and generate device lost errors. Ensuring that the application properly manages its resource usage and gracefully handles out-of-memory conditions can help prevent these issues.
Overall, while device lost errors can be frustrating and difficult to diagnose, they are relatively rare and can often be avoided by following best practices for hardware and software management.
Q5. 대부분 하드웨어 이슈면 복원이 되기나 하겠니?
Well, then in most cases I don't need to try to recover from vulkan physical/logical device lost in my graphics engine.
A5. 이렇게 하란 말이다
In general, it is a good idea to handle device lost errors in your graphics engine, even if they are relatively rare. While the underlying causes of a device lost error can vary, the result is typically that the application is unable to communicate with the graphics hardware, and any resources associated with the Vulkan device, such as command buffers, pipelines, and memory allocations, are no longer valid.
To recover from a device lost error, the application typically needs to recreate the Vulkan device and any associated resources, which can be a non-trivial task. However, failing to handle device lost errors can lead to unpredictable behavior, such as crashes, freezes, or other unexpected behavior, which can be difficult for the end user to diagnose and fix.
Some common strategies for handling device lost errors include:
- Detecting the error: In order to handle a device lost error, the application needs to be able to detect when the error has occurred. This can be done by checking the return codes of Vulkan functions, such as vkQueueSubmit, vkCreateFramebuffer, or vkAcquireNextImageKHR, or by monitoring system-level events, such as window resize events or device notifications.
- Cleaning up resources: When a device lost error occurs, any resources associated with the Vulkan device, such as command buffers, pipelines, and memory allocations, are no longer valid. The application should clean up these resources as gracefully as possible, to avoid memory leaks or other issues.
- Recreating the device: Once the resources associated with the Vulkan device have been cleaned up, the application needs to recreate the device and any associated resources. This can be a non-trivial task, and may involve re-initializing the application state or reloading data from disk.
Overall, while device lost errors are relatively rare, it is a good idea to handle them in your graphics engine, to ensure that your application behaves gracefully and predictably in the face of unexpected errors.
Q6. 싫어요
But in the above incidents, even device recreation will fail in most cases, isn't it?
A6. 그래도 해라
You are correct that in some cases, device recreation may not be possible or may not be sufficient to recover from a device lost error. For example, if the underlying cause of the error is a hardware failure or a power issue, then simply recreating the Vulkan device may not be enough to restore normal operation.
In these cases, it may be necessary to take additional steps, such as:
- Logging the error: When a device lost error occurs, it's important to log as much information as possible about the error, including the error code, any relevant system information, and any application-specific data. This information can be useful for diagnosing the root cause of the error and for determining the appropriate course of action.
- Notifying the user: When a device lost error occurs, it's important to notify the user in a clear and informative way, so that they understand what has happened and what steps they can take to recover. This might include displaying a message box with instructions for restarting the application, or providing a link to a support forum or knowledge base.
- Implementing fallback modes: In some cases, it may be possible to implement fallback modes that allow the application to continue running even if the Vulkan device is unavailable or in a degraded state. For example, the application might switch to a lower-quality rendering mode or disable certain graphics features that require the Vulkan device.
Overall, while device lost errors can be challenging to recover from, it is still important to handle them gracefully in your graphics engine, to ensure that your application behaves predictably and in a way that is informative to the user.
번거로운 걸 피하려는 무책임한 인간을 끝까지 떠밀려는 인공지능 선생님..
코드 최적화도 제의해 줄 수 있고(대부분 '잘 했네' 정도지만) 아주 재밌는 도구입니다.
'개발하다가' 카테고리의 다른 글
C++에서 템플릿 메타프로그래밍하다가 발생한 오류 (0) | 2022.05.31 |
---|---|
오버플로 없는 short int x 분수 (0) | 2022.05.25 |
1초당 목표 위치에 99% 다가가는 카메라 (0) | 2022.05.22 |
원 모양 물체의 2차원 비탄성 충돌에 대한 고민 (0) | 2022.05.10 |
동일 평면 상 원과 선분의 위치 관계, 선분과 선분의 위치 관계 (0) | 2022.05.09 |