| 142 | } |
| 143 | |
| 144 | void PixelDebug::renderUI(Gui::Widgets* widget) |
| 145 | { |
| 146 | FALCOR_CHECK(!mRunning, "Logging is running, call endFrame() before renderUI()."); |
| 147 | |
| 148 | if (widget) |
| 149 | { |
| 150 | // Configure logging. |
| 151 | widget->checkbox("Pixel debug", mEnabled); |
| 152 | widget->tooltip( |
| 153 | "Enables shader debugging.\n\n" |
| 154 | "Left-mouse click on a pixel to select it.\n" |
| 155 | "Use print(value) or print(msg, value) in the shader to print values for the selected pixel.\n" |
| 156 | "All basic types such as int, float2, etc. are supported.\n" |
| 157 | "Use assert(condition) or assert(condition, msg) in the shader to test a condition.", |
| 158 | true |
| 159 | ); |
| 160 | if (mEnabled) |
| 161 | { |
| 162 | widget->var("Selected pixel", mSelectedPixel); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // Fetch stats and show log if available. |
| 167 | bool isNewData = copyDataToCPU(); |
| 168 | if (mDataValid) |
| 169 | { |
| 170 | std::ostringstream oss; |
| 171 | |
| 172 | // Print list of printed values. |
| 173 | oss << "Pixel log:" << (mPrintData.empty() ? " <empty>\n" : "\n"); |
| 174 | for (auto v : mPrintData) |
| 175 | { |
| 176 | // Print message. |
| 177 | auto it = mHashToString.find(v.msgHash); |
| 178 | if (it != mHashToString.end() && !it->second.empty()) |
| 179 | oss << it->second << " "; |
| 180 | |
| 181 | // Parse value and convert to string. |
| 182 | if (v.count > 1) |
| 183 | oss << "("; |
| 184 | for (uint32_t i = 0; i < v.count; i++) |
| 185 | { |
| 186 | uint32_t bits = v.data[i]; |
| 187 | switch ((PrintValueType)v.type) |
| 188 | { |
| 189 | case PrintValueType::Bool: |
| 190 | oss << (bits != 0 ? "true" : "false"); |
| 191 | break; |
| 192 | case PrintValueType::Int: |
| 193 | oss << (int32_t)bits; |
| 194 | break; |
| 195 | case PrintValueType::Uint: |
| 196 | oss << bits; |
| 197 | break; |
| 198 | case PrintValueType::Float: |
| 199 | oss << fstd::bit_cast<float>(bits); |
| 200 | break; |
| 201 | default: |