forked from PazerOP/TF2Vulkan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
About to switch shader constant buffer organization
- Loading branch information
Showing
38 changed files
with
818 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include <string_view> | ||
|
||
namespace Util | ||
{ | ||
// Can't use stringstream due to linking issues | ||
template<size_t bufSize, typename TChar = char> | ||
class CStringBuilder | ||
{ | ||
public: | ||
CStringBuilder(const std::basic_string_view<TChar>& initialValue = {}) | ||
{ | ||
Append(initialValue); | ||
} | ||
|
||
const TChar* c_str() | ||
{ | ||
if (m_Length >= bufSize) | ||
throw std::overflow_error("Ran out of space when trying to add null terminator"); | ||
|
||
m_Buffer[m_Length] = '\0'; | ||
return m_Buffer; | ||
} | ||
|
||
std::basic_string_view<TChar> GetBuffer() const { return std::basic_string_view<TChar>(m_Buffer, m_Length); } | ||
|
||
void Append(const std::basic_string_view<TChar>& sv) | ||
{ | ||
memcpy_s(&m_Buffer[m_Length], sizeof(TChar) * (bufSize - m_Length), sv.data(), sizeof(TChar) * sv.size()); | ||
m_Length += sv.size(); | ||
} | ||
|
||
template<typename... TArgs> | ||
__declspec(noinline) void AppendF(const char* fmt, const TArgs& ... args) | ||
{ | ||
auto written = sprintf_s(&m_Buffer[m_Length], bufSize - m_Length, fmt, args...); | ||
if (written > 0) | ||
m_Length += written; | ||
} | ||
|
||
private: | ||
TChar m_Buffer[bufSize]; | ||
size_t m_Length = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <string_view> | ||
|
||
#include "std_compare.h" | ||
|
||
#ifndef __INTELLISENSE__ | ||
template<typename TChar, typename TTraits> | ||
inline std::strong_ordering operator<=>(const std::basic_string_view<TChar, TTraits>& lhs, const std::basic_string_view<TChar, TTraits>& rhs) | ||
{ | ||
if (lhs < rhs) | ||
return std::strong_ordering::less; | ||
else if (rhs < lhs) | ||
return std::strong_ordering::greater; | ||
else | ||
return std::strong_ordering::equal; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
101 changes: 101 additions & 0 deletions
101
shaderapivulkan/include/TF2Vulkan/ShaderResourceBinder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#pragma once | ||
|
||
#include "AlignedTypes.h" | ||
#include "TF2Vulkan/SamplerSettings.h" | ||
#include "TF2Vulkan/Util/InPlaceVector.h" | ||
#include "TF2Vulkan/Util/SafeConvert.h" | ||
|
||
#include <materialsystem/itexture.h> | ||
#include <vtf/vtf.h> | ||
|
||
namespace TF2Vulkan | ||
{ | ||
static constexpr size_t MAX_SHADER_RESOURCE_BINDINGS = 32; | ||
|
||
class ShaderTextureBinder final | ||
{ | ||
public: | ||
void AddBinding(ITexture& texture, int32_t& texLocationSpecConst, uint32_t& smpLocationSpecConst, | ||
const SamplerSettings* sampler = nullptr); | ||
|
||
const auto& GetTextures() const { return m_Textures; } | ||
const auto& GetSamplers() const { return m_Samplers; } | ||
|
||
private: | ||
int32_t FindOrInsertTexture(ITexture& texture); | ||
uint32_t FindOrInsertSampler(const SamplerSettings& sampler); | ||
static SamplerSettings SamplerFromTexture(const ITexture& texture); | ||
|
||
Util::InPlaceVector<ITexture*, MAX_SHADER_RESOURCE_BINDINGS> m_Textures; | ||
Util::InPlaceVector<SamplerSettings, MAX_SHADER_RESOURCE_BINDINGS> m_Samplers; | ||
}; | ||
|
||
inline void ShaderTextureBinder::AddBinding(ITexture& texture, int32_t& texLocationSpecConst, | ||
uint32_t& smpLocationSpecConst, const SamplerSettings* sampler) | ||
{ | ||
texLocationSpecConst = FindOrInsertTexture(texture); | ||
smpLocationSpecConst = FindOrInsertSampler(sampler ? *sampler : SamplerFromTexture(texture)); | ||
} | ||
|
||
inline int32_t ShaderTextureBinder::FindOrInsertTexture(ITexture& texture) | ||
{ | ||
for (size_t i = 0; i < m_Textures.size(); i++) | ||
{ | ||
if (m_Textures[i] == &texture) | ||
return Util::SafeConvert<int32_t>(i); | ||
} | ||
|
||
m_Textures.emplace_back(&texture); | ||
return Util::SafeConvert<int32_t>(m_Textures.size() - 1); | ||
} | ||
|
||
inline uint32_t ShaderTextureBinder::FindOrInsertSampler(const SamplerSettings& sampler) | ||
{ | ||
for (uint32_t i = 0; i < m_Samplers.size(); i++) | ||
{ | ||
if (m_Samplers[i] == sampler) | ||
return i; | ||
} | ||
|
||
m_Samplers.emplace_back(sampler); | ||
return m_Samplers.size() - 1; | ||
} | ||
|
||
inline SamplerSettings ShaderTextureBinder::SamplerFromTexture(const ITexture& tex) | ||
{ | ||
const auto flags = tex.GetFlags(); | ||
|
||
SamplerSettings retVal; | ||
|
||
// This code relies on the constructor for SamplerSettings initializing | ||
// these to SHADER_TEXWRAPMODE_REPEAT | ||
assert(retVal.m_WrapS == SHADER_TEXWRAPMODE_REPEAT); | ||
assert(retVal.m_WrapT == SHADER_TEXWRAPMODE_REPEAT); | ||
assert(retVal.m_WrapU == SHADER_TEXWRAPMODE_REPEAT); | ||
|
||
if (flags & TEXTUREFLAGS_CLAMPS) | ||
retVal.m_WrapS = SHADER_TEXWRAPMODE_CLAMP; | ||
if ((flags & TEXTUREFLAGS_CLAMPT) && tex.GetActualHeight() > 1) | ||
retVal.m_WrapT = SHADER_TEXWRAPMODE_CLAMP; | ||
if ((flags & TEXTUREFLAGS_CLAMPU) && tex.GetActualDepth() > 1) | ||
retVal.m_WrapU = SHADER_TEXWRAPMODE_CLAMP; | ||
|
||
if (flags & TEXTUREFLAGS_POINTSAMPLE) | ||
{ | ||
retVal.m_MinFilter = retVal.m_MagFilter = | ||
SHADER_TEXFILTERMODE_NEAREST; | ||
} | ||
else if (flags & TEXTUREFLAGS_TRILINEAR) | ||
{ | ||
retVal.m_MinFilter = retVal.m_MagFilter = | ||
SHADER_TEXFILTERMODE_LINEAR_MIPMAP_LINEAR; | ||
} | ||
else if (flags & TEXTUREFLAGS_ANISOTROPIC) | ||
{ | ||
retVal.m_MinFilter = retVal.m_MagFilter = | ||
SHADER_TEXFILTERMODE_ANISOTROPIC; | ||
} | ||
|
||
return retVal; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.