Skip to content

Commit

Permalink
hitting a "Called function that cannot be supported" issue somewhere.…
Browse files Browse the repository at this point in the history
….. needs further investigation. But we're making significant progress on getting into the game!
  • Loading branch information
PazerOP committed May 28, 2019
1 parent c07cead commit bc125d7
Show file tree
Hide file tree
Showing 54 changed files with 2,089 additions and 446 deletions.
1 change: 1 addition & 0 deletions TF2VulkanUtil/TF2VulkanUtil.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<ClInclude Include="include\TF2Vulkan\Util\interface.h" />
<ClInclude Include="include\TF2Vulkan\Util\KeyValues.h" />
<ClInclude Include="include\TF2Vulkan\Util\MemoryPool.h" />
<ClInclude Include="include\TF2Vulkan\Util\MutexWrapper.h" />
<ClInclude Include="include\TF2Vulkan\Util\platform.h" />
<ClInclude Include="include\TF2Vulkan\Util\SafeConvert.h" />
<ClInclude Include="include\TF2Vulkan\Util\ScopeFunc.h" />
Expand Down
6 changes: 3 additions & 3 deletions TF2VulkanUtil/include/TF2Vulkan/Util/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Util

void LogFunctionCall(const std::string_view& fnSig, const std::string_view& file, int line, const std::string_view& msg);
[[noreturn]] void EnsureConditionFailed(const char* condition, const char* fnSig, const char* file, int line);
void FunctionNotImplemented(const char* fnSig, const char* file, int line);
void FunctionNotImplemented(const char* fnSig, const char* file, int line, const std::string_view& msg = {});

template<>
struct LogFunctionCallScope<false>
Expand All @@ -49,7 +49,7 @@ namespace Util
#define ALL_STATIC_TYPE_INFO(type) \
::Util::StaticTypeInfo{ sizeof(type), 0, alignof(type) }

//#define TF2VULKAN_ENABLE_FUNCTION_LOGGING 1
#define TF2VULKAN_ENABLE_FUNCTION_LOGGING 1
#define TF2VULKAN_LOCAL_ENABLE_FUNCTION_LOGGING true

#if defined(TF2VULKAN_ENABLE_FUNCTION_LOGGING)
Expand All @@ -66,7 +66,7 @@ namespace Util

#define TF2VULKAN_PREFIX "[TF2Vulkan] " __FUNCSIG__ ": "

#define NOT_IMPLEMENTED_FUNC_NOBREAK() ::Util::FunctionNotImplemented(__FUNCSIG__, __FILE__, __LINE__)
#define NOT_IMPLEMENTED_FUNC_NOBREAK(...) ::Util::FunctionNotImplemented(__FUNCSIG__, __FILE__, __LINE__, __VA_ARGS__)

#define PRINTF_SV(stringView) Util::SafeConvert<int>((stringView).size()), (stringView).data()
static constexpr const char* PRINTF_BOOL(bool val) { return val ? "true" : "false"; }
Expand Down
51 changes: 51 additions & 0 deletions TF2VulkanUtil/include/TF2Vulkan/Util/MutexWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include <cassert>
#include <mutex>

namespace Util
{
template<typename T>
class MutexDbgWrapper
{
public:
void lock()
{
m_Mutex.lock();

#ifdef _DEBUG
if (m_LockCount++ == 0)
m_OwningThread = std::this_thread::get_id();
#endif
}

void unlock()
{
#if _DEBUG
auto oldLock = m_LockCount--;
assert(oldLock > 0);
if (oldLock == 1)
m_OwningThread = {};
#endif

m_Mutex.unlock();
}

void assert_has_lock()
{
#ifdef _DEBUG
assert(m_OwningThread == std::this_thread::get_id());
#endif
}

private:
#ifdef _DEBUG
std::thread::id m_OwningThread;
uint32_t m_LockCount = 0;
#endif
T m_Mutex;
};

using MutexDbg = MutexDbgWrapper<std::mutex>;
using RecursiveMutexDbg = MutexDbgWrapper<std::recursive_mutex>;
}
15 changes: 15 additions & 0 deletions TF2VulkanUtil/include/TF2Vulkan/Util/std_variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

#include <variant>

namespace Util
{
template<typename T, typename... Types, typename... TArgs>
inline T& get_or_emplace(std::variant<Types...>& var, TArgs&& ... emplaceArgs)
{
return std::holds_alternative<T>(var) ? std::get<T>(var) : var.emplace<T>(std::forward(emplaceArgs)...);
}

template<size_t index, typename... Types, typename... TArgs>
inline auto& get_or_emplace(std::variant<Types...>& var, TArgs&& ... emplaceArgs)
{
return std::holds_alternative<index>(var) ? std::get<index>(var) : var.emplace<index>(std::forward(emplaceArgs)...);
}
}

#if false
#ifndef __INTELLISENSE__
template<typename... T>
Expand Down
10 changes: 5 additions & 5 deletions TF2VulkanUtil/src/TF2Vulkan/Util/Macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ namespace

void Util::EnsureConditionFailed(const char* condition, const char* fnSig, const char* file, int line)
{
Warning("[TF2Vulkan] ENSURE(%s) failed @ %s, %s:%i\n", condition, fnSig, file, line);
const char* fmtStr = "[TF2Vulkan] ENSURE(%s) failed @ %s, %s:%i\n";
Warning(fmtStr, condition, fnSig, file, line);

if (Plat_IsInDebugSession())
__debugbreak();

Error("[TF2Vulkan] ENSURE(%s) failed @ %s, %s:%i\n", condition, fnSig, file, line);
Error(fmtStr, condition, fnSig, file, line);
}

void Util::FunctionNotImplemented(const char* fnSig, const char* file, int line)
void Util::FunctionNotImplemented(const char* fnSig, const char* file, int line, const std::string_view& msg)
{
Warning("[TF2Vulkan] NOT IMPLEMENTED: %s in %s:%i\n", fnSig, file, line);
Warning("[TF2Vulkan] NOT IMPLEMENTED: %s in %s:%i%.*s\n", fnSig, file, line, PRINTF_SV(msg));
}

static thread_local int s_LogFunctionCallIndentation = 0;
Expand Down Expand Up @@ -85,7 +86,6 @@ template struct Util::LogFunctionCallScope<true>;
void Util::LogFunctionCall(const std::string_view& fnSig, const std::string_view& file, int line,
const std::string_view& msg)
{
ASSERT_MAIN_THREAD();
const FnSigComponents comps(fnSig);

char buf[512];
Expand Down
2 changes: 1 addition & 1 deletion sdk2013
22 changes: 22 additions & 0 deletions shaderapivulkan/include/TF2Vulkan/FogParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "TF2Vulkan/Util/std_compare.h"

namespace TF2Vulkan
{
struct LogicalFogParams final
{
constexpr LogicalFogParams() = default;

DEFAULT_PARTIAL_ORDERING_OPERATOR(LogicalFogParams);

float m_Start = 0;
float m_End = 0;
float m_Z = 0;
float m_MaxDensity = 0;
MaterialFogMode_t m_Mode = MATERIAL_FOG_NONE;
uint8_t m_ColorR = 255;
uint8_t m_ColorG = 255;
uint8_t m_ColorB = 255;
};
}
6 changes: 6 additions & 0 deletions shaderapivulkan/include/TF2Vulkan/IShaderDynamicNext.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#include <TF2Vulkan/IBufferPool.h>
#include <TF2Vulkan/IShaderGroup.h>
#include <TF2Vulkan/IShaderInstance.h>
#include "TF2Vulkan/FogParams.h"
#include <TF2Vulkan/Util/Macros.h>

#include <stdshader_vulkan/ShaderDataShared.h>

#include <shaderapi/ishaderdynamic.h>

namespace TF2Vulkan
Expand All @@ -27,6 +31,8 @@ namespace TF2Vulkan
[[nodiscard]] virtual size_t GetLights(LightDesc_t* lights, size_t maxLights) const = 0;
virtual void GetAmbientLightCube(Shaders::AmbientLightCube& cube) const = 0;

virtual const LogicalFogParams& GetFogParams() const = 0;

// From IShaderDynamicAPI
virtual void BindStandardTexture(Sampler_t sampler, StandardTextureId_t id) = 0;
virtual void GetWorldSpaceCameraPosition(Vector& pPos) const = 0;
Expand Down
4 changes: 2 additions & 2 deletions shaderapivulkan/include/TF2Vulkan/IShaderShadowNext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ namespace TF2Vulkan
private:
[[deprecated]] void SetPixelShader(const char* name, int staticIndex) override final
{
NOT_IMPLEMENTED_FUNC_NOBREAK();
NOT_IMPLEMENTED_FUNC_NOBREAK(name);
}
[[deprecated]] void SetVertexShader(const char* name, int staticIndex) override final
{
NOT_IMPLEMENTED_FUNC_NOBREAK();
NOT_IMPLEMENTED_FUNC_NOBREAK(name);
}

[[deprecated]] void EnableTexture(Sampler_t sampler, bool bEnable) override final {}
Expand Down
22 changes: 22 additions & 0 deletions shaderapivulkan/include/TF2Vulkan/LogicalFogParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "TF2Vulkan/Util/std_compare.h"

namespace TF2Vulkan
{
struct FogParams final
{
constexpr FogParams() = default;

DEFAULT_PARTIAL_ORDERING_OPERATOR(FogParams);

float m_Start = 0;
float m_End = 0;
float m_Z = 0;
float m_MaxDensity = 0;
MaterialFogMode_t m_Mode = MATERIAL_FOG_NONE;
uint8_t m_ColorR = 255;
uint8_t m_ColorG = 255;
uint8_t m_ColorB = 255;
};
}
21 changes: 6 additions & 15 deletions shaderapivulkan/include/TF2Vulkan/TextureData.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
#pragma once

#include <TF2Vulkan/Util/ImageManip.h>

#include <bitmap/imageformat.h>
#include <vtf/vtf.h>
#include "TextureSubrect.h"

namespace TF2Vulkan
{
struct TextureData
struct TextureData : TextureSubrect
{
uint_fast8_t m_MipLevel = uint_fast8_t(-1);
CubeMapFaceIndex_t m_CubeFace{};
uint_fast32_t m_Width = 0;
uint_fast32_t m_Height = 0;
uint_fast32_t m_Depth = 1;

uint_fast32_t m_XOffset = 0;
uint_fast32_t m_YOffset = 0;
uint_fast32_t m_ZOffset = 0;
constexpr TextureData() = default;
constexpr TextureData(const TextureSubrect& baseRect) : TextureSubrect(baseRect) {}

ImageFormat m_Format = ImageFormat::IMAGE_FORMAT_UNKNOWN;
const void* m_Data = nullptr;

void* m_Data = nullptr;
size_t m_DataLength = 0;
size_t m_Stride = 0;
size_t m_SliceStride = 0;
Expand Down
20 changes: 20 additions & 0 deletions shaderapivulkan/include/TF2Vulkan/TextureSubrect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <bitmap/imageformat.h>
#include <vtf/vtf.h>

namespace TF2Vulkan
{
struct TextureSubrect
{
uint_fast8_t m_MipLevel = uint_fast8_t(-1);
CubeMapFaceIndex_t m_CubeFace{};
uint_fast32_t m_Width = 0;
uint_fast32_t m_Height = 0;
uint_fast32_t m_Depth = 1;

uint_fast32_t m_OffsetX = 0;
uint_fast32_t m_OffsetY = 0;
uint_fast32_t m_OffsetZ = 0;
};
}
6 changes: 4 additions & 2 deletions shaderapivulkan/shaderapivulkan.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@
<ItemGroup>
<ClInclude Include="include\TF2Vulkan\AlignedTypes.h" />
<ClInclude Include="include\TF2Vulkan\DataFormat.h" />
<ClInclude Include="include\TF2Vulkan\LogicalFogParams.h" />
<ClInclude Include="include\TF2Vulkan\IShaderGroup.h" />
<ClInclude Include="include\TF2Vulkan\IShaderNextFactory.h" />
<ClInclude Include="include\TF2Vulkan\IShaderDynamicNext.h" />
<ClInclude Include="include\TF2Vulkan\IShaderInstance.h" />
<ClInclude Include="include\TF2Vulkan\IShaderShadowNext.h" />
<ClInclude Include="include\TF2Vulkan\ISpecConstLayout.h" />
<ClInclude Include="include\TF2Vulkan\IBufferPool.h" />
<ClInclude Include="include\TF2Vulkan\TextureSubrect.h" />
<ClInclude Include="src\interface\IMaterialInternal.h" />
<ClInclude Include="src\interface\internal\IDebugTextureInfoInternal.h" />
<ClInclude Include="src\interface\internal\IMeshInternal.h" />
Expand Down Expand Up @@ -139,7 +141,7 @@
<ClInclude Include="src\interface\internal\IVulkanCommandBuffer.h" />
<ClInclude Include="src\TF2Vulkan\VulkanCommandBufferBase.h" />
<ClInclude Include="src\TF2Vulkan\VulkanFactories.h" />
<ClInclude Include="src\TF2Vulkan\VulkanMesh.h" />
<ClInclude Include="src\TF2Vulkan\meshes\VulkanMesh.h" />
<ClInclude Include="src\TF2Vulkan\VulkanUtil.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -184,7 +186,7 @@
<ClCompile Include="src\TF2Vulkan\IShaderAPI\IShaderAPI_StateManagerDynamic.cpp" />
<ClCompile Include="src\TF2Vulkan\VertexFormat.cpp" />
<ClCompile Include="src\TF2Vulkan\vk_mem_alloc.cpp" />
<ClCompile Include="src\TF2Vulkan\VulkanMesh.cpp" />
<ClCompile Include="src\TF2Vulkan\meshes\VulkanMesh.cpp" />
<ClCompile Include="src\TF2Vulkan\VulkanUtil.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
14 changes: 11 additions & 3 deletions shaderapivulkan/src/TF2Vulkan/BufferPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ BufferPoolContiguous::BufferPoolContiguous(size_t backingBufferSize, vk::BufferU
m_BackingBufferSize(backingBufferSize),
m_ElementAlignment(GetAlignment(usage)),
m_BackingBuffer(CreateBackingBuffer(usage)),
m_SliceInfo(backingBufferSize / m_ElementAlignment)
m_SliceInfo(backingBufferSize / m_ElementAlignment),
m_Mutex(std::make_unique<Util::MutexDbg>())
{
}

Expand All @@ -52,14 +53,21 @@ void BufferPoolContiguous::Update(const void* data, size_t size, size_t offset)
m_BackingBuffer.GetAllocation().Write(data, size, offset);
}

std::byte* BufferPoolContiguous::GetBufferData(size_t offset)
{
auto mapped = m_BackingBuffer.GetAllocation().data();
return mapped ? (mapped + offset) : nullptr;
}

auto BufferPoolContiguous::GetBackingBufferInfo() const -> BufferInfo
{
return BufferInfo{ m_BackingBuffer.GetBuffer(), m_BackingBufferSize };
}

BufferPoolEntry BufferPoolContiguous::Create(size_t size)
{
ASSERT_MAIN_THREAD();
std::lock_guard lock(*m_Mutex);
LOG_FUNC_ANYTHREAD();

size = ALIGN_VALUE(size, m_ElementAlignment);

Expand All @@ -76,7 +84,7 @@ BufferPoolEntry BufferPoolContiguous::Create(size_t size)
}

assert((offset + size) <= m_BackingBufferSize);
assert(ALIGN_VALUE(offset, m_ElementAlignment) == offset);
assert((offset % m_ElementAlignment) == 0);

m_SliceInfo.at(offset / m_ElementAlignment).m_Length = size;

Expand Down
3 changes: 3 additions & 0 deletions shaderapivulkan/src/TF2Vulkan/BufferPool.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "interface/internal/IBufferPoolInternal.h"
#include "TF2Vulkan/Util/MutexWrapper.h"

namespace TF2Vulkan
{
Expand All @@ -13,6 +14,7 @@ namespace TF2Vulkan
BufferInfo GetBackingBufferInfo() const override;
BufferPoolEntry Create(size_t size) override;
void Update(const void* data, size_t size, size_t offset) override;
std::byte* GetBufferData(size_t offset) override;

BufferInfo GetBufferInfo(size_t offset) const override;

Expand All @@ -29,6 +31,7 @@ namespace TF2Vulkan

vma::AllocatedBuffer CreateBackingBuffer(vk::BufferUsageFlags usage) const;
vma::AllocatedBuffer m_BackingBuffer;
std::unique_ptr<Util::MutexDbg> m_Mutex;
};

class BufferPool final : public IBufferPoolInternal
Expand Down
Loading

0 comments on commit bc125d7

Please sign in to comment.