| 74 | |
| 75 | template<typename T> |
| 76 | void ParallelReduction::execute( |
| 77 | RenderContext* pRenderContext, |
| 78 | const ref<Texture>& pInput, |
| 79 | Type operation, |
| 80 | T* pResult, |
| 81 | ref<Buffer> pResultBuffer, |
| 82 | uint64_t resultOffset |
| 83 | ) |
| 84 | { |
| 85 | FALCOR_PROFILE(pRenderContext, "ParallelReduction::execute"); |
| 86 | |
| 87 | // Check texture array/mip/sample count. |
| 88 | if (pInput->getArraySize() != 1 || pInput->getMipCount() != 1 || pInput->getSampleCount() != 1) |
| 89 | { |
| 90 | FALCOR_THROW("ParallelReduction::execute() - Input texture is unsupported."); |
| 91 | } |
| 92 | |
| 93 | // Check texture format. |
| 94 | uint32_t formatType = FORMAT_TYPE_UNKNOWN; |
| 95 | switch (getFormatType(pInput->getFormat())) |
| 96 | { |
| 97 | case FormatType::Float: |
| 98 | case FormatType::Unorm: |
| 99 | case FormatType::Snorm: |
| 100 | formatType = FORMAT_TYPE_FLOAT; |
| 101 | break; |
| 102 | case FormatType::Sint: |
| 103 | formatType = FORMAT_TYPE_SINT; |
| 104 | break; |
| 105 | case FormatType::Uint: |
| 106 | formatType = FORMAT_TYPE_UINT; |
| 107 | break; |
| 108 | default: |
| 109 | FALCOR_THROW("ParallelReduction::execute() - Input texture format unsupported."); |
| 110 | } |
| 111 | |
| 112 | // Check that reduction type T is compatible with the resource format. |
| 113 | if (sizeof(typename T::value_type) != 4 || // The shader is written for 32-bit types |
| 114 | (formatType == FORMAT_TYPE_FLOAT && !std::is_floating_point<typename T::value_type>::value) || |
| 115 | (formatType == FORMAT_TYPE_SINT && |
| 116 | (!std::is_integral<typename T::value_type>::value || !std::is_signed<typename T::value_type>::value)) || |
| 117 | (formatType == FORMAT_TYPE_UINT && |
| 118 | (!std::is_integral<typename T::value_type>::value || !std::is_unsigned<typename T::value_type>::value))) |
| 119 | { |
| 120 | FALCOR_THROW("ParallelReduction::execute() - Template type T is not compatible with resource format."); |
| 121 | } |
| 122 | |
| 123 | uint32_t reductionType = REDUCTION_TYPE_UNKNOWN; |
| 124 | uint32_t elementSize = 0; |
| 125 | switch (operation) |
| 126 | { |
| 127 | case Type::Sum: |
| 128 | reductionType = REDUCTION_TYPE_SUM; |
| 129 | elementSize = 1; |
| 130 | break; |
| 131 | case Type::MinMax: |
| 132 | reductionType = REDUCTION_TYPE_MINMAX; |
| 133 | elementSize = 2; |
nothing calls this directly
no test coverage detected