specialization-constants-vk.azsl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. /*
  9. * Demonstrates the use of shader variants (options)
  10. *
  11. * Global constants and SRG constants marked with the "option" qualifier are treated as variant options
  12. */
  13. enum class QualityT {Low, Medium, High};
  14. // Option keyword Type Name Default value (hint)
  15. option QualityT Quality = QualityT::High;
  16. // Boolean is supported
  17. option bool UseGI = true;
  18. // Integer is supported
  19. [range(1, 64)]
  20. option int IntOption = 42;
  21. ShaderResourceGroupSemantic ExampleBinding
  22. {
  23. FrequencyId = 0;
  24. ShaderVariantFallback = 64;
  25. };
  26. ShaderResourceGroup ExampleSRG : ExampleBinding
  27. {
  28. float4 exampleColor;
  29. };
  30. struct VertexInput { float3 m_position : POSITION; };
  31. struct VertexOutput { float4 m_position : SV_Position; };
  32. VertexOutput MainVS(VertexInput input)
  33. {
  34. VertexOutput output;
  35. output.m_position = float4(input.m_position, 1.0);
  36. return output;
  37. }
  38. float4 MainPS() : SV_Target0
  39. {
  40. switch (Quality)
  41. {
  42. case QualityT::Low: return ExampleSRG::exampleColor * float4(IntOption, 0, 0, 0);
  43. case QualityT::Medium: return ExampleSRG::exampleColor * float4(0, IntOption, 0, 0);
  44. case QualityT::High: return ExampleSRG::exampleColor * float4(0, 0, IntOption, 0);
  45. default: return ExampleSRG::exampleColor; // https://github.com/microsoft/DirectXShaderCompiler/issues/2331
  46. }
  47. }