MSVC fixes.

This commit is contained in:
Anish Bhobe 2024-07-14 23:03:04 +02:00
parent 69aa72770f
commit 362468ebe7
11 changed files with 41 additions and 25 deletions

View File

@ -10,7 +10,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
if (MSVC) if (MSVC)
set(CMAKE_CXX_FLAGS "/W4 /GR- /Zi") set(CMAKE_CXX_FLAGS "/W4 /GR- /Zi")
add_compile_definitions(_HAS_EXCEPTIONS=1) add_compile_definitions(_HAS_EXCEPTIONS=0)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
else () else ()
set(CMAKE_CXX_FLAGS "-Wall -g -fno-rtti -fno-exceptions") set(CMAKE_CXX_FLAGS "-Wall -g -fno-rtti -fno-exceptions")

View File

@ -49,7 +49,7 @@ Buffer::Allocate(const Device *device, usize size, vk::BufferUsageFlags bufferUs
m_Buffer = buffer; m_Buffer = buffer;
m_Size = size | VALID_BUFFER_BIT | (hostAccessible ? HOST_ACCESSIBLE_BIT : 0); m_Size = size | VALID_BUFFER_BIT | (hostAccessible ? HOST_ACCESSIBLE_BIT : 0);
m_Allocation = allocation; m_Allocation = allocation;
m_Mapped = allocationInfo.pMappedData; m_Mapped = Cast<u8 *>(allocationInfo.pMappedData);
device->SetName(m_Buffer, name); device->SetName(m_Buffer, name);
} }
@ -61,11 +61,13 @@ Buffer::Write(const Device *device, usize offset, usize size, const void *data)
if (!IsMapped()) if (!IsMapped())
{ {
auto result = Cast<vk::Result>(vmaMapMemory(device->m_Allocator, m_Allocation, &m_Mapped)); void *mapped;
auto result = Cast<vk::Result>(vmaMapMemory(device->m_Allocator, m_Allocation, &mapped));
ERROR_IF(Failed(result), "Memory mapping failed. Cause: {}", result); ERROR_IF(Failed(result), "Memory mapping failed. Cause: {}", result);
if (!Failed(result)) if (!Failed(result))
{ {
memcpy(m_Mapped, data, size); m_Mapped = Cast<u8 *>(mapped);
memcpy(m_Mapped + offset, data, size);
vmaUnmapMemory(device->m_Allocator, m_Allocation); vmaUnmapMemory(device->m_Allocator, m_Allocation);
m_Mapped = nullptr; m_Mapped = nullptr;
@ -73,7 +75,7 @@ Buffer::Write(const Device *device, usize offset, usize size, const void *data)
} }
else else
{ {
memcpy(m_Mapped, data, size); memcpy(m_Mapped + offset, data, size);
} }
// TODO: Debug this. // TODO: Debug this.

View File

@ -13,7 +13,7 @@ struct Buffer
{ {
vk::Buffer m_Buffer = nullptr; vk::Buffer m_Buffer = nullptr;
VmaAllocation m_Allocation = nullptr; VmaAllocation m_Allocation = nullptr;
void *m_Mapped = nullptr; u8 *m_Mapped = nullptr;
[[nodiscard]] usize GetSize() const; [[nodiscard]] usize GetSize() const;
[[nodiscard]] bool IsHostVisible() const; [[nodiscard]] bool IsHostVisible() const;

View File

@ -68,7 +68,7 @@ Texture::Init(const Device *device, const vk::Extent2D extent, vk::Format imageF
m_View = view; m_View = view;
m_Allocation = allocation; m_Allocation = allocation;
m_Extent = {extent.width, extent.height, 1}; m_Extent = {extent.width, extent.height, 1};
m_MipLevels = mipLevels; m_MipLevels = Cast<u8>(mipLevels);
device->SetName(m_Image, name); device->SetName(m_Image, name);
} }

View File

@ -103,7 +103,7 @@ FrameManager::GetNextFrame(Swapchain *swapchain, const Window *window)
AbortIfFailedMV(m_Device->m_Device.waitForFences(1, &currentFrame->m_FrameAvailableFence, true, MaxValue<u64>), AbortIfFailedMV(m_Device->m_Device.waitForFences(1, &currentFrame->m_FrameAvailableFence, true, MaxValue<u64>),
"Waiting for fence {} failed.", frameIndex); "Waiting for fence {} failed.", frameIndex);
u32 imageIndex; u32 imageIndex = 0;
bool imageAcquired = false; bool imageAcquired = false;
while (!imageAcquired) while (!imageAcquired)
{ {

View File

@ -339,7 +339,7 @@ main(int, char **)
.addressModeU = vk::SamplerAddressMode::eRepeat, .addressModeU = vk::SamplerAddressMode::eRepeat,
.addressModeV = vk::SamplerAddressMode::eRepeat, .addressModeV = vk::SamplerAddressMode::eRepeat,
.addressModeW = vk::SamplerAddressMode::eRepeat, .addressModeW = vk::SamplerAddressMode::eRepeat,
.mipLodBias = 0.2, .mipLodBias = 0.2f,
.anisotropyEnable = true, .anisotropyEnable = true,
.maxAnisotropy = 1.0f, .maxAnisotropy = 1.0f,
.compareEnable = false, .compareEnable = false,

View File

@ -29,10 +29,23 @@ VectorToVec4(const std::vector<double> &vec)
{ {
return vec4{0.0f}; return vec4{0.0f};
} }
assert(vec.size() == 4);
return {vec[0], vec[1], vec[2], vec[3]}; return {vec[0], vec[1], vec[2], vec[3]};
} }
vec3
VectorToVec3(const std::vector<double> &vec)
{
if (vec.empty())
{
return vec3{0.0f};
}
assert(vec.size() == 3);
return {vec[0], vec[1], vec[2]};
}
TextureHandle TextureHandle
ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, Texture *texture, StagingBuffer *stagingBuffer, ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, Texture *texture, StagingBuffer *stagingBuffer,
tinygltf::Image *image) tinygltf::Image *image)
@ -228,7 +241,7 @@ ModelLoader::LoadModel(cstr path, cstr name)
if (!model.images.empty()) if (!model.images.empty())
{ {
u32 numImages = model.images.size(); u32 numImages = Cast<u32>(model.images.size());
stagingBuffers.resize(numImages); stagingBuffers.resize(numImages);
textures.resize(numImages); textures.resize(numImages);
@ -264,7 +277,7 @@ ModelLoader::LoadModel(cstr path, cstr name)
{ {
materials.push_back({ materials.push_back({
.m_AlbedoFactor = VectorToVec4(material.pbrMetallicRoughness.baseColorFactor), .m_AlbedoFactor = VectorToVec4(material.pbrMetallicRoughness.baseColorFactor),
.m_EmissionFactor = VectorToVec4(material.emissiveFactor), .m_EmissionFactor = VectorToVec3(material.emissiveFactor),
.m_MetalFactor = Cast<f32>(material.pbrMetallicRoughness.metallicFactor), .m_MetalFactor = Cast<f32>(material.pbrMetallicRoughness.metallicFactor),
.m_RoughFactor = Cast<f32>(material.pbrMetallicRoughness.roughnessFactor), .m_RoughFactor = Cast<f32>(material.pbrMetallicRoughness.roughnessFactor),
.m_AlbedoTex = getTextureHandle(material.pbrMetallicRoughness.baseColorTexture.index), .m_AlbedoTex = getTextureHandle(material.pbrMetallicRoughness.baseColorTexture.index),
@ -299,9 +312,9 @@ ModelLoader::LoadModel(cstr path, cstr name)
{ {
for (auto &prim : mesh.primitives) for (auto &prim : mesh.primitives)
{ {
u32 vertexOffset = vertexPositions.size(); u32 vertexOffset = Cast<u32>(vertexPositions.size());
u32 vertexCount; u32 vertexCount;
u32 indexOffset = indices.size(); u32 indexOffset = Cast<u32>(indices.size());
u32 indexCount; u32 indexCount;
assert(prim.attributes.contains(APosition)); assert(prim.attributes.contains(APosition));
@ -315,7 +328,7 @@ ModelLoader::LoadModel(cstr path, cstr name)
tinygltf::Buffer *posBuffer = &model.buffers[posBufferView->buffer]; tinygltf::Buffer *posBuffer = &model.buffers[posBufferView->buffer];
usize byteOffset = (posAccessor->byteOffset + posBufferView->byteOffset); usize byteOffset = (posAccessor->byteOffset + posBufferView->byteOffset);
vertexCount = posAccessor->count; vertexCount = Cast<u32>(posAccessor->count);
vertexPositions.reserve(vertexOffset + vertexCount); vertexPositions.reserve(vertexOffset + vertexCount);
if (posAccessor->type == TINYGLTF_TYPE_VEC4) if (posAccessor->type == TINYGLTF_TYPE_VEC4)
@ -351,7 +364,7 @@ ModelLoader::LoadModel(cstr path, cstr name)
tinygltf::Buffer *indexBuffer = &model.buffers[indexBufferView->buffer]; tinygltf::Buffer *indexBuffer = &model.buffers[indexBufferView->buffer];
usize byteOffset = (indexAccessor->byteOffset + indexBufferView->byteOffset); usize byteOffset = (indexAccessor->byteOffset + indexBufferView->byteOffset);
indexCount = indexAccessor->count; indexCount = Cast<u32>(indexAccessor->count);
indices.reserve(indexOffset + indexCount); indices.reserve(indexOffset + indexCount);
if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT) if (indexAccessor->componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT)

View File

@ -30,7 +30,7 @@ struct MeshPrimitive
struct Material struct Material
{ {
vec4 m_AlbedoFactor; vec4 m_AlbedoFactor;
vec4 m_EmissionFactor; vec3 m_EmissionFactor;
f32 m_MetalFactor; f32 m_MetalFactor;
f32 m_RoughFactor; f32 m_RoughFactor;
TextureHandle m_AlbedoTex; TextureHandle m_AlbedoTex;

View File

@ -128,10 +128,11 @@ RenderResourceManager::Update()
if (m_Writes.empty() || m_WriteInfos.empty()) if (m_Writes.empty() || m_WriteInfos.empty())
return; return;
m_Device->m_Device.updateDescriptorSets(m_Writes.size(), m_Writes.data(), 0, nullptr); m_Device->m_Device.updateDescriptorSets(Cast<u32>(m_Writes.size()), m_Writes.data(), 0, nullptr);
m_Writes.clear(); m_Writes.clear();
m_WriteInfos.clear(); m_WriteInfos.clear();
m_WriteOwner.clear();
} }
RenderResourceManager::RenderResourceManager(const Device *device, u16 maxSize) RenderResourceManager::RenderResourceManager(const Device *device, u16 maxSize)

View File

@ -12,7 +12,7 @@ struct VertexData {
struct MaterialData { struct MaterialData {
float m_AlbedoFactor[4]; float m_AlbedoFactor[4];
float m_EmissionFactor[4]; float m_EmissionFactor[3];
float m_MetalFactor; float m_MetalFactor;
float m_RoughFactor; float m_RoughFactor;
uint m_AlbedoTex; uint m_AlbedoTex;

View File

@ -11,7 +11,7 @@ struct VertexData {
struct MaterialData { struct MaterialData {
float m_AlbedoFactor[4]; float m_AlbedoFactor[4];
float m_EmissionFactor[4]; float m_EmissionFactor[3];
float m_MetalFactor; float m_MetalFactor;
float m_RoughFactor; float m_RoughFactor;
uint m_AlbedoTex; uint m_AlbedoTex;