mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
ShaderGeneration: Get rid of static buffers
This commit is contained in:
@ -27,34 +27,31 @@
|
||||
class ShaderGeneratorInterface
|
||||
{
|
||||
public:
|
||||
virtual ~ShaderGeneratorInterface()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a read pointer to the internal buffer.
|
||||
*/
|
||||
const std::string& GetBuffer() const { return m_buffer; }
|
||||
|
||||
/*
|
||||
* Used when the shader generator would write a piece of ShaderCode.
|
||||
* Can be used like printf.
|
||||
* @note In the ShaderCode implementation, this does indeed write the parameter string to an internal buffer. However, you're free to do whatever you like with the parameter.
|
||||
*/
|
||||
void Write(const char*, ...)
|
||||
virtual void Write(const char*, ...)
|
||||
#ifdef __GNUC__
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
#endif
|
||||
{}
|
||||
|
||||
/*
|
||||
* Returns a read pointer to the internal buffer.
|
||||
* @note When implementing this method in a child class, you likely want to return the argument of the last SetBuffer call here
|
||||
* @note SetBuffer() should be called before using GetBuffer().
|
||||
*/
|
||||
const char* GetBuffer() { return nullptr; }
|
||||
|
||||
/*
|
||||
* Can be used to give the object a place to write to. This should be called before using Write().
|
||||
* @param buffer pointer to a char buffer that the object can write to
|
||||
*/
|
||||
void SetBuffer(char* buffer) { }
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Tells us that a specific constant range (including last_index) is being used by the shader
|
||||
*/
|
||||
inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index) {}
|
||||
virtual void SetConstantsUsed(unsigned int first_index, unsigned int last_index) {}
|
||||
|
||||
/*
|
||||
* Returns a pointer to an internally stored object of the uid_data type.
|
||||
@ -62,6 +59,9 @@ public:
|
||||
*/
|
||||
template<class uid_data>
|
||||
uid_data* GetUidData() { return nullptr; }
|
||||
|
||||
protected:
|
||||
std::string m_buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -114,27 +114,21 @@ private:
|
||||
class ShaderCode : public ShaderGeneratorInterface
|
||||
{
|
||||
public:
|
||||
ShaderCode() : buf(nullptr), write_ptr(nullptr)
|
||||
ShaderCode()
|
||||
{
|
||||
m_buffer.reserve(16384);
|
||||
}
|
||||
|
||||
void Write(const char* fmt, ...)
|
||||
void Write(const char* fmt, ...) override
|
||||
#ifdef __GNUC__
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
#endif
|
||||
{
|
||||
va_list arglist;
|
||||
va_start(arglist, fmt);
|
||||
write_ptr += vsprintf(write_ptr, fmt, arglist);
|
||||
m_buffer += StringFromFormatV(fmt, arglist);
|
||||
va_end(arglist);
|
||||
}
|
||||
|
||||
const char* GetBuffer() { return buf; }
|
||||
void SetBuffer(char* buffer) { buf = buffer; write_ptr = buffer; }
|
||||
|
||||
private:
|
||||
const char* buf;
|
||||
char* write_ptr;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -145,13 +139,13 @@ class ShaderConstantProfile : public ShaderGeneratorInterface
|
||||
public:
|
||||
ShaderConstantProfile(int num_constants) { constant_usage.resize(num_constants); }
|
||||
|
||||
inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index)
|
||||
void SetConstantsUsed(unsigned int first_index, unsigned int last_index) override
|
||||
{
|
||||
for (unsigned int i = first_index; i < last_index + 1; ++i)
|
||||
constant_usage[i] = true;
|
||||
}
|
||||
|
||||
inline bool ConstantIsUsed(unsigned int index)
|
||||
bool ConstantIsUsed(unsigned int index) const
|
||||
{
|
||||
// TODO: Not ready for usage yet
|
||||
return true;
|
||||
@ -185,7 +179,7 @@ public:
|
||||
{
|
||||
// uid is already in the index => check if there's a shader with the same uid but different code
|
||||
auto& old_code = m_shaders[new_uid];
|
||||
if (strcmp(old_code.c_str(), new_code.GetBuffer()) != 0)
|
||||
if (old_code != new_code.GetBuffer())
|
||||
{
|
||||
static int num_failures = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user