Skip to content

Commit

Permalink
Merge pull request #891 from Sergio0694/dev/add-comment
Browse files Browse the repository at this point in the history
Add comment to 'ResourceStateHelper'
  • Loading branch information
Sergio0694 authored Dec 23, 2024
2 parents e4a8770 + 249881e commit 120aff2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ComputeSharp/Graphics/Resources/Helpers/ResourceStateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ public static D3D12_RESOURCE_STATES GetD3D12ResourceStates(ResourceState resourc
{
if (resourceState == ResourceState.ReadOnly)
{
// Transitioning to 'NON_PIXEL_SHADER_RESOURCE' here is intentional, for writeable textures. Non writeable textures
// are created as 'D3D12_RESOURCE_STATE_COMMON', which should not be used in this scenario. Writable textures need
// a state transition to 'NON_PIXEL_SHADER_RESOURCE' after being used as 'UNORDERED_ACCESS'. Readonly textures can
// be created as 'COMMON', which is a shorthand for read-compatible states. The difference is intentional, and it
// ensures correct usage and synchronization based on how resources are accessed.
//
// Transitioning to 'COMMON' instead of 'NON_PIXEL_SHADER_RESOURCE' might "work" due to leniency in the hardware or
// driver implementation. However, it's not guaranteed behavior and could lead to undefined results in other
// environments or under different conditions. To ensure portability and correctness, explicit and precise resource
// states like 'NON_PIXEL_SHADER_RESOURCE' should be preferred, which is why the latter is being used here.
return D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
}

Expand Down

0 comments on commit 120aff2

Please sign in to comment.