wiGraphics refactors (#359)
* Mark concrete graphics device classes as final - they should not be inherited from further. * Apply consistent snake_cast naming (which has been used in more recent additions) across wiGraphics structs * Make 'CommandList' type safe so that calling graphics device functions is less error-prone. * Decouple wiProfiler from wiRenderer by passing the device instance to functions instead of using wiRenderer::GetDevice(). * Bump minor version for graphics refactors. * Decouple wiHelper screenshot/saveTexture* functions from wiRenderer by providing the graphics device as a parameter. * Convert wiGraphics.h enums to use enum class (except a couple of raytracing flag enums which seem best left) * hdr fix * Documentation updates for enum class. * Revert "Decouple wiHelper screenshot/saveTexture* functions from wiRenderer by providing the graphics device as a parameter." This reverts commitfd70249554. * Revert "Decouple wiProfiler from wiRenderer by passing the device instance to functions instead of using wiRenderer::GetDevice()." This reverts commit69b5326cfc. * Fix debug build * Fix gcc build (hopefully). Move bitmask operator defs to end of file outside of wiGraphics namespace. * Remove 'to_underlying' and replace with casts * graphics device access decoupled from wiRenderer, now should be accessed from wiGraphics::GetDevice() * minor refactors, comments * dx12 assert fix * fixes * commandlist refactor * commandlist initial value * commandlist refactor * graphicsdevice comments, GetActivePipelineCount() function * has changed to has_flag * just rename a thing Co-authored-by: Turánszki János <turanszkij@users.noreply.github.com>
This commit is contained in:
+38
-39
@@ -1,6 +1,5 @@
|
||||
#include "wiHelper.h"
|
||||
#include "wiPlatform.h"
|
||||
#include "wiRenderer.h"
|
||||
#include "wiBackLog.h"
|
||||
#include "wiEvent.h"
|
||||
|
||||
@@ -90,7 +89,7 @@ namespace wiHelper
|
||||
filename = directory + "/sc_" + getCurrentDateTimeAsString() + ".jpg";
|
||||
}
|
||||
|
||||
bool result = saveTextureToFile(wiRenderer::GetDevice()->GetBackBuffer(&swapchain), filename);
|
||||
bool result = saveTextureToFile(wiGraphics::GetDevice()->GetBackBuffer(&swapchain), filename);
|
||||
assert(result);
|
||||
|
||||
if (result)
|
||||
@@ -104,17 +103,17 @@ namespace wiHelper
|
||||
{
|
||||
using namespace wiGraphics;
|
||||
|
||||
GraphicsDevice* device = wiRenderer::GetDevice();
|
||||
GraphicsDevice* device = wiGraphics::GetDevice();
|
||||
|
||||
TextureDesc desc = texture.GetDesc();
|
||||
|
||||
Texture stagingTex;
|
||||
TextureDesc staging_desc = desc;
|
||||
staging_desc.Usage = USAGE_READBACK;
|
||||
staging_desc.MipLevels = 1;
|
||||
staging_desc.layout = RESOURCE_STATE_COPY_DST;
|
||||
staging_desc.BindFlags = BIND_NONE;
|
||||
staging_desc.MiscFlags = RESOURCE_MISC_NONE;
|
||||
staging_desc.usage = Usage::READBACK;
|
||||
staging_desc.mip_levels = 1;
|
||||
staging_desc.layout = ResourceState::COPY_DST;
|
||||
staging_desc.bind_flags = BindFlag::NONE;
|
||||
staging_desc.misc_flags = ResourceMiscFlag::NONE;
|
||||
bool success = device->CreateTexture(&staging_desc, nullptr, &stagingTex);
|
||||
assert(success);
|
||||
|
||||
@@ -122,7 +121,7 @@ namespace wiHelper
|
||||
|
||||
{
|
||||
GPUBarrier barriers[] = {
|
||||
GPUBarrier::Image(&texture,texture.desc.layout,RESOURCE_STATE_COPY_SRC),
|
||||
GPUBarrier::Image(&texture,texture.desc.layout,ResourceState::COPY_SRC),
|
||||
};
|
||||
device->Barrier(barriers, arraysize(barriers), cmd);
|
||||
}
|
||||
@@ -131,7 +130,7 @@ namespace wiHelper
|
||||
|
||||
{
|
||||
GPUBarrier barriers[] = {
|
||||
GPUBarrier::Image(&texture,RESOURCE_STATE_COPY_SRC,texture.desc.layout),
|
||||
GPUBarrier::Image(&texture,ResourceState::COPY_SRC,texture.desc.layout),
|
||||
};
|
||||
device->Barrier(barriers, arraysize(barriers), cmd);
|
||||
}
|
||||
@@ -139,10 +138,10 @@ namespace wiHelper
|
||||
device->SubmitCommandLists();
|
||||
device->WaitForGPU();
|
||||
|
||||
desc.Width /= GetFormatBlockSize(desc.Format);
|
||||
desc.Height /= GetFormatBlockSize(desc.Format);
|
||||
uint32_t data_count = desc.Width * desc.Height;
|
||||
uint32_t data_stride = GetFormatStride(desc.Format);
|
||||
desc.width /= GetFormatBlockSize(desc.format);
|
||||
desc.height /= GetFormatBlockSize(desc.format);
|
||||
uint32_t data_count = desc.width * desc.height;
|
||||
uint32_t data_stride = GetFormatStride(desc.format);
|
||||
uint32_t data_size = data_count * data_stride;
|
||||
|
||||
texturedata.clear();
|
||||
@@ -150,11 +149,11 @@ namespace wiHelper
|
||||
|
||||
if (stagingTex.mapped_data != nullptr)
|
||||
{
|
||||
if (stagingTex.mapped_rowpitch / data_stride != desc.Width)
|
||||
if (stagingTex.mapped_rowpitch / data_stride != desc.width)
|
||||
{
|
||||
// Copy padded texture row by row:
|
||||
const uint32_t cpysize = desc.Width * data_stride;
|
||||
for (uint32_t i = 0; i < desc.Height; ++i)
|
||||
const uint32_t cpysize = desc.width * data_stride;
|
||||
for (uint32_t i = 0; i < desc.height; ++i)
|
||||
{
|
||||
void* src = (void*)((size_t)stagingTex.mapped_data + size_t(i * stagingTex.mapped_rowpitch));
|
||||
void* dst = (void*)((size_t)texturedata.data() + size_t(i * cpysize));
|
||||
@@ -190,14 +189,14 @@ namespace wiHelper
|
||||
bool saveTextureToMemoryFile(const std::vector<uint8_t>& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileExtension, std::vector<uint8_t>& filedata)
|
||||
{
|
||||
using namespace wiGraphics;
|
||||
uint32_t data_count = desc.Width * desc.Height;
|
||||
uint32_t data_count = desc.width * desc.height;
|
||||
|
||||
std::string extension = wiHelper::toUpper(fileExtension);
|
||||
bool basis = !extension.compare("BASIS");
|
||||
bool ktx2 = !extension.compare("KTX2");
|
||||
basisu::image basis_image;
|
||||
|
||||
if (desc.Format == FORMAT_R10G10B10A2_UNORM)
|
||||
if (desc.format == Format::R10G10B10A2_UNORM)
|
||||
{
|
||||
// This will be converted first to rgba8 before saving to common format:
|
||||
uint32_t* data32 = (uint32_t*)texturedata.data();
|
||||
@@ -219,7 +218,7 @@ namespace wiHelper
|
||||
data32[i] = rgba8;
|
||||
}
|
||||
}
|
||||
else if (desc.Format == FORMAT_R32G32B32A32_FLOAT)
|
||||
else if (desc.format == Format::R32G32B32A32_FLOAT)
|
||||
{
|
||||
// This will be converted first to rgba8 before saving to common format:
|
||||
XMFLOAT4* dataSrc = (XMFLOAT4*)texturedata.data();
|
||||
@@ -242,7 +241,7 @@ namespace wiHelper
|
||||
data32[i] = rgba8;
|
||||
}
|
||||
}
|
||||
else if (desc.Format == FORMAT_R16G16B16A16_FLOAT)
|
||||
else if (desc.format == Format::R16G16B16A16_FLOAT)
|
||||
{
|
||||
// This will be converted first to rgba8 before saving to common format:
|
||||
XMHALF4* dataSrc = (XMHALF4*)texturedata.data();
|
||||
@@ -265,7 +264,7 @@ namespace wiHelper
|
||||
data32[i] = rgba8;
|
||||
}
|
||||
}
|
||||
else if (desc.Format == FORMAT_R11G11B10_FLOAT)
|
||||
else if (desc.format == Format::R11G11B10_FLOAT)
|
||||
{
|
||||
// This will be converted first to rgba8 before saving to common format:
|
||||
XMFLOAT3PK* dataSrc = (XMFLOAT3PK*)texturedata.data();
|
||||
@@ -291,48 +290,48 @@ namespace wiHelper
|
||||
data32[i] = rgba8;
|
||||
}
|
||||
}
|
||||
else if (IsFormatBlockCompressed(desc.Format))
|
||||
else if (IsFormatBlockCompressed(desc.format))
|
||||
{
|
||||
basisu::texture_format fmt;
|
||||
switch (desc.Format)
|
||||
switch (desc.format)
|
||||
{
|
||||
default:
|
||||
assert(0);
|
||||
return false;
|
||||
case FORMAT_BC1_UNORM:
|
||||
case FORMAT_BC1_UNORM_SRGB:
|
||||
case Format::BC1_UNORM:
|
||||
case Format::BC1_UNORM_SRGB:
|
||||
fmt = basisu::texture_format::cBC1;
|
||||
break;
|
||||
case FORMAT_BC3_UNORM:
|
||||
case FORMAT_BC3_UNORM_SRGB:
|
||||
case Format::BC3_UNORM:
|
||||
case Format::BC3_UNORM_SRGB:
|
||||
fmt = basisu::texture_format::cBC3;
|
||||
break;
|
||||
case FORMAT_BC4_UNORM:
|
||||
case Format::BC4_UNORM:
|
||||
fmt = basisu::texture_format::cBC4;
|
||||
break;
|
||||
case FORMAT_BC5_UNORM:
|
||||
case Format::BC5_UNORM:
|
||||
fmt = basisu::texture_format::cBC5;
|
||||
break;
|
||||
case FORMAT_BC7_UNORM:
|
||||
case FORMAT_BC7_UNORM_SRGB:
|
||||
case Format::BC7_UNORM:
|
||||
case Format::BC7_UNORM_SRGB:
|
||||
fmt = basisu::texture_format::cBC7;
|
||||
break;
|
||||
}
|
||||
basisu::gpu_image basis_gpu_image;
|
||||
basis_gpu_image.init(fmt, desc.Width, desc.Height);
|
||||
basis_gpu_image.init(fmt, desc.width, desc.height);
|
||||
std::memcpy(basis_gpu_image.get_ptr(), texturedata.data(), std::min(texturedata.size(), (size_t)basis_gpu_image.get_size_in_bytes()));
|
||||
basis_gpu_image.unpack(basis_image);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(desc.Format == FORMAT_R8G8B8A8_UNORM); // If you need to save other texture format, implement data conversion for it
|
||||
assert(desc.format == Format::R8G8B8A8_UNORM); // If you need to save other texture format, implement data conversion for it
|
||||
}
|
||||
|
||||
if (basis || ktx2)
|
||||
{
|
||||
if (basis_image.get_total_pixels() == 0)
|
||||
{
|
||||
basis_image.init(texturedata.data(), desc.Width, desc.Height, 4);
|
||||
basis_image.init(texturedata.data(), desc.width, desc.height, 4);
|
||||
}
|
||||
basisu::basis_compressor_params params;
|
||||
params.m_source_images.push_back(basis_image);
|
||||
@@ -400,19 +399,19 @@ namespace wiHelper
|
||||
|
||||
if (!extension.compare("JPG") || !extension.compare("JPEG"))
|
||||
{
|
||||
write_result = stbi_write_jpg_to_func(func, &filedata, (int)desc.Width, (int)desc.Height, 4, src_data, 100);
|
||||
write_result = stbi_write_jpg_to_func(func, &filedata, (int)desc.width, (int)desc.height, 4, src_data, 100);
|
||||
}
|
||||
else if (!extension.compare("PNG"))
|
||||
{
|
||||
write_result = stbi_write_png_to_func(func, &filedata, (int)desc.Width, (int)desc.Height, 4, src_data, 0);
|
||||
write_result = stbi_write_png_to_func(func, &filedata, (int)desc.width, (int)desc.height, 4, src_data, 0);
|
||||
}
|
||||
else if (!extension.compare("TGA"))
|
||||
{
|
||||
write_result = stbi_write_tga_to_func(func, &filedata, (int)desc.Width, (int)desc.Height, 4, src_data);
|
||||
write_result = stbi_write_tga_to_func(func, &filedata, (int)desc.width, (int)desc.height, 4, src_data);
|
||||
}
|
||||
else if (!extension.compare("BMP"))
|
||||
{
|
||||
write_result = stbi_write_bmp_to_func(func, &filedata, (int)desc.Width, (int)desc.Height, 4, src_data);
|
||||
write_result = stbi_write_bmp_to_func(func, &filedata, (int)desc.width, (int)desc.height, 4, src_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user