diff options
| author | Lioncash <mathew1800@gmail.com> | 2015-12-26 16:00:23 -0500 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2015-12-26 17:01:54 -0500 |
| commit | 8ce3a4aa7014c378d4121979f3fd10b9886d38bc (patch) | |
| tree | 2b5221c8457b0ce489f165cb4cc926901ad32705 /Source/Core/VideoCommon | |
| parent | be8410dcade41f4e1d69cbdbfc46dfce9635287f (diff) | |
ShaderGeneration: Get rid of static buffers
Diffstat (limited to 'Source/Core/VideoCommon')
| -rw-r--r-- | Source/Core/VideoCommon/GeometryShaderGen.cpp | 14 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/ImageWrite.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/ImageWrite.h | 2 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/PixelShaderGen.cpp | 21 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/ShaderGenCommon.h | 52 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderGen.cpp | 16 |
6 files changed, 27 insertions, 80 deletions
diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index bf054464c2..5bb1c4906c 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -7,10 +7,8 @@ #include "VideoCommon/BPMemory.h" #include "VideoCommon/GeometryShaderGen.h" #include "VideoCommon/LightingShaderGen.h" -#include "VideoCommon/VertexShaderGen.h" #include "VideoCommon/VideoConfig.h" -static char text[16384]; static const char* primitives_ogl[] = { @@ -39,12 +37,6 @@ static inline T GenerateGeometryShader(u32 primitive_type, API_TYPE ApiType) if (uid_data == nullptr) uid_data = &dummy_data; - out.SetBuffer(text); - const bool is_writing_shadercode = (out.GetBuffer() != nullptr); - - if (is_writing_shadercode) - text[sizeof(text) - 1] = 0x7C; // canary - uid_data->primitive_type = primitive_type; const unsigned int vertex_in = primitive_type + 1; unsigned int vertex_out = primitive_type == PRIMITIVE_TRIANGLES ? 3 : 4; @@ -288,12 +280,6 @@ static inline T GenerateGeometryShader(u32 primitive_type, API_TYPE ApiType) out.Write("}\n"); - if (is_writing_shadercode) - { - if (text[sizeof(text) - 1] != 0x7C) - PanicAlert("GeometryShader generator - buffer too small, canary has been eaten!"); - } - return out; } diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp index f50c5d02b4..e8c55088c1 100644 --- a/Source/Core/VideoCommon/ImageWrite.cpp +++ b/Source/Core/VideoCommon/ImageWrite.cpp @@ -12,7 +12,7 @@ #include "Common/Logging/Log.h" #include "VideoCommon/ImageWrite.h" -bool SaveData(const std::string& filename, const char* data) +bool SaveData(const std::string& filename, const std::string& data) { std::ofstream f; OpenFStream(f, filename, std::ios::binary); diff --git a/Source/Core/VideoCommon/ImageWrite.h b/Source/Core/VideoCommon/ImageWrite.h index 730b3f7540..880d99e431 100644 --- a/Source/Core/VideoCommon/ImageWrite.h +++ b/Source/Core/VideoCommon/ImageWrite.h @@ -7,5 +7,5 @@ #include <string> #include "Common/CommonTypes.h" -bool SaveData(const std::string& filename, const char* pdata); +bool SaveData(const std::string& filename, const std::string& data); bool TextureToPng(u8* data, int row_stride, const std::string& filename, int width, int height, bool saveAlpha = true); diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 3439481da5..c647e35179 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -9,13 +9,10 @@ #include "Common/Common.h" #include "VideoCommon/BoundingBox.h" #include "VideoCommon/BPMemory.h" -#include "VideoCommon/ConstantManager.h" #include "VideoCommon/DriverDetails.h" #include "VideoCommon/LightingShaderGen.h" -#include "VideoCommon/NativeVertexFormat.h" #include "VideoCommon/PixelShaderGen.h" #include "VideoCommon/VertexLoaderManager.h" -#include "VideoCommon/VertexShaderGen.h" #include "VideoCommon/VideoConfig.h" #include "VideoCommon/XFMemory.h" // for texture projection mode @@ -157,8 +154,6 @@ static const char *tevRasTable[] = static const char *tevCOutputTable[] = { "prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb" }; static const char *tevAOutputTable[] = { "prev.a", "c0.a", "c1.a", "c2.a" }; -static char text[32768]; - template<class T> static inline void WriteStage(T& out, pixel_shader_uid_data* uid_data, int n, API_TYPE ApiType, const char swapModeTable[4][5]); template<class T> static inline void WriteTevRegular(T& out, const char* components, int bias, int op, int clamp, int shift); template<class T> static inline void SampleTexture(T& out, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType); @@ -176,12 +171,6 @@ static inline T GeneratePixelShader(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if (uid_data == nullptr) uid_data = &dummy_data; - out.SetBuffer(text); - const bool is_writing_shadercode = (out.GetBuffer() != nullptr); - - if (is_writing_shadercode) - text[sizeof(text) - 1] = 0x7C; // canary - unsigned int numStages = bpmem.genMode.numtevstages + 1; unsigned int numTexgen = bpmem.genMode.numtexgens; @@ -339,7 +328,7 @@ static inline T GeneratePixelShader(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType out.Write("[earlydepthstencil]\n"); } } - else if (bpmem.UseEarlyDepthTest() && (g_ActiveConfig.bFastDepthCalc || bpmem.alpha_test.TestResult() == AlphaTest::UNDETERMINED) && is_writing_shadercode) + else if (bpmem.UseEarlyDepthTest() && (g_ActiveConfig.bFastDepthCalc || bpmem.alpha_test.TestResult() == AlphaTest::UNDETERMINED)) { static bool warn_once = true; if (warn_once) @@ -663,12 +652,6 @@ static inline T GeneratePixelShader(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType out.Write("}\n"); - if (is_writing_shadercode) - { - if (text[sizeof(text) - 1] != 0x7C) - PanicAlert("PixelShader generator - buffer too small, canary has been eaten!"); - } - return out; } @@ -1165,7 +1148,7 @@ static inline void WriteFog(T& out, pixel_shader_uid_data* uid_data) } else { - if (bpmem.fog.c_proj_fsel.fsel != 2 && out.GetBuffer() != nullptr) + if (bpmem.fog.c_proj_fsel.fsel != 2) WARN_LOG(VIDEO, "Unknown Fog Type! %08x", bpmem.fog.c_proj_fsel.fsel); } diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index 11c4e2870e..98fde74d36 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -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; diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 9f0c1795a0..ba9fdb3493 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -5,16 +5,12 @@ #include <cmath> #include "VideoCommon/BPMemory.h" -#include "VideoCommon/CPMemory.h" -#include "VideoCommon/DriverDetails.h" #include "VideoCommon/LightingShaderGen.h" #include "VideoCommon/NativeVertexFormat.h" #include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexShaderGen.h" #include "VideoCommon/VideoConfig.h" -static char text[16768]; - template<class T> static inline T GenerateVertexShader(API_TYPE api_type) { @@ -26,12 +22,6 @@ static inline T GenerateVertexShader(API_TYPE api_type) if (uid_data == nullptr) uid_data = &dummy_data; - out.SetBuffer(text); - const bool is_writing_shadercode = (out.GetBuffer() != nullptr); - - if (is_writing_shadercode) - text[sizeof(text) - 1] = 0x7C; // canary - _assert_(bpmem.genMode.numtexgens == xfmem.numTexGen.numTexGens); _assert_(bpmem.genMode.numcolchans == xfmem.numChan.numColorChans); @@ -390,12 +380,6 @@ static inline T GenerateVertexShader(API_TYPE api_type) } out.Write("}\n"); - if (is_writing_shadercode) - { - if (text[sizeof(text) - 1] != 0x7C) - PanicAlert("VertexShader generator - buffer too small, canary has been eaten!"); - } - return out; } |
