Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan dump resources: Add support for R32G32B32A32_SFLOAT images #1768

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions framework/decode/vulkan_replay_dump_resources_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ util::imagewriter::DataFormats VkFormatToImageWriterDataFormat(VkFormat format)
case VK_FORMAT_R16G16B16A16_SFLOAT:
return util::imagewriter::DataFormats::kFormat_R16G16B16A16_SFLOAT;

case VK_FORMAT_R32G32B32A32_SFLOAT:
return util::imagewriter::DataFormats::kFormat_R32G32B32A32_SFLOAT;

case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
return util::imagewriter::DataFormats::kFormat_B10G11R11_UFLOAT;

Expand Down
43 changes: 43 additions & 0 deletions framework/util/image_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,49 @@ static const uint8_t* ConvertIntoTemporaryBuffer(uint32_t width,
}
break;

case kFormat_R32G32B32A32_SFLOAT:
{
const float* float_vals = reinterpret_cast<const float*>(data);

for (uint32_t y = 0; y < height; ++y)
{
for (uint32_t x = 0; x < 4 * width; x += 4)
{
float float_r = float_vals[x];
float float_g = float_vals[x + 1];
float float_b = float_vals[x + 2];
float float_a = float_vals[x + 3];

uint8_t r = static_cast<uint8_t>(float_r * 255.0f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user wants the range [0.0f,1.0f] to be evenly distributed among uint8_t values, I think 255.0f should be std::nextafter(256.0f, 0.0f) (which will equate to 255.99...f). Also, SFLOAT isn't normalized so you probably need to clamp the source values here to [0.0f, 1.0f]. Maybe some day in the future we can go back and alter the other case statements to match but not in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent this feedback from blocking this PR when it applies to all other cases in image_writer.cpp and not just this new addition, I've moved this feedback to #1790 and will remove my feedback on this PR. Note that values will not be distributed uniformly from [0,1] to [0,255] and values outside the range [0,1] will wrap.

uint8_t g = static_cast<uint8_t>(float_g * 255.0f);
uint8_t b = static_cast<uint8_t>(float_b * 255.0f);
uint8_t a = static_cast<uint8_t>(float_a * 255.0f);

if (is_png)
{
*(temp_buffer++) = r;
*(temp_buffer++) = g;
*(temp_buffer++) = b;
}
else
{
*(temp_buffer++) = b;
*(temp_buffer++) = g;
*(temp_buffer++) = r;
}

if (write_alpha)
{
*(temp_buffer++) = a;
}
}

float_vals = reinterpret_cast<const float*>(reinterpret_cast<const uint8_t*>(float_vals) + data_pitch);
temp_buffer = reinterpret_cast<uint8_t*>(temporary_buffer.get()) + (y + 1) * output_pitch;
}
}
break;

case kFormat_D32_FLOAT:
{
const float* floats = reinterpret_cast<const float*>(data);
Expand Down
4 changes: 4 additions & 0 deletions framework/util/image_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ enum DataFormats
kFormat_RGBA,
kFormat_BGR,
kFormat_R16G16B16A16_SFLOAT,
kFormat_R32G32B32A32_SFLOAT,
kFormat_B10G11R11_UFLOAT,
kFormat_BGRA,
kFormat_A2B10G10R10,
Expand Down Expand Up @@ -106,6 +107,9 @@ constexpr size_t DataFormatsSizes(DataFormats format)
case kFormat_R16G16B16A16_SFLOAT:
return 8;

case kFormat_R32G32B32A32_SFLOAT:
return 16;

case kFormat_ASTC:
GFXRECON_LOG_WARNING("%s(): Cannot calculate element size for ASTC.", __func__);
return 0;
Expand Down
Loading