DownsampleBloomCS.hlsl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
  2. // CHECK: flattenedThreadIdInGroup
  3. // CHECK: threadId
  4. // CHECK: sampleLevel
  5. // CHECK: textureStore
  6. // CHECK: barrier
  7. //
  8. // Copyright (c) Microsoft. All rights reserved.
  9. // This code is licensed under the MIT License (MIT).
  10. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  11. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  12. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  13. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  14. //
  15. // Developed by Minigraph
  16. //
  17. // Author: James Stanard
  18. //
  19. // The CS for downsampling 16x16 blocks of pixels down to 4x4 and 1x1 blocks.
  20. #include "PostEffectsRS.hlsli"
  21. Texture2D<float3> BloomBuf : register( t0 );
  22. RWTexture2D<float3> Result1 : register( u0 );
  23. RWTexture2D<float3> Result2 : register( u1 );
  24. SamplerState BiLinearClamp : register( s0 );
  25. cbuffer cb0 : register(b0)
  26. {
  27. float2 g_inverseDimensions;
  28. }
  29. groupshared float3 g_Tile[64]; // 8x8 input pixels
  30. [RootSignature(PostEffects_RootSig)]
  31. [numthreads( 8, 8, 1 )]
  32. void main( uint GI : SV_GroupIndex, uint3 Did : SV_DispatchThreadID )
  33. {
  34. // You can tell if both x and y are divisible by a power of two with this value
  35. uint parity = Did.x | Did.y;
  36. // Store the first downsampled quad per thread
  37. float2 centerUV = (float2(Did.xy) * 2.0f + 1.0f) * g_inverseDimensions;
  38. float3 avgPixel = BloomBuf.SampleLevel(BiLinearClamp, centerUV, 0.0f);
  39. g_Tile[GI] = avgPixel;
  40. GroupMemoryBarrierWithGroupSync();
  41. if ((parity & 1) == 0)
  42. {
  43. avgPixel = 0.25f * (avgPixel + g_Tile[GI+1] + g_Tile[GI+8] + g_Tile[GI+9]);
  44. g_Tile[GI] = avgPixel;
  45. Result1[Did.xy >> 1] = avgPixel;
  46. }
  47. GroupMemoryBarrierWithGroupSync();
  48. if ((parity & 3) == 0)
  49. {
  50. avgPixel = avgPixel + g_Tile[GI+2] + g_Tile[GI+16] + g_Tile[GI+18];
  51. g_Tile[GI] = avgPixel;
  52. }
  53. GroupMemoryBarrierWithGroupSync();
  54. if ((parity & 7) == 0)
  55. {
  56. avgPixel = 0.0625f * (avgPixel + g_Tile[GI+4] + g_Tile[GI+32] + g_Tile[GI+36]);
  57. Result2[Did.xy >> 3] = avgPixel;
  58. }
  59. }