mirror of https://github.com/auygun/kaliber.git
Code cleanup
This commit is contained in:
parent
1e57355593
commit
a2dafd172e
|
@ -274,11 +274,7 @@ void Engine::ReleaseTexture(const std::string& asset_name) {
|
|||
if (it == textures_.end())
|
||||
return;
|
||||
|
||||
if (it->second.use_count == 0) {
|
||||
DCHECK(!it->second.texture->IsValid());
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(it->second.use_count > 0);
|
||||
it->second.use_count--;
|
||||
if (!it->second.persistent && it->second.use_count == 0)
|
||||
it->second.texture->Destroy();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "base/log.h"
|
||||
#include "base/vecmath.h"
|
||||
|
@ -23,7 +24,7 @@ using namespace base;
|
|||
namespace {
|
||||
|
||||
using VertexInputDescription =
|
||||
std::tuple<std::vector<VkVertexInputBindingDescription>,
|
||||
std::pair<std::vector<VkVertexInputBindingDescription>,
|
||||
std::vector<VkVertexInputAttributeDescription>>;
|
||||
|
||||
constexpr VkPrimitiveTopology kVkPrimitiveType[eng::kPrimitive_Max] = {
|
||||
|
@ -180,7 +181,7 @@ VertexInputDescription GetVertexInputDescription(
|
|||
bindings[0].stride = vertex_offset;
|
||||
bindings[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
|
||||
return std::make_tuple(std::move(bindings), std::move(attributes));
|
||||
return std::make_pair(std::move(bindings), std::move(attributes));
|
||||
}
|
||||
|
||||
VkIndexType GetIndexType(eng::DataType data_type) {
|
||||
|
@ -214,41 +215,35 @@ VkFormat GetImageFormat(eng::Image::Format format) {
|
|||
return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
}
|
||||
|
||||
void GetBlockSizeForImageFormat(VkFormat format, int& size, int& height) {
|
||||
std::pair<int, int> GetBlockSizeForImageFormat(VkFormat format) {
|
||||
switch (format) {
|
||||
case VK_FORMAT_R8G8B8A8_UNORM:
|
||||
size = 4;
|
||||
height = 1;
|
||||
return;
|
||||
return {4, 1};
|
||||
case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
|
||||
size = 8;
|
||||
height = 4;
|
||||
return;
|
||||
return {8, 4};
|
||||
case VK_FORMAT_BC3_UNORM_BLOCK:
|
||||
size = 16;
|
||||
height = 4;
|
||||
return;
|
||||
return {16, 4};
|
||||
default:
|
||||
break;
|
||||
}
|
||||
NOTREACHED << "Invalid format: " << format;
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
void GetNumBlocksForImageFormat(VkFormat format,
|
||||
int& num_blocks_x,
|
||||
int& num_blocks_y) {
|
||||
std::pair<int, int> GetNumBlocksForImageFormat(VkFormat format,
|
||||
int width,
|
||||
int height) {
|
||||
switch (format) {
|
||||
case VK_FORMAT_R8G8B8A8_UNORM:
|
||||
return;
|
||||
return {width, height};
|
||||
case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
|
||||
case VK_FORMAT_BC3_UNORM_BLOCK:
|
||||
num_blocks_x = (num_blocks_x + 3) / 4;
|
||||
num_blocks_y = (num_blocks_y + 3) / 4;
|
||||
return;
|
||||
return {(width + 3) / 4, (height + 3) / 4};
|
||||
default:
|
||||
break;
|
||||
}
|
||||
NOTREACHED << "Invalid format: " << format;
|
||||
return {width, height};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -1482,12 +1477,10 @@ void RendererVulkan::UpdateImage(VkImage image,
|
|||
const uint8_t* data,
|
||||
int width,
|
||||
int height) {
|
||||
int num_blocks_x = width;
|
||||
int num_blocks_y = height;
|
||||
GetNumBlocksForImageFormat(format, num_blocks_x, num_blocks_y);
|
||||
auto [num_blocks_x, num_blocks_y] =
|
||||
GetNumBlocksForImageFormat(format, width, height);
|
||||
|
||||
int block_size, block_height;
|
||||
GetBlockSizeForImageFormat(format, block_size, block_height);
|
||||
auto [block_size, block_height] = GetBlockSizeForImageFormat(format);
|
||||
|
||||
size_t to_submit = num_blocks_x * num_blocks_y * block_size;
|
||||
size_t submit_from = 0;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ const char kVertexShaderMacros[] = R"(
|
|||
#define PARAM(X) params.X
|
||||
#else
|
||||
#define UNIFORM_BEGIN
|
||||
#define UNIFORM uniform
|
||||
#define UNIFORM_V(X) uniform X;
|
||||
#define UNIFORM_F(X)
|
||||
#define UNIFORM_END
|
||||
|
|
Loading…
Reference in New Issue