Skip to content

Commit

Permalink
Garbage scout model rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
PazerOP committed May 23, 2019
1 parent e69ac91 commit 5c22058
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 84 deletions.
2 changes: 1 addition & 1 deletion TF2VulkanUtil/include/TF2Vulkan/Util/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 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();
NOT_IMPLEMENTED_FUNC_NOBREAK();
}
[[deprecated]] void SetVertexShader(const char* name, int staticIndex) override final
{
NOT_IMPLEMENTED_FUNC();
NOT_IMPLEMENTED_FUNC_NOBREAK();
}

[[deprecated]] void EnableTexture(Sampler_t sampler, bool bEnable) override final {}
Expand Down
1 change: 1 addition & 0 deletions shaderapivulkan/include/TF2Vulkan/VertexFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace TF2Vulkan

union VertexFormat
{
constexpr explicit VertexFormat(VertexFormatFlags flags) : m_BaseFmt(VertexFormat_t(flags)) {}
constexpr explicit VertexFormat(VertexFormat_t baseFmt = VERTEX_FORMAT_UNKNOWN) :
m_BaseFmt(baseFmt)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

using namespace TF2Vulkan;

IShaderAPI_MeshManager::IShaderAPI_MeshManager() :
m_FlexMesh(VertexFormat(VertexFormatFlags::Position | VertexFormatFlags::Normal | VertexFormatFlags::Wrinkle), true)
{

}

int IShaderAPI_MeshManager::GetMaxVerticesToRender(IMaterial* material)
{
LOG_FUNC();
Expand Down Expand Up @@ -32,6 +38,11 @@ int IShaderAPI_MeshManager::GetMaxIndicesToRender()
return INDEX_BUFFER_SIZE;
}

IMesh* IShaderAPI_MeshManager::GetFlexMesh()
{
return &m_FlexMesh;
}

int IShaderAPI_MeshManager::GetCurrentDynamicVBSize()
{
LOG_FUNC();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ namespace TF2Vulkan
class IShaderAPI_MeshManager : public IShaderAPI_TextureManager
{
public:
IShaderAPI_MeshManager();

void GetMaxToRender(IMesh* mesh, bool maxUntilFlush, int* maxVerts, int* maxIndices) override final { NOT_IMPLEMENTED_FUNC(); }

int GetMaxVerticesToRender(IMaterial* material) override final;
int GetMaxIndicesToRender() override final;

IMesh* GetFlexMesh() override final { NOT_IMPLEMENTED_FUNC(); }
IMesh* GetFlexMesh() override final;

int GetCurrentDynamicVBSize() override final;
void DestroyVertexBuffers(bool exitingLevel) override final { NOT_IMPLEMENTED_FUNC(); }
Expand All @@ -31,6 +33,7 @@ namespace TF2Vulkan

private:
std::unordered_map<VertexFormat, VulkanMesh> m_DynamicMeshes;
VulkanMesh m_FlexMesh;

CMeshBuilder m_MeshBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,40 @@ void IShaderAPI_StateManagerDynamic::SetStencilWriteMask(uint32 mask)
LOG_FUNC();
Util::SetDirtyVar(m_State.m_StencilWriteMask, mask, m_Dirty);
}

void IShaderAPI_StateManagerDynamic::SetScissorRect(const int left, const int top,
const int right, const int bottom, const bool enableScissor)
{
LOG_FUNC();

Util::SetDirtyVar(m_State.m_ScissorEnable, enableScissor, m_Dirty);
if (enableScissor)
{
Util::SetDirtyVar(m_State.m_ScissorX, left, m_Dirty);
Util::SetDirtyVar(m_State.m_ScissorY, top, m_Dirty);
Util::SetDirtyVar(m_State.m_ScissorWidth, right - left, m_Dirty);
Util::SetDirtyVar(m_State.m_ScissorHeight, bottom - top, m_Dirty);
}
}

void IShaderAPI_StateManagerDynamic::SetClipPlane(int index, const float* plane)
{
NOT_IMPLEMENTED_FUNC_NOBREAK();
}

void IShaderAPI_StateManagerDynamic::EnableClipPlane(int index, bool enable)
{
NOT_IMPLEMENTED_FUNC_NOBREAK();
}

void IShaderAPI_StateManagerDynamic::LoadBoneMatrix(int boneIndex, const float* m)
{
LOG_FUNC();
return LoadBoneMatrix(Util::SafeConvert<uint32_t>(boneIndex), *reinterpret_cast<const matrix3x4_t*>(m));
}

void IShaderAPI_StateManagerDynamic::LoadBoneMatrix(uint32_t boneIndex, const matrix3x4_t& matrix)
{
LOG_FUNC();
Util::SetDirtyVar(m_State.m_BoneMatrices, boneIndex, matrix, m_Dirty);
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ namespace TF2Vulkan
void SetStencilTestMask(uint32 mask) override final;
void SetStencilWriteMask(uint32 mask) override final;

void SetScissorRect(const int left, const int top, const int right, const int bottom,
const bool enableScissor) override final;

void SetClipPlane(int index, const float* plane) override final;
void EnableClipPlane(int index, bool enable) override final;

void FogStart(float start) override final { NOT_IMPLEMENTED_FUNC(); }
void FogEnd(float end) override final { NOT_IMPLEMENTED_FUNC(); }
void SetFogZ(float fogZ) override final { NOT_IMPLEMENTED_FUNC(); }
Expand Down Expand Up @@ -147,6 +153,9 @@ namespace TF2Vulkan
// Helpers
void SetOverbright(float overbright);

[[deprecated]] void LoadBoneMatrix(int boneIndex, const float* m) override final;
void LoadBoneMatrix(uint32_t boneIndex, const matrix3x4_t& m);

const LogicalDynamicState& GetDynamicState() const { return m_State; }

private:
Expand Down
10 changes: 2 additions & 8 deletions shaderapivulkan/src/TF2Vulkan/IShaderAPI/ShaderAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ namespace
void SetHeightClipZ(float z) override { NOT_IMPLEMENTED_FUNC(); }
void SetHeightClipMode(MaterialHeightClipMode_t mode) override { NOT_IMPLEMENTED_FUNC(); }

void SetClipPlane(int index, const float* plane) override { NOT_IMPLEMENTED_FUNC(); }
void EnableClipPlane(int index, bool enable) override { NOT_IMPLEMENTED_FUNC(); }

ImageFormat GetNearestSupportedFormat(ImageFormat fmt, bool filteringRequired) const override;
ImageFormat GetNearestRenderTargetFormat(ImageFormat fmt) const override;

Expand Down Expand Up @@ -207,9 +204,6 @@ namespace

void PerformFullScreenStencilOperation() override { NOT_IMPLEMENTED_FUNC(); }

void SetScissorRect(const int left, const int top, const int right, const int bottom,
const bool enableScissor) override { NOT_IMPLEMENTED_FUNC(); }

bool SupportsCSAAMode(int numSamples, int qualityLevel) override { NOT_IMPLEMENTED_FUNC(); }

void InvalidateDelayedShaderConstants() override;
Expand Down Expand Up @@ -247,8 +241,6 @@ namespace

ITexture* GetRenderTargetEx(int renderTargetID) override;

void LoadBoneMatrix(int boneIndex, const float* m) override { NOT_IMPLEMENTED_FUNC(); }

void GetDXLevelDefaults(uint& dxLevelMax, uint& dxLevelRecommended) override { NOT_IMPLEMENTED_FUNC(); }

float GetAmbientLightCubeLuminance() override { NOT_IMPLEMENTED_FUNC(); }
Expand Down Expand Up @@ -277,6 +269,8 @@ namespace
private:
mutable std::recursive_mutex m_ShaderLock;

std::array<matrix3x4_t, 53> m_BoneMatrices;

bool m_IsInFrame = false;
ShaderAPITextureHandle_t m_L2GConvTex_SRGBWriteEnabled = INVALID_SHADERAPI_TEXTURE_HANDLE;
ShaderAPITextureHandle_t m_L2GConvTex_Identity = INVALID_SHADERAPI_TEXTURE_HANDLE;
Expand Down
12 changes: 12 additions & 0 deletions shaderapivulkan/src/TF2Vulkan/LogicalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ namespace TF2Vulkan

std::array<BufferPoolEntry, 8> m_UniformBuffers = {};

// Scissor settings
bool m_ScissorEnable = false;
int m_ScissorX = -1;
int m_ScissorY = -1;
int m_ScissorWidth = -1;
int m_ScissorHeight = -1;

// Stencil settings
bool m_StencilEnable = false;
StencilOperation_t m_StencilFailOp = STENCILOPERATION_KEEP;
Expand All @@ -72,6 +79,8 @@ namespace TF2Vulkan

std::array<ShaderAPITextureHandle_t, 16> m_BoundTextures{};

std::array<matrix3x4_t, 53> m_BoneMatrices{};

bool m_UserClipTransformOverrideEnabled = false;
VMatrix m_UserClipTransformOverride{};
};
Expand All @@ -89,6 +98,9 @@ namespace TF2Vulkan
bool m_SRGBRead = false;
};

bool m_FSAlphaToCoverage = false;
bool m_FSFogGammaCorrection = true;

// Vertex shader settings
const IShaderGroupInternal* m_VSShader = nullptr;
VertexFormat m_VSVertexFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ int MaterialSystemHardwareConfig::MaxVertexShaderBlendMatrices() const

int MaterialSystemHardwareConfig::MaxUserClipPlanes() const
{
NOT_IMPLEMENTED_FUNC();
return 0;
LOG_FUNC();
return GetLimits().maxClipDistances; // TODO: Is this the same thing as user clip planes
}

bool MaterialSystemHardwareConfig::UseFastClipping() const
{
NOT_IMPLEMENTED_FUNC();
NOT_IMPLEMENTED_FUNC_NOBREAK();
return false;
}

Expand Down
57 changes: 7 additions & 50 deletions shaderapivulkan/src/TF2Vulkan/ResourceBlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,37 @@

using namespace TF2Vulkan;

struct ResourceBlob::BufferNode : IResource
{
vk::UniqueBuffer m_Buffer;
};
struct ResourceBlob::ImageNode : IResource
{
vk::UniqueImage m_Image;
};
struct ResourceBlob::ImageViewNode : IResource
{
vk::UniqueImageView m_ImageView;
};
struct ResourceBlob::AllocatedBufferNode : IResource
{
vma::AllocatedBuffer m_Buffer;
};
struct ResourceBlob::AllocatedImageNode : IResource
{
vma::AllocatedImage m_Image;
};
struct ResourceBlob::DescriptorSetNode : IResource
{
vk::UniqueDescriptorSet m_DescriptorSet;
};

void ResourceBlob::AddResource(vk::UniqueBuffer&& buffer)
{
auto newNode = std::make_unique<BufferNode>();
newNode->m_Buffer = std::move(buffer);
AddResource(std::move(newNode));
m_Resources.emplace_back(std::move(buffer));
}

void ResourceBlob::AddResource(vk::UniqueImage&& image)
{
auto newNode = std::make_unique<ImageNode>();
newNode->m_Image = std::move(image);
AddResource(std::move(newNode));
m_Resources.emplace_back(std::move(image));
}

void ResourceBlob::AddResource(vk::UniqueImageView&& imageView)
{
auto newNode = std::make_unique<ImageViewNode>();
newNode->m_ImageView = std::move(imageView);
AddResource(std::move(newNode));
m_Resources.emplace_back(std::move(imageView));
}

void ResourceBlob::AddResource(vma::AllocatedBuffer&& buffer)
{
auto newNode = std::make_unique<AllocatedBufferNode>();
newNode->m_Buffer = std::move(buffer);
AddResource(std::move(newNode));
m_Resources.emplace_back(std::move(buffer));
}

void ResourceBlob::AddResource(vma::AllocatedImage&& image)
{
auto newNode = std::make_unique<AllocatedImageNode>();
newNode->m_Image = std::move(image);
AddResource(std::move(newNode));
m_Resources.emplace_back(std::move(image));
}

void ResourceBlob::AddResource(vk::UniqueDescriptorSet&& descriptorSet)
{
auto newNode = std::make_unique<DescriptorSetNode>();
newNode->m_DescriptorSet = std::move(descriptorSet);
AddResource(std::move(newNode));
m_Resources.emplace_back(std::move(descriptorSet));
}

void ResourceBlob::ReleaseAttachedResources()
{
m_FirstNode.reset();
}

void ResourceBlob::AddResource(std::unique_ptr<IResource>&& node)
{
node->m_Next = std::move(m_FirstNode);
m_FirstNode = std::move(node);
m_Resources.clear();
}
21 changes: 11 additions & 10 deletions shaderapivulkan/src/TF2Vulkan/ResourceBlob.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <variant>

namespace TF2Vulkan
{
class ResourceBlob
Expand All @@ -23,21 +25,20 @@ namespace TF2Vulkan
void ReleaseAttachedResources();

private:
struct BufferNode;
struct ImageNode;
struct ImageViewNode;
struct AllocatedBufferNode;
struct AllocatedImageNode;
struct DescriptorSetNode;

struct IResource
{
virtual ~IResource() = default;
std::unique_ptr<IResource> m_Next;
};

void AddResource(std::unique_ptr<IResource>&& node);
using ResourceTypes = std::variant<
std::unique_ptr<IResource>,
vk::UniqueBuffer,
vk::UniqueImage,
vk::UniqueImageView,
vma::AllocatedBuffer,
vma::AllocatedImage,
vk::UniqueDescriptorSet>;

std::unique_ptr<IResource> m_FirstNode;
std::vector<ResourceTypes> m_Resources;
};
}
4 changes: 2 additions & 2 deletions shaderapivulkan/src/TF2Vulkan/ShaderDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ void ShaderDevice::Present()
std::numeric_limits<uint64_t>::max(), curImg.m_ImageAvailableSemaphore.get(),
nullptr);

#pragma warning(suppress : 4996)
//#pragma warning(suppress : 4996)
auto& primaryCmdBuf = *curImg.m_PrimaryCmdBuf;
primaryCmdBuf.endRenderPass();
primaryCmdBuf.TryEndRenderPass();

// Prepare swapchain for presentation
TransitionImageLayout(curImg.m_Image, scData.m_SwapChainCreateInfo.imageFormat,
Expand Down
6 changes: 4 additions & 2 deletions shaderapivulkan/src/TF2Vulkan/StateManagerStatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,14 @@ void ShadowStateManager::SetMorphFormat(MorphFormat_t format)

void ShadowStateManager::DisableFogGammaCorrection(bool disable)
{
NOT_IMPLEMENTED_FUNC();
LOG_FUNC();
Util::SetDirtyVar(m_State.m_FSFogGammaCorrection, !disable, m_Dirty);
}

void ShadowStateManager::EnableAlphaToCoverage(bool enable)
{
NOT_IMPLEMENTED_FUNC();
LOG_FUNC();
Util::SetDirtyVar(m_State.m_FSAlphaToCoverage, enable, m_Dirty);
}

void ShadowStateManager::SetShadowDepthFiltering(Sampler_t stage)
Expand Down
Loading

0 comments on commit 5c22058

Please sign in to comment.