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