Skip to content

Commit 120aff2

Browse files
authored
Merge pull request #891 from Sergio0694/dev/add-comment
Add comment to 'ResourceStateHelper'
2 parents e4a8770 + 249881e commit 120aff2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Diff for: src/ComputeSharp/Graphics/Resources/Helpers/ResourceStateHelper.cs

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ public static D3D12_RESOURCE_STATES GetD3D12ResourceStates(ResourceState resourc
2020
{
2121
if (resourceState == ResourceState.ReadOnly)
2222
{
23+
// Transitioning to 'NON_PIXEL_SHADER_RESOURCE' here is intentional, for writeable textures. Non writeable textures
24+
// are created as 'D3D12_RESOURCE_STATE_COMMON', which should not be used in this scenario. Writable textures need
25+
// a state transition to 'NON_PIXEL_SHADER_RESOURCE' after being used as 'UNORDERED_ACCESS'. Readonly textures can
26+
// be created as 'COMMON', which is a shorthand for read-compatible states. The difference is intentional, and it
27+
// ensures correct usage and synchronization based on how resources are accessed.
28+
//
29+
// Transitioning to 'COMMON' instead of 'NON_PIXEL_SHADER_RESOURCE' might "work" due to leniency in the hardware or
30+
// driver implementation. However, it's not guaranteed behavior and could lead to undefined results in other
31+
// environments or under different conditions. To ensure portability and correctness, explicit and precise resource
32+
// states like 'NON_PIXEL_SHADER_RESOURCE' should be preferred, which is why the latter is being used here.
2333
return D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
2434
}
2535

0 commit comments

Comments
 (0)