├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ ├── legacy.yml │ ├── main.yml │ ├── msvc.yml │ └── vcpkg.yml ├── .gitignore ├── D3DX_DXGIFormatConvert.inl ├── LICENSE ├── README.md ├── Tests ├── .gitignore ├── CMakeLists.txt ├── CMakePresets.json ├── F10UI.hlsl ├── F10UN.hlsl ├── F16F.hlsl ├── F16S.hlsl ├── F16SI.hlsl ├── F16U.hlsl ├── F16UI.hlsl ├── F8S.hlsl ├── F8SI.hlsl ├── F8U.hlsl ├── F8UI.hlsl ├── F8US.hlsl ├── FB8U.hlsl ├── FB8US.hlsl ├── FBX8U.hlsl ├── FBX8US.hlsl ├── fmtconvert.cpp └── fmtconverttest.hlsli └── build └── vcpkg.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Explicitly declare resource files as binary 5 | *.pdb binary 6 | *.dll binary 7 | *.lib binary 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: weekly 7 | -------------------------------------------------------------------------------- /.github/workflows/legacy.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: 'CMake (Windows FXC)' 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | - build/*.json 15 | 16 | permissions: 17 | contents: read 18 | 19 | jobs: 20 | build: 21 | runs-on: ${{ matrix.os }} 22 | 23 | strategy: 24 | fail-fast: false 25 | 26 | matrix: 27 | os: [windows-2019, windows-2022] 28 | build_type: [x64-Debug] 29 | arch: [amd64] 30 | include: 31 | - os: windows-2019 32 | build_type: x86-Debug 33 | arch: amd64_x86 34 | - os: windows-2022 35 | build_type: x86-Debug 36 | arch: amd64_x86 37 | - os: windows-2022 38 | build_type: x64-Debug-Clang 39 | arch: amd64 40 | - os: windows-2022 41 | build_type: x86-Debug-Clang 42 | arch: amd64_x86 43 | - os: windows-2022 44 | build_type: arm64-Debug 45 | arch: amd64_arm64 46 | - os: windows-2022 47 | build_type: arm64ec-Debug 48 | arch: amd64_arm64 49 | 50 | steps: 51 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 52 | 53 | - name: 'Install Ninja' 54 | run: choco install ninja 55 | 56 | - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 57 | with: 58 | arch: ${{ matrix.arch }} 59 | 60 | - name: 'Configure CMake' 61 | working-directory: ${{ github.workspace }}/Tests 62 | run: cmake --preset=${{ matrix.build_type }} -DBUILD_DXIL_SHADERS=OFF 63 | 64 | - name: 'Build' 65 | working-directory: ${{ github.workspace }}/Tests 66 | run: cmake --build out\build\${{ matrix.build_type }} 67 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: 'CMake (Windows DXC)' 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | - build/*.json 15 | 16 | permissions: 17 | contents: read 18 | 19 | jobs: 20 | build: 21 | runs-on: ${{ matrix.os }} 22 | 23 | strategy: 24 | fail-fast: false 25 | 26 | matrix: 27 | os: [windows-2019, windows-2022] 28 | build_type: [x64-Debug, x64-Release] 29 | arch: [amd64] 30 | include: 31 | - os: windows-2019 32 | build_type: x86-Debug 33 | arch: amd64_x86 34 | - os: windows-2019 35 | build_type: x86-Release 36 | arch: amd64_x86 37 | - os: windows-2022 38 | build_type: x86-Debug 39 | arch: amd64_x86 40 | - os: windows-2022 41 | build_type: x86-Release 42 | arch: amd64_x86 43 | - os: windows-2022 44 | build_type: x64-Debug-Clang 45 | arch: amd64 46 | - os: windows-2022 47 | build_type: x64-Release-Clang 48 | arch: amd64 49 | - os: windows-2022 50 | build_type: x86-Debug-Clang 51 | arch: amd64_x86 52 | - os: windows-2022 53 | build_type: x86-Release-Clang 54 | arch: amd64_x86 55 | - os: windows-2022 56 | build_type: arm64-Debug 57 | arch: amd64_arm64 58 | - os: windows-2022 59 | build_type: arm64-Release 60 | arch: amd64_arm64 61 | - os: windows-2022 62 | build_type: arm64ec-Debug 63 | arch: amd64_arm64 64 | - os: windows-2022 65 | build_type: arm64ec-Release 66 | arch: amd64_arm64 67 | 68 | steps: 69 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 70 | 71 | - name: 'Install Ninja' 72 | run: choco install ninja 73 | 74 | - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 75 | with: 76 | arch: ${{ matrix.arch }} 77 | 78 | - name: 'Configure CMake' 79 | working-directory: ${{ github.workspace }}/Tests 80 | run: cmake --preset=${{ matrix.build_type }} -DBUILD_DXIL_SHADERS=ON 81 | 82 | - name: 'Build' 83 | working-directory: ${{ github.workspace }}/Tests 84 | run: cmake --build out\build\${{ matrix.build_type }} 85 | -------------------------------------------------------------------------------- /.github/workflows/msvc.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: Microsoft C++ Code Analysis 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | - build/*.json 15 | schedule: 16 | - cron: '20 21 * * 2' 17 | 18 | permissions: 19 | contents: read 20 | 21 | jobs: 22 | analyze: 23 | permissions: 24 | contents: read 25 | security-events: write 26 | actions: read 27 | name: Analyze 28 | runs-on: windows-latest 29 | 30 | steps: 31 | - name: Checkout repository 32 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 33 | 34 | - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 35 | with: 36 | arch: amd64 37 | 38 | - name: Configure CMake 39 | working-directory: ${{ github.workspace }}/Tests 40 | run: cmake -B out -DBUILD_DXIL_SHADERS=ON 41 | 42 | - name: Initialize MSVC Code Analysis 43 | uses: microsoft/msvc-code-analysis-action@24c285ab36952c9e9182f4b78dfafbac38a7e5ee # v0.1.1 44 | id: run-analysis 45 | with: 46 | cmakeBuildDirectory: Tests/out 47 | buildConfiguration: Debug 48 | ruleset: NativeRecommendedRules.ruleset 49 | 50 | # Upload SARIF file to GitHub Code Scanning Alerts 51 | - name: Upload SARIF to GitHub 52 | uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 53 | with: 54 | sarif_file: ${{ steps.run-analysis.outputs.sarif }} 55 | -------------------------------------------------------------------------------- /.github/workflows/vcpkg.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: 'CMake (Windows DXC using VCPKG)' 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | build: 20 | runs-on: ${{ matrix.os }} 21 | 22 | strategy: 23 | fail-fast: false 24 | 25 | matrix: 26 | os: [windows-2019, windows-2022] 27 | build_type: [x64-Debug-VCPKG] 28 | arch: [amd64] 29 | include: 30 | - os: windows-2022 31 | build_type: x64-Debug-Clang-VCPKG 32 | arch: amd64 33 | - os: windows-2022 34 | build_type: x86-Debug-VCPKG 35 | arch: amd64_x86 36 | - os: windows-2022 37 | build_type: arm64-Debug-VCPKG 38 | arch: amd64_arm64 39 | 40 | steps: 41 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 42 | 43 | - name: 'Install Ninja' 44 | run: choco install ninja 45 | 46 | - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 47 | with: 48 | arch: ${{ matrix.arch }} 49 | 50 | - name: 'Set triplet' 51 | shell: pwsh 52 | run: | 53 | echo "VCPKG_INSTALLED_DIR=${{ github.workspace }}/build/vcpkg_installed" >> $env:GITHUB_ENV 54 | if ("${{ matrix.arch }}" -eq "amd64") 55 | { 56 | echo "VCPKG_DEFAULT_TRIPLET=x64-windows" >> $env:GITHUB_ENV 57 | } 58 | elseif ("${{ matrix.arch }}" -eq "amd64_x86") 59 | { 60 | echo "VCPKG_DEFAULT_TRIPLET=x86-windows" >> $env:GITHUB_ENV 61 | } 62 | elseif ("${{ matrix.arch }}" -eq "amd64_arm64") 63 | { 64 | if ("${{ matrix.build_type }}" -match "^arm64ec") 65 | { 66 | echo "VCPKG_DEFAULT_TRIPLET=arm64ec-windows" >> $env:GITHUB_ENV 67 | } 68 | else 69 | { 70 | echo "VCPKG_DEFAULT_TRIPLET=arm64-windows" >> $env:GITHUB_ENV 71 | } 72 | } 73 | else 74 | { 75 | echo "::error Unknown architecture/build-type triplet mapping" 76 | } 77 | 78 | - uses: lukka/run-vcpkg@7d259227a1fb6471a0253dd5ab7419835228f7d7 # v11 79 | with: 80 | runVcpkgInstall: true 81 | vcpkgJsonGlob: '**/build/vcpkg.json' 82 | vcpkgGitCommitId: '7516a02de04e8f8ff4e4beb8f5bac0565f9bf9da' 83 | 84 | - name: 'Configure CMake' 85 | working-directory: ${{ github.workspace }}/Tests 86 | run: > 87 | cmake --preset=${{ matrix.build_type }} -DBUILD_DXIL_SHADERS=ON 88 | -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_MANIFEST_DIR="${{ github.workspace }}/build" 89 | -DVCPKG_TARGET_TRIPLET="${env:VCPKG_DEFAULT_TRIPLET}" 90 | -DVCPKG_HOST_TRIPLET=x64-windows 91 | 92 | - name: 'Build' 93 | working-directory: ${{ github.workspace }}/Tests 94 | run: cmake --build out\build\${{ matrix.build_type }} 95 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.psess 2 | *.vsp 3 | *.log 4 | *.err 5 | *.wrn 6 | *.suo 7 | *.sdf 8 | *.user 9 | *.i 10 | *.vspscc 11 | *.opensdf 12 | *.opendb 13 | *.ipch 14 | *.cache 15 | *.tlog 16 | *.lastbuildstate 17 | *.ilk 18 | *.VC.db 19 | *.nupkg 20 | .vs 21 | /wiki 22 | /out 23 | /CMakeUserPresets.json 24 | /build/vcpkg_installed 25 | -------------------------------------------------------------------------------- /D3DX_DXGIFormatConvert.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | //============================================================================= 5 | // D3D11 HLSL Routines for Manual Pack/Unpack of 32-bit DXGI_FORMAT_* 6 | //============================================================================= 7 | // 8 | // This file contains format conversion routines for use in the 9 | // Compute Shader or Pixel Shader on D3D11 Hardware. 10 | // 11 | // Skip to the end of this comment to see a summary of the routines 12 | // provided. The rest of the text below explains why they are needed 13 | // and how to use them. 14 | // 15 | // The scenario where these can be useful is if your application 16 | // needs to simultaneously both read and write texture - i.e. in-place 17 | // image editing. 18 | // 19 | // D3D11's Unordered Access View (UAV) of a Texture1D/2D/3D resource 20 | // allows random access reads and writes to memory from a Compute Shader 21 | // or Pixel Shader. However, the only texture format that supports this 22 | // is DXGI_FORMAT_R32_UINT. e.g. Other more interesting formats like 23 | // DXGI_FORMAT_R8G8B8A8_UNORM do not support simultaneous read and 24 | // write. You can use such formats for random access writing only 25 | // using a UAV, or reading only using a Shader Resource View (SRV). 26 | // But for simultaneous read+write, the format conversion hardware is 27 | // not available. 28 | // 29 | // There is a workaround to this limitation, involving casting the texture 30 | // to R32_UINT when creating a UAV, as long as the original format of the 31 | // resource supports it (most 32 bit per element formats). This allows 32 | // simultaneous read+write as long as the shader does manual format 33 | // unpacking on read and packing on write. 34 | // 35 | // The benefit is that later on, other views such as RenderTarget Views 36 | // or ShaderResource Views on the same texture can be used with the 37 | // proper format (e.g. DXGI_FORMAT_R16G16_FLOAT) so the hardware can 38 | // do the usual automatic format unpack/pack and do texture filtering etc. 39 | // where there are no hardware limitations. 40 | // 41 | // The sequence of actions for an application is the following: 42 | // 43 | // Suppose you want to make a texture than you can use a Pixel Shader 44 | // or Compute Shader to perform in-place editing, and that the format 45 | // you want the data to be stored in happens to be a descendent 46 | // of of one of these formats: 47 | // 48 | // DXGI_FORMAT_R10G10B10A2_TYPELESS 49 | // DXGI_FORMAT_R8G8B8A8_TYPELESS 50 | // DXGI_FORMAT_B8G8R8A8_TYPELESS 51 | // DXGI_FORMAT_B8G8R8X8_TYPELESS 52 | // DXGI_FORMAT_R16G16_TYPELESS 53 | // 54 | // e.g. DXGI_FORMAT_R10G10B10A2_UNORM is a descendent of 55 | // DXGI_FORMAT_R10G10B10A2_TYPELESS, so it supports the 56 | // usage pattern described here. 57 | // 58 | // (Formats descending from DXGI_FORMAT_R32_TYPELESS, such as 59 | // DXGI_FORMAT_R32_FLOAT, are trivially supported without 60 | // needing any of the format conversion help provided here.) 61 | // 62 | // Steps: 63 | // 64 | // (1) Create a texture with the appropriate _TYPELESS format above 65 | // along with the needed bind flags, such as 66 | // D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE. 67 | // 68 | // (2) For in-place image editing, create a UAV with the format 69 | // DXGI_FORMAT_R32_UINT. D3D normally doesn't allow casting 70 | // between different format "families", but the API makes 71 | // an exception here. 72 | // 73 | // (3) In the Compute Shader or Pixel Shader, use the appropriate 74 | // format pack/unpack routines provided in this file. 75 | // For example if the DXGI_FORMAT_R32_UINT UAV really holds 76 | // DXGI_FORMAT_R10G10B10A2_UNORM data, then, after reading a 77 | // uint from the UAV into the shader, unpack by calling: 78 | // 79 | // XMFLOAT4 D3DX_R10G10B10A2_UNORM_to_FLOAT4(UINT packedInput) 80 | // 81 | // Then to write to the UAV in the same shader, call the following 82 | // to pack shader data into a uint that can be written out: 83 | // 84 | // UINT D3DX_FLOAT4_to_R10G10B10A2_UNORM(hlsl_precise XMFLOAT4 unpackedInput) 85 | // 86 | // (4) Other views, such as SRVs, can be created with the desired format; 87 | // e.g. DXGI_FORMAT_R10G10B10A2_UNORM if the resource was created as 88 | // DXGI_FORMAT_R10G10B10A2_TYPELESS. When that view is accessed by a 89 | // shader, the hardware can do automatic type conversion as usual. 90 | // 91 | // Note, again, that if the shader only needs to write to a UAV, or read 92 | // as an SRV, then none of this is needed - fully typed UAV or SRVs can 93 | // be used. Only if simultaneous reading and writing to a UAV of a texture 94 | // is needed are the format conversion routines provided here potentially 95 | // useful. 96 | // 97 | // The following is the list of format conversion routines included in this 98 | // file, categorized by the DXGI_FORMAT they unpack/pack. Each of the 99 | // formats supported descends from one of the TYPELESS formats listed 100 | // above, and supports casting to DXGI_FORMAT_R32_UINT as a UAV. 101 | // 102 | // DXGI_FORMAT_R10G10B10A2_UNORM: 103 | // 104 | // XMFLOAT4 D3DX_R10G10B10A2_UNORM_to_FLOAT4(UINT packedInput) 105 | // UINT D3DX_FLOAT4_to_R10G10B10A2_UNORM(hlsl_precise XMFLOAT4 unpackedInput) 106 | // 107 | // DXGI_FORMAT_R10G10B10A2_UINT: 108 | // 109 | // XMUINT4 D3DX_R10G10B10A2_UINT_to_UINT4(UINT packedInput) 110 | // UINT D3DX_UINT4_to_R10G10B10A2_UINT(XMUINT4 unpackedInput) 111 | // 112 | // DXGI_FORMAT_R8G8B8A8_UNORM: 113 | // 114 | // XMFLOAT4 D3DX_R8G8B8A8_UNORM_to_FLOAT4(UINT packedInput) 115 | // UINT D3DX_FLOAT4_to_R8G8B8A8_UNORM(hlsl_precise XMFLOAT4 unpackedInput) 116 | // 117 | // DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: 118 | // 119 | // XMFLOAT4 D3DX_R8G8B8A8_UNORM_SRGB_to_FLOAT4_inexact(UINT packedInput) * 120 | // XMFLOAT4 D3DX_R8G8B8A8_UNORM_SRGB_to_FLOAT4(UINT packedInput) 121 | // UINT D3DX_FLOAT4_to_R8G8B8A8_UNORM_SRGB(hlsl_precise XMFLOAT4 unpackedInput) 122 | // 123 | // * The "_inexact" function above uses shader instructions that don't 124 | // have high enough precision to give the exact answer, albeit close. 125 | // The alternative function uses a lookup table stored in the shader 126 | // to give an exact SRGB->float conversion. 127 | // 128 | // DXGI_FORMAT_R8G8B8A8_UINT: 129 | // 130 | // XMUINT4 D3DX_R8G8B8A8_UINT_to_UINT4(UINT packedInput) 131 | // XMUINT D3DX_UINT4_to_R8G8B8A8_UINT(XMUINT4 unpackedInput) 132 | // 133 | // DXGI_FORMAT_R8G8B8A8_SNORM: 134 | // 135 | // XMFLOAT4 D3DX_R8G8B8A8_SNORM_to_FLOAT4(UINT packedInput) 136 | // UINT D3DX_FLOAT4_to_R8G8B8A8_SNORM(hlsl_precise XMFLOAT4 unpackedInput) 137 | // 138 | // DXGI_FORMAT_R8G8B8A8_SINT: 139 | // 140 | // XMINT4 D3DX_R8G8B8A8_SINT_to_INT4(UINT packedInput) 141 | // UINT D3DX_INT4_to_R8G8B8A8_SINT(XMINT4 unpackedInput) 142 | // 143 | // DXGI_FORMAT_B8G8R8A8_UNORM: 144 | // 145 | // XMFLOAT4 D3DX_B8G8R8A8_UNORM_to_FLOAT4(UINT packedInput) 146 | // UINT D3DX_FLOAT4_to_B8G8R8A8_UNORM(hlsl_precise XMFLOAT4 unpackedInput) 147 | // 148 | // DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: 149 | // 150 | // XMFLOAT4 D3DX_B8G8R8A8_UNORM_SRGB_to_FLOAT4_inexact(UINT packedInput) * 151 | // XMFLOAT4 D3DX_B8G8R8A8_UNORM_SRGB_to_FLOAT4(UINT packedInput) 152 | // UINT D3DX_FLOAT4_to_R8G8B8A8_UNORM_SRGB(hlsl_precise XMFLOAT4 unpackedInput) 153 | // 154 | // * The "_inexact" function above uses shader instructions that don't 155 | // have high enough precision to give the exact answer, albeit close. 156 | // The alternative function uses a lookup table stored in the shader 157 | // to give an exact SRGB->float conversion. 158 | // 159 | // DXGI_FORMAT_B8G8R8X8_UNORM: 160 | // 161 | // XMFLOAT3 D3DX_B8G8R8X8_UNORM_to_FLOAT3(UINT packedInput) 162 | // UINT D3DX_FLOAT3_to_B8G8R8X8_UNORM(hlsl_precise XMFLOAT3 unpackedInput) 163 | // 164 | // DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: 165 | // 166 | // XMFLOAT3 D3DX_B8G8R8X8_UNORM_SRGB_to_FLOAT3_inexact(UINT packedInput) * 167 | // XMFLOAT3 D3DX_B8G8R8X8_UNORM_SRGB_to_FLOAT3(UINT packedInput) 168 | // UINT D3DX_FLOAT3_to_B8G8R8X8_UNORM_SRGB(hlsl_precise XMFLOAT3 unpackedInput) 169 | // 170 | // * The "_inexact" function above uses shader instructions that don't 171 | // have high enough precision to give the exact answer, albeit close. 172 | // The alternative function uses a lookup table stored in the shader 173 | // to give an exact SRGB->float conversion. 174 | // 175 | // DXGI_FORMAT_R16G16_FLOAT: 176 | // 177 | // XMFLOAT2 D3DX_R16G16_FLOAT_to_FLOAT2(UINT packedInput) 178 | // UINT D3DX_FLOAT2_to_R16G16_FLOAT(hlsl_precise XMFLOAT2 unpackedInput) 179 | // 180 | // DXGI_FORMAT_R16G16_UNORM: 181 | // 182 | // XMFLOAT2 D3DX_R16G16_UNORM_to_FLOAT2(UINT packedInput) 183 | // UINT D3DX_FLOAT2_to_R16G16_UNORM(hlsl_precise FLOAT2 unpackedInput) 184 | // 185 | // DXGI_FORMAT_R16G16_UINT: 186 | // 187 | // XMUINT2 D3DX_R16G16_UINT_to_UINT2(UINT packedInput) 188 | // UINT D3DX_UINT2_to_R16G16_UINT(XMUINT2 unpackedInput) 189 | // 190 | // DXGI_FORMAT_R16G16_SNORM: 191 | // 192 | // XMFLOAT2 D3DX_R16G16_SNORM_to_FLOAT2(UINT packedInput) 193 | // UINT D3DX_FLOAT2_to_R16G16_SNORM(hlsl_precise XMFLOAT2 unpackedInput) 194 | // 195 | // DXGI_FORMAT_R16G16_SINT: 196 | // 197 | // XMINT2 D3DX_R16G16_SINT_to_INT2(UINT packedInput) 198 | // UINT D3DX_INT2_to_R16G16_SINT(XMINT2 unpackedInput) 199 | // 200 | //============================================================================= 201 | 202 | #ifndef __D3DX_DXGI_FORMAT_CONVERT_INL___ 203 | #define __D3DX_DXGI_FORMAT_CONVERT_INL___ 204 | 205 | #if (HLSL_VERSION > 0) || (__HLSL_VERSION > 0) 206 | 207 | #pragma warning(disable: 3577) 208 | 209 | #define D3DX11INLINE 210 | 211 | typedef float FLOAT; 212 | typedef int INT; 213 | typedef uint UINT; 214 | 215 | typedef float2 XMFLOAT2; 216 | typedef float3 XMFLOAT3; 217 | typedef float4 XMFLOAT4; 218 | typedef int2 XMINT2; 219 | typedef int4 XMINT4; 220 | typedef uint2 XMUINT2; 221 | typedef uint4 XMUINT4; 222 | 223 | #define hlsl_precise precise 224 | 225 | #define D3DX_Saturate_FLOAT(_V) saturate(_V) 226 | #define D3DX_IsNan(_V) isnan(_V) 227 | #define D3DX_Truncate_FLOAT(_V) trunc(_V) 228 | 229 | #else 230 | 231 | #ifndef __cplusplus 232 | #error C++ compilation required 233 | #endif 234 | 235 | #ifndef D3DX11INLINE 236 | #define D3DX11INLINE inline 237 | #endif 238 | 239 | #include 240 | 241 | #include 242 | #include 243 | #include 244 | 245 | #define hlsl_precise 246 | 247 | namespace DirectX 248 | { 249 | 250 | D3DX11INLINE float D3DX_Saturate_FLOAT(float _V) 251 | { 252 | return std::min(std::max(_V, 0), 1); 253 | } 254 | D3DX11INLINE bool D3DX_IsNan(float _V) 255 | { 256 | return isnan(_V); 257 | } 258 | D3DX11INLINE float D3DX_Truncate_FLOAT(float _V) 259 | { 260 | return _V >= 0 ? floorf(_V) : ceilf(_V); 261 | } 262 | 263 | #endif 264 | 265 | //============================================================================= 266 | // SRGB Helper Functions Called By Conversions Further Below. 267 | //============================================================================= 268 | // SRGB_to_FLOAT_inexact is imprecise due to precision of pow implementations. 269 | // If exact SRGB->float conversion is needed, a table lookup is provided 270 | // further below. 271 | D3DX11INLINE FLOAT D3DX_SRGB_to_FLOAT_inexact(hlsl_precise FLOAT val) 272 | { 273 | if( val < 0.04045f ) 274 | val /= 12.92f; 275 | else 276 | val = pow((val + 0.055f)/1.055f,2.4f); 277 | return val; 278 | } 279 | 280 | static const UINT D3DX_SRGBTable[] = 281 | { 282 | 0x00000000,0x399f22b4,0x3a1f22b4,0x3a6eb40e,0x3a9f22b4,0x3ac6eb61,0x3aeeb40e,0x3b0b3e5d, 283 | 0x3b1f22b4,0x3b33070b,0x3b46eb61,0x3b5b518d,0x3b70f18d,0x3b83e1c6,0x3b8fe616,0x3b9c87fd, 284 | 0x3ba9c9b7,0x3bb7ad6f,0x3bc63549,0x3bd56361,0x3be539c1,0x3bf5ba70,0x3c0373b5,0x3c0c6152, 285 | 0x3c15a703,0x3c1f45be,0x3c293e6b,0x3c3391f7,0x3c3e4149,0x3c494d43,0x3c54b6c7,0x3c607eb1, 286 | 0x3c6ca5df,0x3c792d22,0x3c830aa8,0x3c89af9f,0x3c9085db,0x3c978dc5,0x3c9ec7c2,0x3ca63433, 287 | 0x3cadd37d,0x3cb5a601,0x3cbdac20,0x3cc5e639,0x3cce54ab,0x3cd6f7d5,0x3cdfd010,0x3ce8ddb9, 288 | 0x3cf2212c,0x3cfb9ac1,0x3d02a569,0x3d0798dc,0x3d0ca7e6,0x3d11d2af,0x3d171963,0x3d1c7c2e, 289 | 0x3d21fb3c,0x3d2796b2,0x3d2d4ebb,0x3d332380,0x3d39152b,0x3d3f23e3,0x3d454fd1,0x3d4b991c, 290 | 0x3d51ffef,0x3d58846a,0x3d5f26b7,0x3d65e6fe,0x3d6cc564,0x3d73c20f,0x3d7add29,0x3d810b67, 291 | 0x3d84b795,0x3d887330,0x3d8c3e4a,0x3d9018f6,0x3d940345,0x3d97fd4a,0x3d9c0716,0x3da020bb, 292 | 0x3da44a4b,0x3da883d7,0x3daccd70,0x3db12728,0x3db59112,0x3dba0b3b,0x3dbe95b5,0x3dc33092, 293 | 0x3dc7dbe2,0x3dcc97b6,0x3dd1641f,0x3dd6412c,0x3ddb2eef,0x3de02d77,0x3de53cd5,0x3dea5d19, 294 | 0x3def8e52,0x3df4d091,0x3dfa23e8,0x3dff8861,0x3e027f07,0x3e054280,0x3e080ea3,0x3e0ae378, 295 | 0x3e0dc105,0x3e10a754,0x3e13966b,0x3e168e52,0x3e198f10,0x3e1c98ad,0x3e1fab30,0x3e22c6a3, 296 | 0x3e25eb09,0x3e29186c,0x3e2c4ed0,0x3e2f8e41,0x3e32d6c4,0x3e362861,0x3e39831e,0x3e3ce703, 297 | 0x3e405416,0x3e43ca5f,0x3e4749e4,0x3e4ad2ae,0x3e4e64c2,0x3e520027,0x3e55a4e6,0x3e595303, 298 | 0x3e5d0a8b,0x3e60cb7c,0x3e6495e0,0x3e6869bf,0x3e6c4720,0x3e702e0c,0x3e741e84,0x3e781890, 299 | 0x3e7c1c38,0x3e8014c2,0x3e82203c,0x3e84308d,0x3e8645ba,0x3e885fc5,0x3e8a7eb2,0x3e8ca283, 300 | 0x3e8ecb3d,0x3e90f8e1,0x3e932b74,0x3e9562f8,0x3e979f71,0x3e99e0e2,0x3e9c274e,0x3e9e72b7, 301 | 0x3ea0c322,0x3ea31892,0x3ea57308,0x3ea7d289,0x3eaa3718,0x3eaca0b7,0x3eaf0f69,0x3eb18333, 302 | 0x3eb3fc18,0x3eb67a18,0x3eb8fd37,0x3ebb8579,0x3ebe12e1,0x3ec0a571,0x3ec33d2d,0x3ec5da17, 303 | 0x3ec87c33,0x3ecb2383,0x3ecdd00b,0x3ed081cd,0x3ed338cc,0x3ed5f50b,0x3ed8b68d,0x3edb7d54, 304 | 0x3ede4965,0x3ee11ac1,0x3ee3f16b,0x3ee6cd67,0x3ee9aeb6,0x3eec955d,0x3eef815d,0x3ef272ba, 305 | 0x3ef56976,0x3ef86594,0x3efb6717,0x3efe6e02,0x3f00bd2d,0x3f02460e,0x3f03d1a7,0x3f055ff9, 306 | 0x3f06f106,0x3f0884cf,0x3f0a1b56,0x3f0bb49b,0x3f0d50a0,0x3f0eef67,0x3f1090f1,0x3f12353e, 307 | 0x3f13dc51,0x3f15862b,0x3f1732cd,0x3f18e239,0x3f1a946f,0x3f1c4971,0x3f1e0141,0x3f1fbbdf, 308 | 0x3f21794e,0x3f23398e,0x3f24fca0,0x3f26c286,0x3f288b41,0x3f2a56d3,0x3f2c253d,0x3f2df680, 309 | 0x3f2fca9e,0x3f31a197,0x3f337b6c,0x3f355820,0x3f3737b3,0x3f391a26,0x3f3aff7c,0x3f3ce7b5, 310 | 0x3f3ed2d2,0x3f40c0d4,0x3f42b1be,0x3f44a590,0x3f469c4b,0x3f4895f1,0x3f4a9282,0x3f4c9201, 311 | 0x3f4e946e,0x3f5099cb,0x3f52a218,0x3f54ad57,0x3f56bb8a,0x3f58ccb0,0x3f5ae0cd,0x3f5cf7e0, 312 | 0x3f5f11ec,0x3f612eee,0x3f634eef,0x3f6571e9,0x3f6797e3,0x3f69c0d6,0x3f6beccd,0x3f6e1bbf, 313 | 0x3f704db8,0x3f7282af,0x3f74baae,0x3f76f5ae,0x3f7933b9,0x3f7b74c6,0x3f7db8e0,0x3f800000 314 | }; 315 | 316 | D3DX11INLINE FLOAT D3DX_SRGB_to_FLOAT(UINT val) 317 | { 318 | #if (HLSL_VERSION > 0) || (__HLSL_VERSION > 0) 319 | return asfloat(D3DX_SRGBTable[val]); 320 | #else 321 | return *reinterpret_cast(&D3DX_SRGBTable[val]); 322 | #endif 323 | } 324 | 325 | D3DX11INLINE FLOAT D3DX_FLOAT_to_SRGB(hlsl_precise FLOAT val) 326 | { 327 | if( val < 0.0031308f ) 328 | val *= 12.92f; 329 | else 330 | val = 1.055f * pow(val,1.0f/2.4f) - 0.055f; 331 | return val; 332 | } 333 | 334 | D3DX11INLINE FLOAT D3DX_SaturateSigned_FLOAT(FLOAT _V) 335 | { 336 | if (D3DX_IsNan(_V)) 337 | { 338 | return 0; 339 | } 340 | 341 | return min(max(_V, -1), 1); 342 | } 343 | 344 | D3DX11INLINE UINT D3DX_FLOAT_to_UINT(FLOAT _V, 345 | FLOAT _Scale) 346 | { 347 | return (UINT)floor(_V * _Scale + 0.5f); 348 | } 349 | 350 | D3DX11INLINE FLOAT D3DX_INT_to_FLOAT(INT _V, 351 | FLOAT _Scale) 352 | { 353 | FLOAT Scaled = (FLOAT)_V / _Scale; 354 | // The integer is a two's-complement signed 355 | // number so the negative range is slightly 356 | // larger than the positive range, meaning 357 | // the scaled value can be slight less than -1. 358 | // Clamp to keep the float range [-1, 1]. 359 | return max(Scaled, -1.0f); 360 | } 361 | 362 | D3DX11INLINE INT D3DX_FLOAT_to_INT(FLOAT _V, 363 | FLOAT _Scale) 364 | { 365 | return (INT)D3DX_Truncate_FLOAT(_V * _Scale + (_V >= 0 ? 0.5f : -0.5f)); 366 | } 367 | 368 | //============================================================================= 369 | // Conversion routines 370 | //============================================================================= 371 | //----------------------------------------------------------------------------- 372 | // R10B10G10A2_UNORM <-> FLOAT4 373 | //----------------------------------------------------------------------------- 374 | D3DX11INLINE XMFLOAT4 D3DX_R10G10B10A2_UNORM_to_FLOAT4(UINT packedInput) 375 | { 376 | hlsl_precise XMFLOAT4 unpackedOutput; 377 | unpackedOutput.x = (FLOAT) (packedInput & 0x000003ff) / 1023; 378 | unpackedOutput.y = (FLOAT)(((packedInput>>10) & 0x000003ff)) / 1023; 379 | unpackedOutput.z = (FLOAT)(((packedInput>>20) & 0x000003ff)) / 1023; 380 | unpackedOutput.w = (FLOAT)(((packedInput>>30) & 0x00000003)) / 3; 381 | return unpackedOutput; 382 | } 383 | 384 | D3DX11INLINE UINT D3DX_FLOAT4_to_R10G10B10A2_UNORM(hlsl_precise XMFLOAT4 unpackedInput) 385 | { 386 | UINT packedOutput; 387 | packedOutput = ( (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.x), 1023)) | 388 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.y), 1023)<<10) | 389 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.z), 1023)<<20) | 390 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.w), 3)<<30) ); 391 | return packedOutput; 392 | } 393 | 394 | //----------------------------------------------------------------------------- 395 | // R10B10G10A2_UINT <-> UINT4 396 | //----------------------------------------------------------------------------- 397 | D3DX11INLINE XMUINT4 D3DX_R10G10B10A2_UINT_to_UINT4(UINT packedInput) 398 | { 399 | XMUINT4 unpackedOutput; 400 | unpackedOutput.x = packedInput & 0x000003ff; 401 | unpackedOutput.y = (packedInput>>10) & 0x000003ff; 402 | unpackedOutput.z = (packedInput>>20) & 0x000003ff; 403 | unpackedOutput.w = (packedInput>>30) & 0x00000003; 404 | return unpackedOutput; 405 | } 406 | 407 | D3DX11INLINE UINT D3DX_UINT4_to_R10G10B10A2_UINT(XMUINT4 unpackedInput) 408 | { 409 | UINT packedOutput; 410 | unpackedInput.x = min(unpackedInput.x, 0x000003ff); 411 | unpackedInput.y = min(unpackedInput.y, 0x000003ff); 412 | unpackedInput.z = min(unpackedInput.z, 0x000003ff); 413 | unpackedInput.w = min(unpackedInput.w, 0x00000003); 414 | packedOutput = ( (unpackedInput.x) | 415 | ((unpackedInput.y)<<10) | 416 | ((unpackedInput.z)<<20) | 417 | ((unpackedInput.w)<<30) ); 418 | return packedOutput; 419 | } 420 | 421 | //----------------------------------------------------------------------------- 422 | // R8G8B8A8_UNORM <-> FLOAT4 423 | //----------------------------------------------------------------------------- 424 | D3DX11INLINE XMFLOAT4 D3DX_R8G8B8A8_UNORM_to_FLOAT4(UINT packedInput) 425 | { 426 | hlsl_precise XMFLOAT4 unpackedOutput; 427 | unpackedOutput.x = (FLOAT) (packedInput & 0x000000ff) / 255; 428 | unpackedOutput.y = (FLOAT)(((packedInput>> 8) & 0x000000ff)) / 255; 429 | unpackedOutput.z = (FLOAT)(((packedInput>>16) & 0x000000ff)) / 255; 430 | unpackedOutput.w = (FLOAT) (packedInput>>24) / 255; 431 | return unpackedOutput; 432 | } 433 | 434 | D3DX11INLINE UINT D3DX_FLOAT4_to_R8G8B8A8_UNORM(hlsl_precise XMFLOAT4 unpackedInput) 435 | { 436 | UINT packedOutput; 437 | packedOutput = ( (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.x), 255)) | 438 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.y), 255)<< 8) | 439 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.z), 255)<<16) | 440 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.w), 255)<<24) ); 441 | return packedOutput; 442 | } 443 | 444 | //----------------------------------------------------------------------------- 445 | // R8G8B8A8_UNORM_SRGB <-> FLOAT4 446 | //----------------------------------------------------------------------------- 447 | D3DX11INLINE XMFLOAT4 D3DX_R8G8B8A8_UNORM_SRGB_to_FLOAT4_inexact(UINT packedInput) 448 | { 449 | hlsl_precise XMFLOAT4 unpackedOutput; 450 | unpackedOutput.x = D3DX_SRGB_to_FLOAT_inexact(((FLOAT) (packedInput & 0x000000ff) )/255); 451 | unpackedOutput.y = D3DX_SRGB_to_FLOAT_inexact(((FLOAT)(((packedInput>> 8) & 0x000000ff)))/255); 452 | unpackedOutput.z = D3DX_SRGB_to_FLOAT_inexact(((FLOAT)(((packedInput>>16) & 0x000000ff)))/255); 453 | unpackedOutput.w = (FLOAT)(packedInput>>24) / 255; 454 | return unpackedOutput; 455 | } 456 | 457 | D3DX11INLINE XMFLOAT4 D3DX_R8G8B8A8_UNORM_SRGB_to_FLOAT4(UINT packedInput) 458 | { 459 | hlsl_precise XMFLOAT4 unpackedOutput; 460 | unpackedOutput.x = D3DX_SRGB_to_FLOAT( (packedInput & 0x000000ff) ); 461 | unpackedOutput.y = D3DX_SRGB_to_FLOAT((((packedInput>> 8) & 0x000000ff))); 462 | unpackedOutput.z = D3DX_SRGB_to_FLOAT((((packedInput>>16) & 0x000000ff))); 463 | unpackedOutput.w = (FLOAT)(packedInput>>24) / 255; 464 | return unpackedOutput; 465 | } 466 | 467 | D3DX11INLINE UINT D3DX_FLOAT4_to_R8G8B8A8_UNORM_SRGB(hlsl_precise XMFLOAT4 unpackedInput) 468 | { 469 | UINT packedOutput; 470 | unpackedInput.x = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.x)); 471 | unpackedInput.y = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.y)); 472 | unpackedInput.z = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.z)); 473 | unpackedInput.w = D3DX_Saturate_FLOAT(unpackedInput.w); 474 | packedOutput = ( (D3DX_FLOAT_to_UINT(unpackedInput.x, 255)) | 475 | (D3DX_FLOAT_to_UINT(unpackedInput.y, 255)<< 8) | 476 | (D3DX_FLOAT_to_UINT(unpackedInput.z, 255)<<16) | 477 | (D3DX_FLOAT_to_UINT(unpackedInput.w, 255)<<24) ); 478 | return packedOutput; 479 | } 480 | 481 | //----------------------------------------------------------------------------- 482 | // R8G8B8A8_UINT <-> UINT4 483 | //----------------------------------------------------------------------------- 484 | D3DX11INLINE XMUINT4 D3DX_R8G8B8A8_UINT_to_UINT4(UINT packedInput) 485 | { 486 | XMUINT4 unpackedOutput; 487 | unpackedOutput.x = packedInput & 0x000000ff; 488 | unpackedOutput.y = (packedInput>> 8) & 0x000000ff; 489 | unpackedOutput.z = (packedInput>>16) & 0x000000ff; 490 | unpackedOutput.w = packedInput>>24; 491 | return unpackedOutput; 492 | } 493 | 494 | D3DX11INLINE UINT D3DX_UINT4_to_R8G8B8A8_UINT(XMUINT4 unpackedInput) 495 | { 496 | UINT packedOutput; 497 | unpackedInput.x = min(unpackedInput.x, 0x000000ff); 498 | unpackedInput.y = min(unpackedInput.y, 0x000000ff); 499 | unpackedInput.z = min(unpackedInput.z, 0x000000ff); 500 | unpackedInput.w = min(unpackedInput.w, 0x000000ff); 501 | packedOutput = ( unpackedInput.x | 502 | (unpackedInput.y<< 8) | 503 | (unpackedInput.z<<16) | 504 | (unpackedInput.w<<24) ); 505 | return packedOutput; 506 | } 507 | 508 | //----------------------------------------------------------------------------- 509 | // R8G8B8A8_SNORM <-> FLOAT4 510 | //----------------------------------------------------------------------------- 511 | D3DX11INLINE XMFLOAT4 D3DX_R8G8B8A8_SNORM_to_FLOAT4(UINT packedInput) 512 | { 513 | hlsl_precise XMFLOAT4 unpackedOutput; 514 | XMINT4 signExtendedBits; 515 | signExtendedBits.x = (INT)(packedInput << 24) >> 24; 516 | signExtendedBits.y = (INT)((packedInput << 16) & 0xff000000) >> 24; 517 | signExtendedBits.z = (INT)((packedInput << 8) & 0xff000000) >> 24; 518 | signExtendedBits.w = (INT)(packedInput & 0xff000000) >> 24; 519 | unpackedOutput.x = D3DX_INT_to_FLOAT(signExtendedBits.x, 127); 520 | unpackedOutput.y = D3DX_INT_to_FLOAT(signExtendedBits.y, 127); 521 | unpackedOutput.z = D3DX_INT_to_FLOAT(signExtendedBits.z, 127); 522 | unpackedOutput.w = D3DX_INT_to_FLOAT(signExtendedBits.w, 127); 523 | return unpackedOutput; 524 | } 525 | 526 | D3DX11INLINE UINT D3DX_FLOAT4_to_R8G8B8A8_SNORM(hlsl_precise XMFLOAT4 unpackedInput) 527 | { 528 | UINT packedOutput; 529 | packedOutput = ( (D3DX_FLOAT_to_INT(D3DX_SaturateSigned_FLOAT(unpackedInput.x), 127) & 0x000000ff) | 530 | ((D3DX_FLOAT_to_INT(D3DX_SaturateSigned_FLOAT(unpackedInput.y), 127) & 0x000000ff)<< 8) | 531 | ((D3DX_FLOAT_to_INT(D3DX_SaturateSigned_FLOAT(unpackedInput.z), 127) & 0x000000ff)<<16) | 532 | ((D3DX_FLOAT_to_INT(D3DX_SaturateSigned_FLOAT(unpackedInput.w), 127)) <<24) ); 533 | return packedOutput; 534 | } 535 | 536 | //----------------------------------------------------------------------------- 537 | // R8G8B8A8_SINT <-> INT4 538 | //----------------------------------------------------------------------------- 539 | D3DX11INLINE XMINT4 D3DX_R8G8B8A8_SINT_to_INT4(UINT packedInput) 540 | { 541 | XMINT4 unpackedOutput; 542 | unpackedOutput.x = (INT)(packedInput << 24) >> 24; 543 | unpackedOutput.y = (INT)((packedInput << 16) & 0xff000000) >> 24; 544 | unpackedOutput.z = (INT)((packedInput << 8) & 0xff000000) >> 24; 545 | unpackedOutput.w = (INT)(packedInput & 0xff000000) >> 24; 546 | return unpackedOutput; 547 | } 548 | 549 | D3DX11INLINE UINT D3DX_INT4_to_R8G8B8A8_SINT(XMINT4 unpackedInput) 550 | { 551 | UINT packedOutput; 552 | unpackedInput.x = max(min(unpackedInput.x,127),-128); 553 | unpackedInput.y = max(min(unpackedInput.y,127),-128); 554 | unpackedInput.z = max(min(unpackedInput.z,127),-128); 555 | unpackedInput.w = max(min(unpackedInput.w,127),-128); 556 | packedOutput = ( (unpackedInput.x & 0x000000ff) | 557 | ((unpackedInput.y & 0x000000ff)<< 8) | 558 | ((unpackedInput.z & 0x000000ff)<<16) | 559 | (unpackedInput.w <<24) ); 560 | return packedOutput; 561 | } 562 | 563 | //----------------------------------------------------------------------------- 564 | // B8G8R8A8_UNORM <-> FLOAT4 565 | //----------------------------------------------------------------------------- 566 | D3DX11INLINE XMFLOAT4 D3DX_B8G8R8A8_UNORM_to_FLOAT4(UINT packedInput) 567 | { 568 | hlsl_precise XMFLOAT4 unpackedOutput; 569 | unpackedOutput.z = (FLOAT) (packedInput & 0x000000ff) / 255; 570 | unpackedOutput.y = (FLOAT)(((packedInput>> 8) & 0x000000ff)) / 255; 571 | unpackedOutput.x = (FLOAT)(((packedInput>>16) & 0x000000ff)) / 255; 572 | unpackedOutput.w = (FLOAT) (packedInput>>24) / 255; 573 | return unpackedOutput; 574 | } 575 | 576 | D3DX11INLINE UINT D3DX_FLOAT4_to_B8G8R8A8_UNORM(hlsl_precise XMFLOAT4 unpackedInput) 577 | { 578 | UINT packedOutput; 579 | packedOutput = ( (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.z), 255)) | 580 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.y), 255)<< 8) | 581 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.x), 255)<<16) | 582 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.w), 255)<<24) ); 583 | return packedOutput; 584 | } 585 | 586 | //----------------------------------------------------------------------------- 587 | // B8G8R8A8_UNORM_SRGB <-> FLOAT4 588 | //----------------------------------------------------------------------------- 589 | D3DX11INLINE XMFLOAT4 D3DX_B8G8R8A8_UNORM_SRGB_to_FLOAT4_inexact(UINT packedInput) 590 | { 591 | hlsl_precise XMFLOAT4 unpackedOutput; 592 | unpackedOutput.z = D3DX_SRGB_to_FLOAT_inexact(((FLOAT) (packedInput & 0x000000ff) )/255); 593 | unpackedOutput.y = D3DX_SRGB_to_FLOAT_inexact(((FLOAT)(((packedInput>> 8) & 0x000000ff)))/255); 594 | unpackedOutput.x = D3DX_SRGB_to_FLOAT_inexact(((FLOAT)(((packedInput>>16) & 0x000000ff)))/255); 595 | unpackedOutput.w = (FLOAT)(packedInput>>24) / 255; 596 | return unpackedOutput; 597 | } 598 | 599 | D3DX11INLINE XMFLOAT4 D3DX_B8G8R8A8_UNORM_SRGB_to_FLOAT4(UINT packedInput) 600 | { 601 | hlsl_precise XMFLOAT4 unpackedOutput; 602 | unpackedOutput.z = D3DX_SRGB_to_FLOAT( (packedInput & 0x000000ff) ); 603 | unpackedOutput.y = D3DX_SRGB_to_FLOAT((((packedInput>> 8) & 0x000000ff))); 604 | unpackedOutput.x = D3DX_SRGB_to_FLOAT((((packedInput>>16) & 0x000000ff))); 605 | unpackedOutput.w = (FLOAT)(packedInput>>24) / 255; 606 | return unpackedOutput; 607 | } 608 | 609 | D3DX11INLINE UINT D3DX_FLOAT4_to_B8G8R8A8_UNORM_SRGB(hlsl_precise XMFLOAT4 unpackedInput) 610 | { 611 | UINT packedOutput; 612 | unpackedInput.z = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.z)); 613 | unpackedInput.y = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.y)); 614 | unpackedInput.x = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.x)); 615 | unpackedInput.w = D3DX_Saturate_FLOAT(unpackedInput.w); 616 | packedOutput = ( (D3DX_FLOAT_to_UINT(unpackedInput.z, 255)) | 617 | (D3DX_FLOAT_to_UINT(unpackedInput.y, 255)<< 8) | 618 | (D3DX_FLOAT_to_UINT(unpackedInput.x, 255)<<16) | 619 | (D3DX_FLOAT_to_UINT(unpackedInput.w, 255)<<24) ); 620 | return packedOutput; 621 | } 622 | 623 | //----------------------------------------------------------------------------- 624 | // B8G8R8X8_UNORM <-> FLOAT3 625 | //----------------------------------------------------------------------------- 626 | D3DX11INLINE XMFLOAT3 D3DX_B8G8R8X8_UNORM_to_FLOAT3(UINT packedInput) 627 | { 628 | hlsl_precise XMFLOAT3 unpackedOutput; 629 | unpackedOutput.z = (FLOAT) (packedInput & 0x000000ff) / 255; 630 | unpackedOutput.y = (FLOAT)(((packedInput>> 8) & 0x000000ff)) / 255; 631 | unpackedOutput.x = (FLOAT)(((packedInput>>16) & 0x000000ff)) / 255; 632 | return unpackedOutput; 633 | } 634 | 635 | D3DX11INLINE UINT D3DX_FLOAT3_to_B8G8R8X8_UNORM(hlsl_precise XMFLOAT3 unpackedInput) 636 | { 637 | UINT packedOutput; 638 | packedOutput = ( (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.z), 255)) | 639 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.y), 255)<< 8) | 640 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.x), 255)<<16) ); 641 | return packedOutput; 642 | } 643 | 644 | //----------------------------------------------------------------------------- 645 | // B8G8R8X8_UNORM_SRGB <-> FLOAT3 646 | //----------------------------------------------------------------------------- 647 | D3DX11INLINE XMFLOAT3 D3DX_B8G8R8X8_UNORM_SRGB_to_FLOAT3_inexact(UINT packedInput) 648 | { 649 | hlsl_precise XMFLOAT3 unpackedOutput; 650 | unpackedOutput.z = D3DX_SRGB_to_FLOAT_inexact(((FLOAT) (packedInput & 0x000000ff) )/255); 651 | unpackedOutput.y = D3DX_SRGB_to_FLOAT_inexact(((FLOAT)(((packedInput>> 8) & 0x000000ff)))/255); 652 | unpackedOutput.x = D3DX_SRGB_to_FLOAT_inexact(((FLOAT)(((packedInput>>16) & 0x000000ff)))/255); 653 | return unpackedOutput; 654 | } 655 | 656 | D3DX11INLINE XMFLOAT3 D3DX_B8G8R8X8_UNORM_SRGB_to_FLOAT3(UINT packedInput) 657 | { 658 | hlsl_precise XMFLOAT3 unpackedOutput; 659 | unpackedOutput.z = D3DX_SRGB_to_FLOAT( (packedInput & 0x000000ff) ); 660 | unpackedOutput.y = D3DX_SRGB_to_FLOAT((((packedInput>> 8) & 0x000000ff))); 661 | unpackedOutput.x = D3DX_SRGB_to_FLOAT((((packedInput>>16) & 0x000000ff))); 662 | return unpackedOutput; 663 | } 664 | 665 | D3DX11INLINE UINT D3DX_FLOAT3_to_B8G8R8X8_UNORM_SRGB(hlsl_precise XMFLOAT3 unpackedInput) 666 | { 667 | UINT packedOutput; 668 | unpackedInput.z = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.z)); 669 | unpackedInput.y = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.y)); 670 | unpackedInput.x = D3DX_FLOAT_to_SRGB(D3DX_Saturate_FLOAT(unpackedInput.x)); 671 | packedOutput = ( (D3DX_FLOAT_to_UINT(unpackedInput.z, 255)) | 672 | (D3DX_FLOAT_to_UINT(unpackedInput.y, 255)<< 8) | 673 | (D3DX_FLOAT_to_UINT(unpackedInput.x, 255)<<16) ); 674 | return packedOutput; 675 | } 676 | 677 | //----------------------------------------------------------------------------- 678 | // R16G16_FLOAT <-> FLOAT2 679 | //----------------------------------------------------------------------------- 680 | 681 | #if (HLSL_VERSION > 0) || (__HLSL_VERSION > 0) 682 | 683 | D3DX11INLINE XMFLOAT2 D3DX_R16G16_FLOAT_to_FLOAT2(UINT packedInput) 684 | { 685 | hlsl_precise XMFLOAT2 unpackedOutput; 686 | unpackedOutput.x = f16tof32(packedInput&0x0000ffff); 687 | unpackedOutput.y = f16tof32(packedInput>>16); 688 | return unpackedOutput; 689 | } 690 | 691 | D3DX11INLINE UINT D3DX_FLOAT2_to_R16G16_FLOAT(hlsl_precise XMFLOAT2 unpackedInput) 692 | { 693 | UINT packedOutput; 694 | packedOutput = asuint(f32tof16(unpackedInput.x)) | 695 | (asuint(f32tof16(unpackedInput.y)) << 16); 696 | return packedOutput; 697 | } 698 | 699 | #endif 700 | 701 | //----------------------------------------------------------------------------- 702 | // R16G16_UNORM <-> FLOAT2 703 | //----------------------------------------------------------------------------- 704 | D3DX11INLINE XMFLOAT2 D3DX_R16G16_UNORM_to_FLOAT2(UINT packedInput) 705 | { 706 | hlsl_precise XMFLOAT2 unpackedOutput; 707 | unpackedOutput.x = (FLOAT) (packedInput & 0x0000ffff) / 65535; 708 | unpackedOutput.y = (FLOAT) (packedInput>>16) / 65535; 709 | return unpackedOutput; 710 | } 711 | 712 | D3DX11INLINE UINT D3DX_FLOAT2_to_R16G16_UNORM(hlsl_precise XMFLOAT2 unpackedInput) 713 | { 714 | UINT packedOutput; 715 | packedOutput = ( (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.x), 65535)) | 716 | (D3DX_FLOAT_to_UINT(D3DX_Saturate_FLOAT(unpackedInput.y), 65535)<< 16) ); 717 | return packedOutput; 718 | } 719 | 720 | //----------------------------------------------------------------------------- 721 | // R16G16_UINT <-> UINT2 722 | //----------------------------------------------------------------------------- 723 | D3DX11INLINE XMUINT2 D3DX_R16G16_UINT_to_UINT2(UINT packedInput) 724 | { 725 | XMUINT2 unpackedOutput; 726 | unpackedOutput.x = packedInput & 0x0000ffff; 727 | unpackedOutput.y = packedInput>>16; 728 | return unpackedOutput; 729 | } 730 | 731 | D3DX11INLINE UINT D3DX_UINT2_to_R16G16_UINT(XMUINT2 unpackedInput) 732 | { 733 | UINT packedOutput; 734 | unpackedInput.x = min(unpackedInput.x,0x0000ffff); 735 | unpackedInput.y = min(unpackedInput.y,0x0000ffff); 736 | packedOutput = ( unpackedInput.x | 737 | (unpackedInput.y<<16) ); 738 | return packedOutput; 739 | } 740 | 741 | //----------------------------------------------------------------------------- 742 | // R16G16_SNORM <-> FLOAT2 743 | //----------------------------------------------------------------------------- 744 | D3DX11INLINE XMFLOAT2 D3DX_R16G16_SNORM_to_FLOAT2(UINT packedInput) 745 | { 746 | hlsl_precise XMFLOAT2 unpackedOutput; 747 | XMINT2 signExtendedBits; 748 | signExtendedBits.x = (INT)(packedInput << 16) >> 16; 749 | signExtendedBits.y = (INT)(packedInput & 0xffff0000) >> 16; 750 | unpackedOutput.x = D3DX_INT_to_FLOAT(signExtendedBits.x, 32767); 751 | unpackedOutput.y = D3DX_INT_to_FLOAT(signExtendedBits.y, 32767); 752 | return unpackedOutput; 753 | } 754 | 755 | D3DX11INLINE UINT D3DX_FLOAT2_to_R16G16_SNORM(hlsl_precise XMFLOAT2 unpackedInput) 756 | { 757 | UINT packedOutput; 758 | packedOutput = ( (D3DX_FLOAT_to_INT(D3DX_SaturateSigned_FLOAT(unpackedInput.x), 32767) & 0x0000ffff) | 759 | (D3DX_FLOAT_to_INT(D3DX_SaturateSigned_FLOAT(unpackedInput.y), 32767) <<16) ); 760 | return packedOutput; 761 | } 762 | 763 | //----------------------------------------------------------------------------- 764 | // R16G16_SINT <-> INT2 765 | //----------------------------------------------------------------------------- 766 | D3DX11INLINE XMINT2 D3DX_R16G16_SINT_to_INT2(UINT packedInput) 767 | { 768 | XMINT2 unpackedOutput; 769 | unpackedOutput.x = (INT)(packedInput << 16) >> 16; 770 | unpackedOutput.y = (INT)(packedInput & 0xffff0000) >> 16; 771 | return unpackedOutput; 772 | } 773 | 774 | D3DX11INLINE UINT D3DX_INT2_to_R16G16_SINT(XMINT2 unpackedInput) 775 | { 776 | UINT packedOutput; 777 | unpackedInput.x = max(min(unpackedInput.x,32767),-32768); 778 | unpackedInput.y = max(min(unpackedInput.y,32767),-32768); 779 | packedOutput = ( (unpackedInput.x & 0x0000ffff) | 780 | (unpackedInput.y <<16) ); 781 | return packedOutput; 782 | } 783 | 784 | #if (HLSL_VERSION > 0) || (__HLSL_VERSION > 0) 785 | #else 786 | } // namespace DirectX; 787 | #endif 788 | 789 | #endif // __D3DX_DXGI_FORMAT_CONVERT_INL___ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2010-2021 Microsoft Corp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # D3DX_DXGIFormatConvert.inl 2 | 3 | This utility header was introduced in the legacy DirectX SDK in June 2010. 4 | 5 | > The new D3DX_DXGIFormatConvert.inl inline header includes light-weight conversion functions for use in Compute Shaders or Pixel Shaders on D3D11 Hardware that can be useful when applications need to simultaneously read and write to textures, such as in-place editing scenarios. 6 | 7 | This repro contains the latest updates to this header, which is included in the [Microsoft.DXSDK.D3DX](https://www.nuget.org/packages/Microsoft.DXSDK.D3DX) NuGet package. 8 | 9 | Documentation can be found on Microsoft Docs: [Programming Guide](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-unpacking-packing-dxgi-format), [Reference Guide](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/inline-format-conversion-reference). 10 | 11 | ## Notices 12 | 13 | This header is made available subject to the terms of the [MIT License](http://opensource.org/licenses/MIT). 14 | 15 | ## Contributing 16 | 17 | This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 18 | 19 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. 20 | 21 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 22 | 23 | ## Trademarks 24 | 25 | This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies. 26 | 27 | # Version History 28 | 29 | |Date|Notes| 30 | |---|---| 31 | |June 2010|Release in legacy DirectX SDK| 32 | |April 2021|Updated to use DirectXMath in the Windows SDK instead of legacy XNAMath from the DirectX SDK for C++ support| 33 | |September 2024|Updated to build with DXC Shader Model 6 compiler| 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Tests/.gitignore: -------------------------------------------------------------------------------- 1 | *.psess 2 | *.vsp 3 | *.log 4 | *.err 5 | *.wrn 6 | *.suo 7 | *.sdf 8 | *.user 9 | *.i 10 | *.vspscc 11 | *.opensdf 12 | *.opendb 13 | *.ipch 14 | *.cache 15 | *.tlog 16 | *.lastbuildstate 17 | *.ilk 18 | *.VC.db 19 | *.nupkg 20 | .vs 21 | Bin 22 | packages 23 | /ipch 24 | /out 25 | -------------------------------------------------------------------------------- /Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | cmake_minimum_required (VERSION 3.20) 5 | 6 | project (fmtconvert 7 | DESCRIPTION "D3DX_DXGIFormatConvert.inl Tester" 8 | HOMEPAGE_URL "https://github.com/walbourn/dxgiformatconvert" 9 | LANGUAGES CXX) 10 | 11 | 12 | option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF) 13 | 14 | option(BUILD_DXIL_SHADERS "Use DXC Shader Model 6 for shaders" OFF) 15 | 16 | set(CMAKE_CXX_STANDARD 17) 17 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 18 | set(CMAKE_CXX_EXTENSIONS OFF) 19 | 20 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 22 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 23 | 24 | if(DEFINED VCPKG_TARGET_ARCHITECTURE) 25 | set(DIRECTX_ARCH ${VCPKG_TARGET_ARCHITECTURE}) 26 | elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$") 27 | set(DIRECTX_ARCH x86) 28 | elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Xx]64$") 29 | set(DIRECTX_ARCH x64) 30 | elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]$") 31 | set(DIRECTX_ARCH arm) 32 | elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]64$") 33 | set(DIRECTX_ARCH arm64) 34 | elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]64EC$") 35 | set(DIRECTX_ARCH arm64ec) 36 | elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Ww][Ii][Nn]32$") 37 | set(DIRECTX_ARCH x86) 38 | elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Xx]64$") 39 | set(DIRECTX_ARCH x64) 40 | elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]$") 41 | set(DIRECTX_ARCH arm) 42 | elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]64$") 43 | set(DIRECTX_ARCH arm64) 44 | elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]64EC$") 45 | set(DIRECTX_ARCH arm64ec) 46 | endif() 47 | 48 | add_executable(${PROJECT_NAME} 49 | fmtconvert.cpp) 50 | 51 | target_include_directories(${PROJECT_NAME} PRIVATE ../) 52 | 53 | # Build HLSL shaders 54 | if(BUILD_DXIL_SHADERS AND VCPKG_TOOLCHAIN) 55 | set(ShaderProfile "cs_6_0") 56 | get_filename_component(_vcpkg_root "${CMAKE_CURRENT_LIST_DIR}" PATH) 57 | find_program(DIRECTX_DXC_TOOL DXC.EXE 58 | REQUIRED NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH 59 | HINTS "${_vcpkg_root}/build/vcpkg_installed/${VCPKG_HOST_TRIPLET}/tools/directx-dxc") 60 | set(ShaderOpts "-HV 2021") 61 | message(STATUS "Using VCPKG for DirectXShaderCompiler (${VCPKG_HOST_TRIPLET}).") 62 | elseif(BUILD_DXIL_SHADERS) 63 | set(ShaderProfile "cs_6_0") 64 | find_program(DIRECTX_DXC_TOOL DXC.EXE 65 | HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}" 66 | "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}") 67 | 68 | if(NOT (DIRECTX_DXC_TOOL MATCHES "10\.0\.19041\.0|10\.0\.20348\.0|10\.0\.22000.0")) 69 | set(ShaderOpts "-HV 2021") 70 | endif() 71 | 72 | message(STATUS "Using DirectXShaderCompiler found in ${DIRECTX_DXC_TOOL}") 73 | else() 74 | set(ShaderProfile "cs_5_0") 75 | find_program(DIRECTX_DXC_TOOL FXC.EXE 76 | HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}" 77 | "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}") 78 | set(ShaderOpts "") 79 | 80 | message(STATUS "Using LegacyShaderCompiler found in ${DIRECTX_FXC_TOOL}") 81 | endif() 82 | 83 | add_custom_target(shaders) 84 | 85 | foreach(FILE F10UN.hlsl F10UI.hlsl 86 | F8U.hlsl F8US.hlsl F8UI.hlsl F8S.hlsl F8SI.hlsl FB8U.hlsl FB8US.hlsl FBX8U.hlsl FBX8US.hlsl 87 | F16F.hlsl F16U.hlsl F16UI.hlsl F16S.hlsl F16SI.hlsl) 88 | set_source_files_properties(${FILE} PROPERTIES ShaderType "cs") 89 | get_filename_component(FILE_WE ${FILE} NAME_WE) 90 | add_custom_command(TARGET shaders 91 | COMMAND ${DIRECTX_DXC_TOOL} /nologo /Ges /Gis /Emain /T${ShaderProfile} ${ShaderOpts} $<$:/Od> /Zi /Fo ${CMAKE_BINARY_DIR}/${FILE_WE}.cso /Fd ${CMAKE_BINARY_DIR}/${FILE_WE}.pdb ${FILE} 92 | MAIN_DEPENDENCY ${FILE} 93 | COMMENT "HLSL ${FILE}" 94 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 95 | VERBATIM) 96 | endforeach(FILE) 97 | 98 | add_dependencies(${PROJECT_NAME} shaders) 99 | 100 | if(MSVC) 101 | target_compile_options(${PROJECT_NAME} PRIVATE /Wall /EHsc /GR "$<$>:/guard:cf>") 102 | target_link_options(${PROJECT_NAME} PRIVATE "$<$>:/guard:cf>" /DYNAMICBASE /NXCOMPAT) 103 | 104 | if((CMAKE_SIZEOF_VOID_P EQUAL 4) AND (NOT ${DIRECTX_ARCH} MATCHES "^arm")) 105 | target_link_options(${PROJECT_NAME} PRIVATE /SAFESEH) 106 | endif() 107 | 108 | if((MSVC_VERSION GREATER_EQUAL 1928) 109 | AND (CMAKE_SIZEOF_VOID_P EQUAL 8) 110 | AND ((NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")) OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0))) 111 | target_compile_options(${PROJECT_NAME} PRIVATE "$<$>:/guard:ehcont>") 112 | target_link_options(${PROJECT_NAME} PRIVATE "$<$>:/guard:ehcont>") 113 | endif() 114 | else() 115 | list(APPEND COMPILER_DEFINES $,_DEBUG,NDEBUG>) 116 | endif() 117 | 118 | if(NOT ${DIRECTX_ARCH} MATCHES "^arm") 119 | if(CMAKE_SIZEOF_VOID_P EQUAL 4) 120 | set(ARCH_SSE2 $<$:/arch:SSE2> $<$>:-msse2>) 121 | else() 122 | set(ARCH_SSE2 $<$>:-msse2>) 123 | endif() 124 | 125 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") 126 | list(APPEND ARCH_SSE2 -mfpmath=sse) 127 | endif() 128 | 129 | target_compile_options(${PROJECT_NAME} PRIVATE ${ARCH_SSE2}) 130 | endif() 131 | 132 | if(MINGW) 133 | find_package(directxmath CONFIG REQUIRED) 134 | else() 135 | find_package(directxmath CONFIG QUIET) 136 | endif() 137 | 138 | if(directxmath_FOUND) 139 | message(STATUS "Using DirectXMath package") 140 | target_link_libraries(${PROJECT_NAME} PUBLIC Microsoft::DirectXMath) 141 | endif() 142 | 143 | 144 | if(BUILD_DXIL_SHADERS AND VCPKG_TOOLCHAIN) 145 | message(STATUS "Using VCPKG for DirectXShaderCompiler (${VCPKG_HOST_TRIPLET}).") 146 | find_program(DIRECTX_DXC_TOOL DXC.EXE 147 | REQUIRED NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH 148 | HINTS ${DIRECTX_DXC_PATH} 149 | "${CMAKE_CURRENT_LIST_DIR}/build/vcpkg_installed/${VCPKG_HOST_TRIPLET}/tools/directx-dxc") 150 | elseif(BUILD_DXIL_SHADERS) 151 | find_program(DIRECTX_DXC_TOOL DXC.EXE 152 | HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}" 153 | "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}") 154 | message(STATUS "Using DirectXShaderCompiler found in ${DIRECTX_DXC_TOOL}") 155 | else() 156 | find_program(DIRECTX_FXC_TOOL FXC.EXE 157 | HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}" 158 | "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}") 159 | message(STATUS "Using LegacyShaderCompiler found in ${DIRECTX_FXC_TOOL}") 160 | endif() 161 | 162 | if(MINGW) 163 | target_link_options(${PROJECT_NAME} PRIVATE -municode) 164 | endif() 165 | 166 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM") 167 | target_compile_options(${PROJECT_NAME} PRIVATE 168 | "-Wpedantic" "-Wextra" "-Wno-c++98-compat" 169 | "-Wno-c++98-compat-pedantic" "-Wno-gnu-anonymous-struct" 170 | "-Wno-language-extension-token" "-Wno-missing-prototypes" "-Wno-missing-variable-declarations" "-Wno-nested-anon-types") 171 | 172 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) 173 | target_compile_options(${PROJECT_NAME} PRIVATE /ZH:SHA_256 "-Wno-unsafe-buffer-usage") 174 | endif() 175 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") 176 | target_compile_options(${PROJECT_NAME} PRIVATE -Wno-ignored-attributes) 177 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel") 178 | target_compile_options(${PROJECT_NAME} PRIVATE /Zc:__cplusplus /Zc:inline /fp:fast /Qdiag-disable:161) 179 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") 180 | target_compile_options(${PROJECT_NAME} PRIVATE 181 | /sdl /Zc:inline /fp:fast 182 | "/wd4061" "/wd4365" "/wd4514" "/wd4571" "/wd4668" "/wd4710" "/wd4820" "/wd5031" "/wd5032" "/wd5039" "/wd5045") 183 | 184 | if(ENABLE_CODE_ANALYSIS) 185 | target_compile_options(${PROJECT_NAME} PRIVATE /analyze) 186 | endif() 187 | 188 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10) 189 | target_compile_options(${PROJECT_NAME} PRIVATE /permissive-) 190 | endif() 191 | 192 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.14) 193 | target_compile_options(${PROJECT_NAME} PRIVATE /Zc:__cplusplus) 194 | endif() 195 | 196 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.24) 197 | target_compile_options(${PROJECT_NAME} PRIVATE /ZH:SHA_256) 198 | endif() 199 | 200 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.26) 201 | target_compile_options(${PROJECT_NAME} PRIVATE /Zc:preprocessor /wd5105) 202 | endif() 203 | 204 | if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.27) AND (NOT (${DIRECTX_ARCH} MATCHES "^arm"))) 205 | target_link_options(${PROJECT_NAME} PRIVATE /CETCOMPAT) 206 | endif() 207 | 208 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.28) 209 | target_compile_options(${PROJECT_NAME} PRIVATE /Zc:lambda) 210 | endif() 211 | 212 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29) 213 | target_compile_options(${PROJECT_NAME} PRIVATE /external:W4) 214 | endif() 215 | 216 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.34) 217 | target_compile_options(${PROJECT_NAME} PRIVATE /wd5262 /wd5264) 218 | endif() 219 | 220 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.35) 221 | target_compile_options(${PROJECT_NAME} PRIVATE $<$:/Zc:templateScope>) 222 | endif() 223 | endif() 224 | 225 | if(WIN32) 226 | target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0602) 227 | endif() 228 | -------------------------------------------------------------------------------- /Tests/CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "configurePresets": [ 4 | { 5 | "name": "base", 6 | "displayName": "Basic Config", 7 | "description": "Basic build using Ninja generator", 8 | "generator": "Ninja", 9 | "hidden": true, 10 | "binaryDir": "${sourceDir}/out/build/${presetName}", 11 | "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}" } 12 | }, 13 | 14 | { 15 | "name": "x64", 16 | "architecture": { 17 | "value": "x64", 18 | "strategy": "external" 19 | }, 20 | "cacheVariables": { "DIRECTX_ARCH": "x64" }, 21 | "hidden": true 22 | }, 23 | { 24 | "name": "x86", 25 | "architecture": { 26 | "value": "x86", 27 | "strategy": "external" 28 | }, 29 | "cacheVariables": { "DIRECTX_ARCH": "x86" }, 30 | "hidden": true 31 | }, 32 | { 33 | "name": "ARM64", 34 | "architecture": { 35 | "value": "arm64", 36 | "strategy": "external" 37 | }, 38 | "cacheVariables": { "DIRECTX_ARCH": "arm64" }, 39 | "hidden": true 40 | }, 41 | { 42 | "name": "ARM64EC", 43 | "architecture": { 44 | "value": "arm64ec", 45 | "strategy": "external" 46 | }, 47 | "cacheVariables": { "DIRECTX_ARCH": "arm64ec" }, 48 | "hidden": true 49 | }, 50 | 51 | { 52 | "name": "Debug", 53 | "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }, 54 | "hidden": true 55 | }, 56 | { 57 | "name": "Release", 58 | "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" }, 59 | "hidden": true 60 | }, 61 | 62 | { 63 | "name": "MSVC", 64 | "hidden": true, 65 | "cacheVariables": { 66 | "CMAKE_CXX_COMPILER": "cl.exe" 67 | }, 68 | "toolset": { 69 | "value": "host=x64", 70 | "strategy": "external" 71 | } 72 | }, 73 | { 74 | "name": "Clang", 75 | "hidden": true, 76 | "cacheVariables": { 77 | "CMAKE_CXX_COMPILER": "clang-cl.exe" 78 | }, 79 | "toolset": { 80 | "value": "host=x64", 81 | "strategy": "external" 82 | } 83 | }, 84 | { 85 | "name": "GNUC", 86 | "hidden": true, 87 | "cacheVariables": { 88 | "CMAKE_CXX_COMPILER": "g++.exe" 89 | }, 90 | "toolset": { 91 | "value": "host=x64", 92 | "strategy": "external" 93 | } 94 | }, 95 | 96 | { 97 | "name": "VCPKG", 98 | "cacheVariables": { 99 | "CMAKE_TOOLCHAIN_FILE": { 100 | "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", 101 | "type": "FILEPATH" 102 | } 103 | }, 104 | "hidden": true 105 | }, 106 | { 107 | "name": "MinGW32", 108 | "hidden": true, 109 | "environment": { 110 | "PATH": "$penv{PATH};c:/mingw32/bin;c:/mingw32/libexec/gcc/i686-w64-mingw32/12.2.0" 111 | }, 112 | "cacheVariables": { 113 | "VCPKG_TARGET_TRIPLET": "x86-mingw-static", 114 | "VCPKG_HOST_TRIPLET": "x86-mingw-static" 115 | } 116 | }, 117 | { 118 | "name": "MinGW64", 119 | "hidden": true, 120 | "environment": { 121 | "PATH": "$penv{PATH};c:/mingw64/bin;c:/mingw64/libexec/gcc/x86_64-w64-mingw32/12.2.0" 122 | }, 123 | "cacheVariables": { 124 | "VCPKG_TARGET_TRIPLET": "x64-mingw-static", 125 | "VCPKG_HOST_TRIPLET": "x64-mingw-static" 126 | } 127 | }, 128 | { 129 | "name": "Intel", 130 | "hidden": true, 131 | "cacheVariables": { 132 | "CMAKE_CXX_COMPILER": "icl.exe", 133 | "BUILD_TOOLS": false 134 | }, 135 | "toolset": { 136 | "value": "host=x64", 137 | "strategy": "external" 138 | } 139 | }, 140 | { 141 | "name": "IntelLLVM", 142 | "hidden": true, 143 | "cacheVariables": { 144 | "CMAKE_CXX_COMPILER": "icx.exe" 145 | }, 146 | "toolset": { 147 | "value": "host=x64", 148 | "strategy": "external" 149 | } 150 | }, 151 | 152 | { "name": "x64-Debug" , "description": "MSVC for x64 (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "MSVC" ] }, 153 | { "name": "x64-Release" , "description": "MSVC for x64 (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "MSVC" ] }, 154 | { "name": "x86-Debug" , "description": "MSVC for x86 (Debug) for Windows 8", "inherits": [ "base", "x86", "Debug", "MSVC" ] }, 155 | { "name": "x86-Release" , "description": "MSVC for x86 (Release) for Windows 8", "inherits": [ "base", "x86", "Release", "MSVC" ] }, 156 | 157 | { "name": "arm64-Debug" , "description": "MSVC for ARM64 (Debug) for Windows 10", "inherits": [ "base", "ARM64", "Debug", "MSVC" ] }, 158 | { "name": "arm64-Release" , "description": "MSVC for ARM64 (Release) for Windows 10", "inherits": [ "base", "ARM64", "Release", "MSVC" ] }, 159 | { "name": "arm64ec-Debug" , "description": "MSVC for ARM64EC (Debug) for Windows 10", "inherits": [ "base", "ARM64EC", "Debug", "MSVC" ], "environment": { "CXXFLAGS": "/arm64EC" } }, 160 | { "name": "arm64ec-Release" , "description": "MSVC for ARM64EC (Release) for Windows 10", "inherits": [ "base", "ARM64EC", "Release", "MSVC" ], "environment": { "CXXFLAGS": "/arm64EC" } }, 161 | 162 | { "name": "x64-Debug-VCPKG" , "description": "MSVC for x64 (Debug) using VCPKG", "inherits": [ "base", "x64", "Debug", "MSVC", "VCPKG" ] }, 163 | { "name": "x64-Release-VCPKG" , "description": "MSVC for x64 (Release) using VCPKG", "inherits": [ "base", "x64", "Release", "MSVC", "VCPKG" ] }, 164 | { "name": "x86-Debug-VCPKG" , "description": "MSVC for x86 (Debug) using VCPKG", "inherits": [ "base", "x86", "Debug", "MSVC", "VCPKG" ] }, 165 | { "name": "x86-Release-VCPKG" , "description": "MSVC for x86 (Release) using VCPKG", "inherits": [ "base", "x86", "Release", "MSVC", "VCPKG" ] }, 166 | 167 | { "name": "arm64-Debug-VCPKG" , "description": "MSVC for ARM64 (Debug) using VCPKG", "inherits": [ "base", "ARM64", "Debug", "MSVC", "VCPKG" ] }, 168 | { "name": "arm64-Release-VCPKG" , "description": "MSVC for ARM64 (Release) using VCPKG", "inherits": [ "base", "ARM64", "Release", "MSVC", "VCPKG" ] }, 169 | { "name": "arm64ec-Debug-VCPKG" , "description": "MSVC for ARM64EC (Debug) using VCPKG", "inherits": [ "base", "ARM64EC", "Debug", "MSVC", "VCPKG" ], "environment": { "CXXFLAGS": "/arm64EC" }, "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64ec-windows" } }, 170 | { "name": "arm64ec-Release-VCPKG", "description": "MSVC for ARM64EC (Release) using VCPKG", "inherits": [ "base", "ARM64EC", "Release", "MSVC", "VCPKG" ], "environment": { "CXXFLAGS": "/arm64EC" }, "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64ec-windows" } }, 171 | 172 | { "name": "x64-Debug-Clang" , "description": "Clang/LLVM for x64 (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "Clang" ] }, 173 | { "name": "x64-Release-Clang" , "description": "Clang/LLVM for x64 (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "Clang" ] }, 174 | { "name": "x86-Debug-Clang" , "description": "Clang/LLVM for x86 (Debug) for Windows 8", "inherits": [ "base", "x86", "Debug", "Clang" ], "environment": { "CXXFLAGS": "-m32" } }, 175 | { "name": "x86-Release-Clang" , "description": "Clang/LLVM for x86 (Release) for Windows 8", "inherits": [ "base", "x86", "Release", "Clang" ], "environment": { "CXXFLAGS": "-m32" } }, 176 | { "name": "arm64-Debug-Clang" , "description": "Clang/LLVM for AArch64 (Debug) for Windows 10", "inherits": [ "base", "ARM64", "Debug", "Clang" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } }, 177 | { "name": "arm64-Release-Clang" , "description": "Clang/LLVM for AArch64 (Release) for Windows 10", "inherits": [ "base", "ARM64", "Release", "Clang" ], "environment": { "CXXFLAGS": "--target=arm64-pc-windows-msvc" } }, 178 | 179 | { "name": "x64-Debug-Clang-VCPKG" , "description": "Clang/LLVM for x64 (Debug) using VCPKG", "inherits": [ "base", "x64", "Debug", "Clang", "VCPKG" ] }, 180 | { "name": "x64-Release-Clang-VCPKG" , "description": "Clang/LLVM for x64 (Release) using VCPKG", "inherits": [ "base", "x64", "Release", "Clang", "VCPKG" ] }, 181 | { "name": "x86-Debug-Clang-VCPKG" , "description": "Clang/LLVM for x86 (Debug) using VCPKG", "inherits": [ "base", "x86", "Debug", "Clang", "VCPKG" ], "environment": { "CXXFLAGS": "-m32" } }, 182 | { "name": "x86-Release-Clang-VCPKG" , "description": "Clang/LLVM for x86 (Release) using VCPKG", "inherits": [ "base", "x86", "Release", "Clang", "VCPKG" ], "environment": { "CXXFLAGS": "-m32" } }, 183 | 184 | { "name": "x64-Debug-MinGW" , "description": "MinG-W64 (Debug)", "inherits": [ "base", "x64", "Debug", "GNUC", "VCPKG", "MinGW64" ] }, 185 | { "name": "x64-Release-MinGW", "description": "MinG-W64 (Release)", "inherits": [ "base", "x64", "Release", "GNUC", "VCPKG", "MinGW64" ] }, 186 | { "name": "x86-Debug-MinGW" , "description": "MinG-W32 (Debug)", "inherits": [ "base", "x86", "Debug", "GNUC", "VCPKG", "MinGW32" ] }, 187 | { "name": "x86-Release-MinGW", "description": "MinG-W32 (Release)", "inherits": [ "base", "x86", "Release", "GNUC", "VCPKG", "MinGW32" ] }, 188 | 189 | { "name": "x64-Debug-ICC" , "description": "Intel Classic Compiler (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "Intel" ] }, 190 | { "name": "x64-Release-ICC" , "description": "Intel Classic Compiler (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "Intel" ] }, 191 | 192 | { "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] }, 193 | { "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] }, 194 | 195 | { "name": "x64-Analyze" , "description": "MSVC for x64 (Debug) for Windows 8 using /analyze", "inherits": [ "base", "x64", "Debug", "MSVC" ], "cacheVariables": { "ENABLE_CODE_ANALYSIS": true } } 196 | ] 197 | } 198 | -------------------------------------------------------------------------------- /Tests/F10UI.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R10G10B10A2_UINT Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = tuiRefConversion.Load(uint3(x,y,0)); 22 | values.HLSLResult = D3DX_R10G10B10A2_UINT_to_UINT4(values.testVal); 23 | values.outVal = D3DX_UINT4_to_R10G10B10A2_UINT(values.RefResult); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,0x00000400,0,0x00000004); 34 | values.HLSLResult = uint4(0x000003ff,0x000003ff,0x00000000,0x00000003); 35 | values.testVal = D3DX_UINT4_to_R10G10B10A2_UINT(values.RefResult); 36 | values.outVal = D3DX_UINT4_to_R10G10B10A2_UINT(values.HLSLResult); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/F10UN.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R10G10B10A2_UNORM Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = asuint(tfRefConversion.Load(uint3(x,y,0))); 22 | values.HLSLResult = asuint(D3DX_R10G10B10A2_UNORM_to_FLOAT4(values.testVal)); 23 | values.outVal = D3DX_FLOAT4_to_R10G10B10A2_UNORM(asfloat(values.RefResult)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = asuint(float4(asfloat(0xffffffff),1.1f,-0.2f,asfloat(0x7f800000))); 34 | values.HLSLResult = asuint(float4(0,1,0,1)); 35 | values.testVal = D3DX_FLOAT4_to_R10G10B10A2_UNORM(asfloat(values.RefResult)); 36 | values.outVal = D3DX_FLOAT4_to_R10G10B10A2_UNORM(asfloat(values.HLSLResult)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/F16F.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R16G16_FLOAT Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = uint4(asuint(tfRefConversion.Load(uint3(x,y,0)).xy),0,0); 22 | values.HLSLResult = uint4(asuint(D3DX_R16G16_FLOAT_to_FLOAT2(values.testVal)),0,0); 23 | values.outVal = D3DX_FLOAT2_to_R16G16_FLOAT(asfloat(values.RefResult.xy)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = asuint(float4(65537,-65537,65537,-65537)); 34 | values.HLSLResult = asuint(float4(65536,-65536,65536,-65536)); 35 | values.testVal = D3DX_FLOAT2_to_R16G16_FLOAT(asfloat(values.RefResult.xy)); 36 | values.outVal = D3DX_FLOAT2_to_R16G16_FLOAT(asfloat(values.HLSLResult.xy)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/F16S.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R16G16_SNORM Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = uint4(asuint(tfRefConversion.Load(uint3(x,y,0)).xy),0,0); 22 | values.HLSLResult = uint4(asuint(D3DX_R16G16_SNORM_to_FLOAT2(values.testVal)),0,0); 23 | values.outVal = D3DX_FLOAT2_to_R16G16_SNORM(asfloat(values.RefResult.xy)); 24 | uint cmpval = values.testVal; 25 | if( (cmpval.r & 0xffff0000) == 0x80000000 ) 26 | { 27 | cmpval |= 0x00010000; 28 | } 29 | if( (cmpval.r & 0x0000ffff) == 0x00008000 ) 30 | { 31 | cmpval |= 0x00000001; 32 | } 33 | if( any(values.RefResult != values.HLSLResult) || (cmpval != values.outVal) ) 34 | { 35 | uErrors.Append(values); 36 | } 37 | } 38 | } 39 | if( uUINT[uint2(0,0)] == 0 ) 40 | { 41 | VALUES values; 42 | values.RefResult = uint4(0xffffffff,asuint(1.1f),0xffffffff,asuint(1.1f)); 43 | values.HLSLResult = uint4(0,asuint(1.0f),0,asuint(1.0f)); 44 | values.testVal = D3DX_FLOAT2_to_R16G16_SNORM(asfloat(values.RefResult.xy)); 45 | values.outVal = D3DX_FLOAT2_to_R16G16_SNORM(asfloat(values.HLSLResult.xy)); 46 | if( values.testVal != values.outVal ) 47 | { 48 | uErrors.Append(values); 49 | } 50 | values.RefResult = uint4(asuint(-1.1f),0x7f800000,asuint(-1.1f),0x7f800000); 51 | values.HLSLResult = uint4(asuint(-1.0f),asuint(1.0f),asuint(-1.0f),asuint(1.0f)); 52 | values.testVal = D3DX_FLOAT2_to_R16G16_SNORM(asfloat(values.RefResult.xy)); 53 | values.outVal = D3DX_FLOAT2_to_R16G16_SNORM(asfloat(values.HLSLResult.xy)); 54 | if( values.testVal != values.outVal ) 55 | { 56 | uErrors.Append(values); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Tests/F16SI.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R16G16_SINT Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = asuint(int4(tsiRefConversion.Load(uint3(x,y,0)).xy,0,0)); 22 | values.HLSLResult = asuint(int4(D3DX_R16G16_SINT_to_INT2(values.testVal),0,0)); 23 | values.outVal = D3DX_INT2_to_R16G16_SINT(asint(values.RefResult.xy)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0x80000000,0xffff7fff,0x80000000,0xffff7fff); 34 | values.HLSLResult = uint4(0xFFFF8000,0xFFFF8000,0xFFFF8000,0xFFFF8000); 35 | values.testVal = asuint(D3DX_INT2_to_R16G16_SINT(asint(values.RefResult.xy))); 36 | values.outVal = asuint(D3DX_INT2_to_R16G16_SINT(asint(values.HLSLResult.xy))); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | values.RefResult = uint4(0x80000000,0xffff7fff,0x80000000,0xffff7fff); 42 | values.HLSLResult = uint4(0xFFFF8000,0xFFFF8000,0xFFFF8000,0xFFFF8000); 43 | values.testVal = asuint(D3DX_INT2_to_R16G16_SINT(asint(values.RefResult.xy))); 44 | values.outVal = asuint(D3DX_INT2_to_R16G16_SINT(asint(values.HLSLResult.xy))); 45 | if( values.testVal != values.outVal ) 46 | { 47 | uErrors.Append(values); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Tests/F16U.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R16G16_UNORM Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = uint4(asuint(tfRefConversion.Load(uint3(x,y,0)).xy),0,0); 22 | values.HLSLResult = uint4(asuint(D3DX_R16G16_UNORM_to_FLOAT2(values.testVal)),0,0); 23 | values.outVal = D3DX_FLOAT2_to_R16G16_UNORM(asfloat(values.RefResult.xy)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,asuint(1.1f),0xffffffff,asuint(1.1f)); 34 | values.HLSLResult = uint4(0,asuint(1.0f),0,asuint(1.0f)); 35 | values.testVal = D3DX_FLOAT2_to_R16G16_UNORM(asfloat(values.RefResult.xy)); 36 | values.outVal = D3DX_FLOAT2_to_R16G16_UNORM(asfloat(values.HLSLResult.xy)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | values.RefResult = uint4(asuint(-0.2f),0x7f800000,asuint(-0.2f),0x7f800000); 42 | values.HLSLResult = uint4(0,asuint(1.0f),0,asuint(1.0f)); 43 | values.testVal = D3DX_FLOAT2_to_R16G16_UNORM(asfloat(values.RefResult.xy)); 44 | values.outVal = D3DX_FLOAT2_to_R16G16_UNORM(asfloat(values.HLSLResult.xy)); 45 | if( values.testVal != values.outVal ) 46 | { 47 | uErrors.Append(values); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Tests/F16UI.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R16G16_UINT Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = uint4(tuiRefConversion.Load(uint3(x,y,0)).xy,0,0); 22 | values.HLSLResult = uint4(D3DX_R16G16_UINT_to_UINT2(values.testVal),0,0); 23 | values.outVal = D3DX_UINT2_to_R16G16_UINT(values.RefResult.xy); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,0x00010000,0xffffffff,0x00010000); 34 | values.HLSLResult = uint4(0x0000ffff,0x0000ffff,0x0000ffff,0x0000ffff); 35 | values.testVal = D3DX_UINT2_to_R16G16_UINT(values.RefResult.xy); 36 | values.outVal = D3DX_UINT2_to_R16G16_UINT(values.HLSLResult.xy); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/F8S.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R8G8B8A8_SNORM Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = asuint(tfRefConversion.Load(uint3(x,y,0))); 22 | values.HLSLResult = asuint(D3DX_R8G8B8A8_SNORM_to_FLOAT4(values.testVal)); 23 | values.outVal = D3DX_FLOAT4_to_R8G8B8A8_SNORM(asfloat(values.RefResult)); 24 | uint cmpval = values.testVal; 25 | if( (cmpval & 0xff000000) == 0x80000000 ) 26 | { 27 | cmpval |= 0x01000000; 28 | } 29 | if( (cmpval & 0x00ff0000) == 0x00800000 ) 30 | { 31 | cmpval |= 0x00010000; 32 | } 33 | if( (cmpval & 0x0000ff00) == 0x00008000 ) 34 | { 35 | cmpval |= 0x00000100; 36 | } 37 | if( (cmpval & 0x000000ff) == 0x00000080 ) 38 | { 39 | cmpval |= 0x00000001; 40 | } 41 | if( any(values.RefResult != values.HLSLResult) || (cmpval != values.outVal) ) 42 | { 43 | uErrors.Append(values); 44 | } 45 | } 46 | } 47 | if( uUINT[uint2(0,0)] == 0 ) 48 | { 49 | VALUES values; 50 | values.RefResult = uint4(0xffffffff,asuint(1.1f),asuint(-1.1f),0x7f800000); 51 | values.HLSLResult = asuint(float4(0,1,-1,1)); 52 | values.testVal = D3DX_FLOAT4_to_R8G8B8A8_SNORM(asfloat(values.RefResult)); 53 | values.outVal = D3DX_FLOAT4_to_R8G8B8A8_SNORM(asfloat(values.HLSLResult)); 54 | if( values.testVal != values.outVal ) 55 | { 56 | uErrors.Append(values); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Tests/F8SI.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R8G8B8A8_SINT Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = asuint(tsiRefConversion.Load(uint3(x,y,0))); 22 | values.HLSLResult = asuint(D3DX_R8G8B8A8_SINT_to_INT4(values.testVal)); 23 | values.outVal = D3DX_INT4_to_R8G8B8A8_SINT(asint(values.RefResult)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0x80000000,0xffffff7f,0x80000000,0xffffff7f); 34 | values.HLSLResult = uint4(0xFFFFFF80,0xFFFFFF80,0xFFFFFF80,0xFFFFFF80); 35 | values.testVal = asuint(D3DX_INT4_to_R8G8B8A8_SINT(asint(values.RefResult))); 36 | values.outVal = asuint(D3DX_INT4_to_R8G8B8A8_SINT(asint(values.HLSLResult))); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/F8U.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R8G8B8A8_UNORM Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = asuint(tfRefConversion.Load(uint3(x,y,0))); 22 | values.HLSLResult = asuint(D3DX_R8G8B8A8_UNORM_to_FLOAT4(values.testVal)); 23 | values.outVal = D3DX_FLOAT4_to_R8G8B8A8_UNORM(asfloat(values.RefResult)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,asuint(1.1f),asuint(-0.2f),0x7f800000); 34 | values.HLSLResult = asuint(float4(0,1,0,1)); 35 | values.testVal = D3DX_FLOAT4_to_R8G8B8A8_UNORM(asfloat(values.RefResult)); 36 | values.outVal = D3DX_FLOAT4_to_R8G8B8A8_UNORM(asfloat(values.HLSLResult)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/F8UI.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R8G8B8A8_UINT Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = tuiRefConversion.Load(uint3(x,y,0)); 22 | values.HLSLResult = D3DX_R8G8B8A8_UINT_to_UINT4(values.testVal); 23 | values.outVal = D3DX_UINT4_to_R8G8B8A8_UINT(values.RefResult); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,0x00000100,0xffffffff,0x00000100); 34 | values.HLSLResult = uint4(0x000000ff,0x000000ff,0x000000ff,0x000000ff); 35 | values.testVal = D3DX_UINT4_to_R8G8B8A8_UINT(values.RefResult); 36 | values.outVal = D3DX_UINT4_to_R8G8B8A8_UINT(values.HLSLResult); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/F8US.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // R8G8B8A8_UNORM_SRGB Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = asuint(tfRefConversion.Load(uint3(x,y,0))); 22 | values.HLSLResult = asuint(D3DX_R8G8B8A8_UNORM_SRGB_to_FLOAT4(values.testVal)); 23 | values.outVal = D3DX_FLOAT4_to_R8G8B8A8_UNORM_SRGB(asfloat(values.RefResult)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,asuint(1.1f),asuint(-0.2f),0x7f800000); 34 | values.HLSLResult = asuint(float4(0,1,0,1)); 35 | values.testVal = D3DX_FLOAT4_to_R8G8B8A8_UNORM_SRGB(asfloat(values.RefResult)); 36 | values.outVal = D3DX_FLOAT4_to_R8G8B8A8_UNORM_SRGB(asfloat(values.HLSLResult)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/FB8U.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // B8G8R8A8_UNORM Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = asuint(tfRefConversion.Load(uint3(x,y,0))); 22 | values.HLSLResult = asuint(D3DX_B8G8R8A8_UNORM_to_FLOAT4(values.testVal)); 23 | values.outVal = D3DX_FLOAT4_to_B8G8R8A8_UNORM(asfloat(values.RefResult)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,asuint(1.1f),asuint(-0.2f),0x7f800000); 34 | values.HLSLResult = uint4(0,asuint(1.0f),0,asuint(1.0f)); 35 | values.testVal = D3DX_FLOAT4_to_B8G8R8A8_UNORM(asfloat(values.RefResult)); 36 | values.outVal = D3DX_FLOAT4_to_B8G8R8A8_UNORM(asfloat(values.HLSLResult)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/FB8US.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // B8G8R8A8_UNORM_SRGB Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = asuint(tfRefConversion.Load(uint3(x,y,0))); 22 | values.HLSLResult = asuint(D3DX_B8G8R8A8_UNORM_SRGB_to_FLOAT4(values.testVal)); 23 | values.outVal = D3DX_FLOAT4_to_B8G8R8A8_UNORM_SRGB(asfloat(values.RefResult)); 24 | if( any(values.RefResult != values.HLSLResult) || (values.testVal != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,asuint(1.1f),asuint(-0.2f),0x7f800000); 34 | values.HLSLResult = uint4(0,asuint(1.0f),0,asuint(1.0f)); 35 | values.testVal = D3DX_FLOAT4_to_B8G8R8A8_UNORM_SRGB(asfloat(values.RefResult)); 36 | values.outVal = D3DX_FLOAT4_to_B8G8R8A8_UNORM_SRGB(asfloat(values.HLSLResult)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/FBX8U.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // B8G8R8X8_UNORM Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = uint4(asuint(tfRefConversion.Load(uint3(x,y,0)).xyz),asuint(1.0f)); 22 | values.HLSLResult = float4(asuint(D3DX_B8G8R8X8_UNORM_to_FLOAT3(values.testVal)),asuint(1.0f)); 23 | values.outVal = D3DX_FLOAT3_to_B8G8R8X8_UNORM(asfloat(values.RefResult.xyz)); 24 | if( any(values.RefResult != values.HLSLResult) || ((values.testVal&0x00ffffff) != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,asuint(1.1f),asuint(-0.2f),asuint(1.0f)); 34 | values.HLSLResult = uint4(0,asuint(1.0f),0,asuint(1.0f)); 35 | values.testVal = D3DX_FLOAT3_to_B8G8R8X8_UNORM(asfloat(values.RefResult.xyz)); 36 | values.outVal = D3DX_FLOAT3_to_B8G8R8X8_UNORM(asfloat(values.HLSLResult.xyz)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/FBX8US.hlsl: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include "fmtconverttest.hlsli" 5 | 6 | //----------------------------------------------------------------------------- 7 | // B8G8R8X8_UNORM_SRGB Test Shader 8 | //----------------------------------------------------------------------------- 9 | [numthreads(1,1,1)] 10 | void main() 11 | { 12 | uint width, height; 13 | uUINT.GetDimensions(width, height); 14 | 15 | for(uint y = 0; y < height; y++) 16 | { 17 | for(uint x = 0; x < width; x++) 18 | { 19 | VALUES values; 20 | values.testVal = uUINT[uint2(x,y)]; 21 | values.RefResult = uint4(asuint(tfRefConversion.Load(uint3(x,y,0)).xyz),asuint(1.0f)); 22 | values.HLSLResult = uint4(asuint(D3DX_B8G8R8X8_UNORM_SRGB_to_FLOAT3(values.testVal)),asuint(1.0f)); 23 | values.outVal = D3DX_FLOAT3_to_B8G8R8X8_UNORM_SRGB(asfloat(values.RefResult.xyz)); 24 | if( any(values.RefResult != values.HLSLResult) || ((values.testVal&0x00ffffff) != values.outVal) ) 25 | { 26 | uErrors.Append(values); 27 | } 28 | } 29 | } 30 | if( uUINT[uint2(0,0)] == 0 ) 31 | { 32 | VALUES values; 33 | values.RefResult = uint4(0xffffffff,asuint(1.1f),asuint(-0.2f),asuint(1.0f)); 34 | values.HLSLResult = uint4(0,asuint(1.0f),0,asuint(1.0f)); 35 | values.testVal = D3DX_FLOAT3_to_B8G8R8X8_UNORM_SRGB(asfloat(values.RefResult.xyz)); 36 | values.outVal = D3DX_FLOAT3_to_B8G8R8X8_UNORM_SRGB(asfloat(values.HLSLResult.xyz)); 37 | if( values.testVal != values.outVal ) 38 | { 39 | uErrors.Append(values); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/fmtconvert.cpp: -------------------------------------------------------------------------------- 1 | // D3DX_DXGIFormatConvert.inl Tester 2 | // 3 | // Copyright (c) Microsoft Corporation. 4 | // Licensed under the MIT License. 5 | 6 | #include 7 | 8 | #include "D3DX_DXGIFormatConvert.inl" 9 | 10 | int main() 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Tests/fmtconverttest.hlsli: -------------------------------------------------------------------------------- 1 | #include "..\D3DX_DXGIFormatConvert.inl" 2 | 3 | //----------------------------------------------------------------------------- 4 | // Declare buffers 5 | //----------------------------------------------------------------------------- 6 | Texture2D tfRefConversion : register(t0); 7 | Texture2D tuiRefConversion : register(t0); 8 | Texture2D tsiRefConversion : register(t0); 9 | 10 | struct VALUES 11 | { 12 | uint testVal; 13 | uint4 HLSLResult; 14 | uint4 RefResult; 15 | uint outVal; 16 | }; 17 | 18 | RWTexture2D uUINT : register(u0); 19 | AppendStructuredBuffer uErrors : register(u1); 20 | -------------------------------------------------------------------------------- /build/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", 3 | "dependencies": [ 4 | "directxmath", 5 | { 6 | "name": "directx-dxc", 7 | "host": true 8 | } 9 | ] 10 | } --------------------------------------------------------------------------------