DownsampleBloomAllCS.hlsl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 8x8, 4x4, 2x2, 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. RWTexture2D<float3> Result3 : register( u2 );
  25. RWTexture2D<float3> Result4 : register( u3 );
  26. SamplerState BiLinearClamp : register( s0 );
  27. cbuffer cb0 : register(b0)
  28. {
  29. float2 g_inverseDimensions;
  30. }
  31. groupshared float3 g_Tile[64]; // 8x8 input pixels
  32. [RootSignature(PostEffects_RootSig)]
  33. [numthreads( 8, 8, 1 )]
  34. void main( uint GI : SV_GroupIndex, uint3 DTid : SV_DispatchThreadID )
  35. {
  36. // You can tell if both x and y are divisible by a power of two with this value
  37. uint parity = DTid.x | DTid.y;
  38. // Downsample and store the 8x8 block
  39. float2 centerUV = (float2(DTid.xy) * 2.0f + 1.0f) * g_inverseDimensions;
  40. float3 avgPixel = BloomBuf.SampleLevel(BiLinearClamp, centerUV, 0.0f);
  41. g_Tile[GI] = avgPixel;
  42. Result1[DTid.xy] = avgPixel;
  43. GroupMemoryBarrierWithGroupSync();
  44. // Downsample and store the 4x4 block
  45. if ((parity & 1) == 0)
  46. {
  47. avgPixel = 0.25f * (avgPixel + g_Tile[GI+1] + g_Tile[GI+8] + g_Tile[GI+9]);
  48. g_Tile[GI] = avgPixel;
  49. Result2[DTid.xy >> 1] = avgPixel;
  50. }
  51. GroupMemoryBarrierWithGroupSync();
  52. // Downsample and store the 2x2 block
  53. if ((parity & 3) == 0)
  54. {
  55. avgPixel = 0.25f * (avgPixel + g_Tile[GI+2] + g_Tile[GI+16] + g_Tile[GI+18]);
  56. g_Tile[GI] = avgPixel;
  57. Result3[DTid.xy >> 2] = avgPixel;
  58. }
  59. GroupMemoryBarrierWithGroupSync();
  60. // Downsample and store the 1x1 block
  61. if ((parity & 7) == 0)
  62. {
  63. avgPixel = 0.25f * (avgPixel + g_Tile[GI+4] + g_Tile[GI+32] + g_Tile[GI+36]);
  64. Result4[DTid.xy >> 3] = avgPixel;
  65. }
  66. }