<p>In Vulkan the shader only looks at each 2x2 and won't attempt to look beyond the neighbourhood: <a href="http://vulkan-spec-chunked.ahcox.com/ch15s05.html">http://vulkan-spec-chunked.ahcox.com/ch15s05.html</a></p>

<p>$$dPdx_{0,0}=dPdx_{1, 0} = P_{1,0}−P_{0,0}\\
dPdx_{2,0}=dPdx_{3, 0} = P_{3,0}−P_{2,0}$$</p>

<p>For times when a pixel would fall off the geometry the shader is invoked for the values it would have if the triangle extended a pixel further. </p>

CC BY-SA 3.0
2016-03-30T12:00:36.940Z
Thanks. After reading of Vulkan doc I could find the similar for directx [fine](https://msdn.microsoft.com/en-us/library/windows/desktop/hh446950(v=vs.85).aspx) and [coarse](https://msdn.microsoft.com/en-us/library/windows/desktop/hh446948(v=vs.85).aspx) derivatives.
nikitablack
CC BY-SA 3.0
2016-03-30T11:35:24.423Z
2016-03-30T11:35:24.423Z
ratchet freak
<p>This question bothers me since the first time I got to know about derivatives in pixel shader. Suppose we have a 2d texture:</p>

<pre><code>5   10  20  30
6   11  50  100
</code></pre>

<p>If I correctly understand, the derivatives for the pixel [0, 0] will be:</p>

<ul>
<li>dx = pixel[1, 0] - pixel[0, 0] = 10 - 5 = 5</li>
<li>dy = pixel[0, 1] - pixel[0, 0] = 6 - 5 = 1</li>
</ul>

<p>And this will be 100% guaranteed because gpu executes pixels in 2x2 block. But what is the <strong>dx-derivative</strong> for the pixel[1, 0]? The pixel right to it is from another block which maybe not executed yet? And what about pixel[3, 0]? It doesn't have a right neighbor at all!</p>

<gpu><pixel-shader>
Gpu derivatives. How it's done across 2x2 boundary?
nikitablack
# Gpu derivatives. How it's done across 2x2 boundary?

(Asked by: username_0 on 2016-03-30)

This question bothers me since the first time I got to know about derivatives in pixel shader. Suppose we have a 2d texture:

```
5   10  20  30
6   11  50  100

```

If I correctly understand, the derivatives for the pixel [0, 0] will be:

* dx = pixel[1, 0] - pixel[0, 0] = 10 - 5 = 5
* dy = pixel[0, 1] - pixel[0, 0] = 6 - 5 = 1

And this will be 100% guaranteed because gpu executes pixels in 2x2 block. But what is the **dx-derivative** for the pixel[1, 0]? The pixel right to it is from another block which maybe not executed yet? And what about pixel[3, 0]? It doesn't have a right neighbor at all!

**Tags:** gpu, pixel-shader


---

## 1 answers

### Answer by username_1 on 2016-03-30. Score: 7 | Accepted answer

In Vulkan the shader only looks at each 2x2 and won't attempt to look beyond the neighbourhood: <http://vulkan-spec-chunked.ahcox.com/ch15s05.html>

$$dPdx\_{0,0}=dPdx\_{1, 0} = P\_{1,0}−P\_{0,0}\\
dPdx\_{2,0}=dPdx\_{3, 0} = P\_{3,0}−P\_{2,0}$$

For times when a pixel would fall off the geometry the shader is invoked for the values it would have if the triangle extended a pixel further.

> **Comments:**
> **username_0**: Thanks. After reading of Vulkan doc I could find the similar for directx [fine](https://msdn.microsoft.com/en-us/library/windows/desktop/hh446950(v=vs.85).aspx) and [coarse](https://msdn.microsoft.com/en-us/library/windows/desktop/hh446948(v=vs.85).aspx) derivatives.  

---

