Merge remote-tracking branch 'gzdoom/master' into lightmaps2

This commit is contained in:
Magnus Norddahl 2021-11-04 23:59:00 +01:00
commit 5dec391c8c
294 changed files with 1077 additions and 1031 deletions

View file

@ -76,16 +76,20 @@ void GLBuffer::Bind()
}
void GLBuffer::SetData(size_t size, const void *data, bool staticdata)
void GLBuffer::SetData(size_t size, const void *data, BufferUsageType usage)
{
Bind();
if (data != nullptr)
if (usage == BufferUsageType::Static)
{
glBufferData(mUseType, size, data, staticdata? GL_STATIC_DRAW : GL_STREAM_DRAW);
glBufferData(mUseType, size, data, GL_STATIC_DRAW);
}
else
else if (usage == BufferUsageType::Stream)
{
mPersistent = screen->BuffersArePersistent() && !staticdata;
glBufferData(mUseType, size, data, GL_STREAM_DRAW);
}
else if (usage == BufferUsageType::Persistent)
{
mPersistent = screen->BuffersArePersistent();
if (mPersistent)
{
glBufferStorage(mUseType, size, nullptr, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
@ -93,10 +97,15 @@ void GLBuffer::SetData(size_t size, const void *data, bool staticdata)
}
else
{
glBufferData(mUseType, size, nullptr, staticdata ? GL_STATIC_DRAW : GL_STREAM_DRAW);
glBufferData(mUseType, size, nullptr, GL_STREAM_DRAW);
map = nullptr;
}
if (!staticdata) nomap = false;
nomap = false;
}
else if (usage == BufferUsageType::Mappable)
{
glBufferData(mUseType, size, nullptr, GL_STATIC_DRAW);
map = nullptr;
}
buffersize = size;
InvalidateBufferState();
@ -134,7 +143,7 @@ void GLBuffer::Unmap()
void *GLBuffer::Lock(unsigned int size)
{
// This initializes this buffer as a static object with no data.
SetData(size, nullptr, true);
SetData(size, nullptr, BufferUsageType::Mappable);
return glMapBufferRange(mUseType, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
}
@ -158,7 +167,7 @@ void GLBuffer::Resize(size_t newsize)
glUnmapBuffer(mUseType);
glGenBuffers(1, &mBufferId);
SetData(newsize, nullptr, false);
SetData(newsize, nullptr, BufferUsageType::Persistent);
glBindBuffer(GL_COPY_READ_BUFFER, oldbuffer);
// copy contents and delete the old buffer.

View file

@ -24,7 +24,7 @@ protected:
GLBuffer(int usetype);
~GLBuffer();
void SetData(size_t size, const void *data, bool staticdata) override;
void SetData(size_t size, const void *data, BufferUsageType usage) override;
void SetSubData(size_t offset, size_t size, const void *data) override;
void Map() override;
void Unmap() override;

View file

@ -19,7 +19,7 @@
** 3. This notice may not be removed or altered from any source distribution.
*/
#include "templates.h"
#include "gl_system.h"
#include "gl_debug.h"
#include "stats.h"

View file

@ -36,7 +36,7 @@
#include "gl_system.h"
#include "v_video.h"
#include "m_png.h"
#include "templates.h"
#include "i_time.h"
#include "gl_interface.h"

View file

@ -34,7 +34,7 @@
*/
#include "gl_system.h"
#include "templates.h"
#include "c_cvars.h"
#include "hw_material.h"

View file

@ -33,7 +33,7 @@
#include "flatvertices.h"
#include "r_videoscale.h"
#include "v_video.h"
#include "templates.h"
#include "hw_vrmodes.h"
#include "v_draw.h"

View file

@ -19,7 +19,7 @@
** 3. This notice may not be removed or altered from any source distribution.
*/
#include "templates.h"
#include "gl_system.h"
#include "gl_interface.h"
#include "gl_postprocessstate.h"

View file

@ -30,7 +30,7 @@
#include "gl_postprocessstate.h"
#include "gl_shaderprogram.h"
#include "gl_buffers.h"
#include "templates.h"
#include <random>
EXTERN_CVAR(Int, gl_debug_level)
@ -952,7 +952,7 @@ void GLPPRenderState::Draw()
{
if (!shader->Uniforms)
shader->Uniforms.reset(screen->CreateDataBuffer(POSTPROCESS_BINDINGPOINT, false, false));
shader->Uniforms->SetData(Uniforms.Data.Size(), Uniforms.Data.Data());
shader->Uniforms->SetData(Uniforms.Data.Size(), Uniforms.Data.Data(), BufferUsageType::Static);
static_cast<GLDataBuffer*>(shader->Uniforms.get())->BindBase();
}

View file

@ -25,7 +25,7 @@
**
*/
#include "templates.h"
#include "gl_system.h"
#include "gl_interface.h"
#include "hw_cvars.h"

View file

@ -107,7 +107,7 @@ public:
void EnableDrawBuffers(int count, bool apply = false) override
{
count = std::min(count, 3);
count = min(count, 3);
if (mNumDrawBuffers != count)
{
static GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };

View file

@ -263,7 +263,7 @@ FString FShaderProgram::PatchShader(ShaderType type, const FString &code, const
// If we have 4.2, always use it because it adds important new syntax.
if (maxGlslVersion < 420 && gl.glslversion >= 4.2f) maxGlslVersion = 420;
int shaderVersion = std::min((int)round(gl.glslversion * 10) * 10, maxGlslVersion);
int shaderVersion = min((int)round(gl.glslversion * 10) * 10, maxGlslVersion);
patchedCode.AppendFormat("#version %d\n", shaderVersion);
// TODO: Find some way to add extension requirements to the patching

View file

@ -34,7 +34,7 @@
#include "gl_framebuffer.h"
#include "gl_shaderprogram.h"
#include "gl_buffers.h"
#include "templates.h"
EXTERN_CVAR(Int, vr_mode)
EXTERN_CVAR(Float, vid_saturation)

View file

@ -93,8 +93,9 @@ void GLBuffer::Bind()
}
void GLBuffer::SetData(size_t size, const void* data, bool staticdata)
void GLBuffer::SetData(size_t size, const void* data, BufferUsageType usage)
{
bool staticdata = (usage == BufferUsageType::Static || usage == BufferUsageType::Mappable);
if (isData || !gles.useMappedBuffers)
{
if (memory)
@ -175,7 +176,7 @@ void GLBuffer::Unmap()
void *GLBuffer::Lock(unsigned int size)
{
// This initializes this buffer as a static object with no data.
SetData(size, nullptr, true);
SetData(size, nullptr, BufferUsageType::Mappable);
if (!isData && gles.useMappedBuffers)
{
return glMapBufferRange(mUseType, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);

View file

@ -26,7 +26,7 @@ protected:
GLBuffer(int usetype);
~GLBuffer();
void SetData(size_t size, const void *data, bool staticdata) override;
void SetData(size_t size, const void *data, BufferUsageType usage) override;
void SetSubData(size_t offset, size_t size, const void *data) override;
void Map() override;
void Unmap() override;

View file

@ -36,7 +36,7 @@
#include "gles_system.h"
#include "v_video.h"
#include "m_png.h"
#include "templates.h"
#include "i_time.h"
#include "gles_framebuffer.h"
@ -122,7 +122,7 @@ void OpenGLFrameBuffer::InitializeState()
{
static bool first=true;
mPipelineNbr = gl_pipeline_depth == 0? std::min(4, HW_MAX_PIPELINE_BUFFERS) : clamp(*gl_pipeline_depth, 1, HW_MAX_PIPELINE_BUFFERS);
mPipelineNbr = gl_pipeline_depth == 0? min(4, HW_MAX_PIPELINE_BUFFERS) : clamp(*gl_pipeline_depth, 1, HW_MAX_PIPELINE_BUFFERS);
mPipelineType = 1;
InitGLES();

View file

@ -34,7 +34,7 @@
*/
#include "gles_system.h"
#include "templates.h"
#include "c_cvars.h"
#include "hw_material.h"

View file

@ -32,7 +32,7 @@
#include "flatvertices.h"
#include "r_videoscale.h"
#include "v_video.h"
#include "templates.h"
#include "hw_vrmodes.h"
#include "v_draw.h"
@ -159,7 +159,7 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma)
mPresentShader->Uniforms.SetData();
for (int n = 0; n < mPresentShader->Uniforms.mFields.size(); n++)
for (size_t n = 0; n < mPresentShader->Uniforms.mFields.size(); n++)
{
int index = -1;
UniformFieldDesc desc = mPresentShader->Uniforms.mFields[n];
@ -175,6 +175,8 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma)
case UniformType::Vec2:
glUniform2fv(loc,1 , ((GLfloat*)(((char*)(&mPresentShader->Uniforms)) + desc.Offset)));
break;
default:
break;
}
}

View file

@ -19,7 +19,7 @@
** 3. This notice may not be removed or altered from any source distribution.
*/
#include "templates.h"
#include "gles_system.h"
#include "gles_postprocessstate.h"

View file

@ -28,7 +28,7 @@
#include "gles_postprocessstate.h"
#include "gles_shaderprogram.h"
#include "gles_buffers.h"
#include "templates.h"
#include <random>
EXTERN_CVAR(Int, gl_debug_level)

View file

@ -25,7 +25,7 @@
**
*/
#include "templates.h"
#include "gles_system.h"
#include "hw_cvars.h"
#include "flatvertices.h"
@ -35,6 +35,9 @@
#include "gles_renderbuffers.h"
#include "gles_hwtexture.h"
#include "gles_buffers.h"
#include "gles_renderer.h"
#include "gles_samplers.h"
#include "hw_clock.h"
#include "printf.h"
@ -116,13 +119,13 @@ bool FGLRenderState::ApplyShader()
addLights = (int(lightPtr[3]) - int(lightPtr[2])) / LIGHT_VEC4_NUM;
// Here we limit the number of lights, but dont' change the light data so priority has to be mod, sub then add
if (modLights > gles.maxlights)
if (modLights > (int)gles.maxlights)
modLights = gles.maxlights;
if (modLights + subLights > gles.maxlights)
if (modLights + subLights > (int)gles.maxlights)
subLights = gles.maxlights - modLights;
if (modLights + subLights + addLights > gles.maxlights)
if (modLights + subLights + addLights > (int)gles.maxlights)
addLights = gles.maxlights - modLights - subLights;
totalLights = modLights + subLights + addLights;
@ -332,7 +335,7 @@ bool FGLRenderState::ApplyShader()
// Calculate the total number of vec4s we need
int totalVectors = totalLights * LIGHT_VEC4_NUM;
if (totalVectors > gles.numlightvectors)
if (totalVectors > (int)gles.numlightvectors)
totalVectors = gles.numlightvectors;
glUniform4fv(activeShader->cur->lights_index, totalVectors, lightPtr);
@ -479,6 +482,7 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio
for (int i = 1; i < 3; i++)
{
auto systex = static_cast<FHardwareTexture*>(mat->GetLayer(i, translation, &layer));
GLRenderer->mSamplerManager->Bind(i, CLAMP_NONE, 255);
systex->Bind(i, false);
maxbound = i;
}
@ -720,10 +724,13 @@ void FGLRenderState::ClearScreen()
bool FGLRenderState::SetDepthClamp(bool on)
{
bool res = mLastDepthClamp;
/*
if (!on) glDisable(GL_DEPTH_CLAMP);
else glEnable(GL_DEPTH_CLAMP);
*/
if (gles.depthClampAvailable)
{
if (!on) glDisable(GL_DEPTH_CLAMP);
else glEnable(GL_DEPTH_CLAMP);
}
mLastDepthClamp = on;
return res;
}

View file

@ -109,7 +109,7 @@ public:
void EnableDrawBuffers(int count, bool apply = false) override
{
/*
count = std::min(count, 3);
count = min(count, 3);
if (mNumDrawBuffers != count)
{
static GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };

View file

@ -119,8 +119,26 @@ uint8_t FSamplerManager::Bind(int texunit, int num, int lastval)
break;
case CLAMP_NOFILTER:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
break;
case CLAMP_NOFILTER_X:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
break;
case CLAMP_NOFILTER_Y:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
break;
case CLAMP_NOFILTER_XY:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

View file

@ -272,7 +272,7 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program
Uniforms.UniformLocation.resize(Uniforms.mFields.size());
for (int n = 0; n < Uniforms.mFields.size(); n++)
for (size_t n = 0; n < Uniforms.mFields.size(); n++)
{
int index = -1;
UniformFieldDesc desc = Uniforms.mFields[n];

View file

@ -88,7 +88,7 @@ public:
void SetData()
{
if (mBuffer != nullptr)
mBuffer->SetData(sizeof(T), &Values);
mBuffer->SetData(sizeof(T), &Values, BufferUsageType::Static);
}
IDataBuffer* GetBuffer() const

View file

@ -62,7 +62,6 @@ static PROC(WINAPI* getprocaddress)(LPCSTR name);
static void* LoadGLES2Proc(const char* name)
{
HINSTANCE hGetProcIDDLL = LoadLibraryA("libGLESv2.dll");
int error = GetLastError();
@ -71,6 +70,7 @@ static void* LoadGLES2Proc(const char* name)
if (!addr)
{
//exit(1);
return nullptr;
}
else
{
@ -182,10 +182,12 @@ namespace OpenGLESRenderer
#if USE_GLES2
gles.depthStencilAvailable = CheckExtension("GL_OES_packed_depth_stencil");
gles.npotAvailable = CheckExtension("GL_OES_texture_npot");
gles.depthClampAvailable = CheckExtension("GL_EXT_depth_clamp");
#else
gles.depthStencilAvailable = true;
gles.npotAvailable = true;
gles.useMappedBuffers = true;
gles.depthClampAvailable = true;
#endif
gles.numlightvectors = (gles.maxlights * LIGHT_VEC4_NUM);

View file

@ -42,6 +42,7 @@ GLAPI PFNGLUNMAPBUFFEROESPROC glUnmapBuffer;
#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020
#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
#define GL_BGRA 0x80E1
#define GL_DEPTH_CLAMP 0x864F
#else
#include "gl_load/gl_load.h"
@ -69,6 +70,7 @@ namespace OpenGLESRenderer
bool depthStencilAvailable;
bool npotAvailable;
bool forceGLSLv100;
bool depthClampAvailable;
int max_texturesize;
char* vendorstring;
char* modelstring;

View file

@ -47,6 +47,14 @@ struct FVertexBufferAttribute
int offset;
};
enum class BufferUsageType
{
Static, // initial data is not null, staticdata is true
Stream, // initial data is not null, staticdata is false
Persistent, // initial data is null, staticdata is false
Mappable // initial data is null, staticdata is true
};
class IBuffer
{
protected:
@ -58,7 +66,7 @@ public:
IBuffer &operator=(const IBuffer &) = delete;
virtual ~IBuffer() = default;
virtual void SetData(size_t size, const void *data, bool staticdata = true) = 0;
virtual void SetData(size_t size, const void *data, BufferUsageType type) = 0;
virtual void SetSubData(size_t offset, size_t size, const void *data) = 0;
virtual void *Lock(unsigned int size) = 0;
virtual void Unlock() = 0;

View file

@ -81,7 +81,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height, int pipelineNbr):
mIndexBuffer = screen->CreateIndexBuffer();
int data[4] = {};
mIndexBuffer->SetData(4, data); // On Vulkan this may not be empty, so set some dummy defaults to avoid crashes.
mIndexBuffer->SetData(4, data, BufferUsageType::Static); // On Vulkan this may not be empty, so set some dummy defaults to avoid crashes.
for (int n = 0; n < mPipelineNbr; n++)
@ -89,7 +89,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height, int pipelineNbr):
mVertexBufferPipeline[n] = screen->CreateVertexBuffer();
unsigned int bytesize = BUFFER_SIZE * sizeof(FFlatVertex);
mVertexBufferPipeline[n]->SetData(bytesize, nullptr, false);
mVertexBufferPipeline[n]->SetData(bytesize, nullptr, BufferUsageType::Persistent);
static const FVertexBufferAttribute format[] = {
{ 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) },

View file

@ -64,7 +64,7 @@ FLightBuffer::FLightBuffer(int pipelineNbr):
for (int n = 0; n < mPipelineNbr; n++)
{
mBufferPipeline[n] = screen->CreateDataBuffer(LIGHTBUF_BINDINGPOINT, mBufferType, false);
mBufferPipeline[n]->SetData(mByteSize, nullptr, false);
mBufferPipeline[n]->SetData(mByteSize, nullptr, BufferUsageType::Persistent);
}
Clear();

View file

@ -117,7 +117,7 @@ void IShadowMap::UploadLights()
if (mLightList == nullptr)
mLightList = screen->CreateDataBuffer(LIGHTLIST_BINDINGPOINT, true, false);
mLightList->SetData(sizeof(float) * mLights.Size(), &mLights[0]);
mLightList->SetData(sizeof(float) * mLights.Size(), &mLights[0], BufferUsageType::Stream);
}
@ -129,11 +129,11 @@ void IShadowMap::UploadAABBTree()
if (!mNodesBuffer)
mNodesBuffer = screen->CreateDataBuffer(LIGHTNODES_BINDINGPOINT, true, false);
mNodesBuffer->SetData(mAABBTree->NodesSize(), mAABBTree->Nodes());
mNodesBuffer->SetData(mAABBTree->NodesSize(), mAABBTree->Nodes(), BufferUsageType::Static);
if (!mLinesBuffer)
mLinesBuffer = screen->CreateDataBuffer(LIGHTLINES_BINDINGPOINT, true, false);
mLinesBuffer->SetData(mAABBTree->LinesSize(), mAABBTree->Lines());
mLinesBuffer->SetData(mAABBTree->LinesSize(), mAABBTree->Lines(), BufferUsageType::Static);
}
else if (mAABBTree->Update())
{

View file

@ -98,7 +98,7 @@ std::pair<PalEntry, PalEntry>& R_GetSkyCapColor(FGameTexture* tex)
const uint32_t* buffer = (const uint32_t*)bitmap.GetPixels();
if (buffer)
{
sky.Colors.first = averageColor((uint32_t*)buffer, w * MIN(30, h), 0);
sky.Colors.first = averageColor((uint32_t*)buffer, w * min(30, h), 0);
if (h > 30)
{
sky.Colors.second = averageColor(((uint32_t*)buffer) + (h - 30) * w, w * 30, 0);
@ -130,7 +130,7 @@ FSkyVertexBuffer::FSkyVertexBuffer()
{ 0, VATTR_COLOR, VFmt_Byte4, (int)myoffsetof(FSkyVertex, color) }
};
mVertexBuffer->SetFormat(1, 3, sizeof(FSkyVertex), format);
mVertexBuffer->SetData(mVertices.Size() * sizeof(FSkyVertex), &mVertices[0], true);
mVertexBuffer->SetData(mVertices.Size() * sizeof(FSkyVertex), &mVertices[0], BufferUsageType::Static);
}
FSkyVertexBuffer::~FSkyVertexBuffer()

View file

@ -43,7 +43,7 @@ HWViewpointBuffer::HWViewpointBuffer(int pipelineNbr):
for (int n = 0; n < mPipelineNbr; n++)
{
mBufferPipeline[n] = screen->CreateDataBuffer(VIEWPOINT_BINDINGPOINT, false, true);
mBufferPipeline[n]->SetData(mByteSize, nullptr, false);
mBufferPipeline[n]->SetData(mByteSize, nullptr, BufferUsageType::Persistent);
}
Clear();

View file

@ -129,7 +129,7 @@ public:
void SetData()
{
if (mBuffer != nullptr)
mBuffer->SetData(sizeof(T), &Values);
mBuffer->SetData(sizeof(T), &Values, BufferUsageType::Static);
}
IDataBuffer* GetBuffer() const

View file

@ -26,7 +26,7 @@
#include "hwrenderer/postprocessing/hw_postprocessshader.h"
#include <random>
#include "texturemanager.h"
#include "templates.h"
#include "stats.h"
Postprocess hw_postprocess;
@ -326,9 +326,9 @@ void PPLensDistort::Render(PPRenderState *renderstate)
// Scale factor to keep sampling within the input texture
float r2 = aspect * aspect * 0.25f + 0.25f;
float sqrt_r2 = sqrt(r2);
float f0 = 1.0f + MAX(r2 * (k[0] + kcube[0] * sqrt_r2), 0.0f);
float f2 = 1.0f + MAX(r2 * (k[2] + kcube[2] * sqrt_r2), 0.0f);
float f = MAX(f0, f2);
float f0 = 1.0f + max(r2 * (k[0] + kcube[0] * sqrt_r2), 0.0f);
float f2 = 1.0f + max(r2 * (k[2] + kcube[2] * sqrt_r2), 0.0f);
float f = max(f0, f2);
float scale = 1.0f / f;
LensUniforms uniforms;
@ -498,8 +498,8 @@ void PPCameraExposure::Render(PPRenderState *renderstate, int sceneWidth, int sc
void PPCameraExposure::UpdateTextures(int width, int height)
{
int firstwidth = MAX(width / 2, 1);
int firstheight = MAX(height / 2, 1);
int firstwidth = max(width / 2, 1);
int firstheight = max(height / 2, 1);
if (ExposureLevels.size() > 0 && ExposureLevels[0].Viewport.width == firstwidth && ExposureLevels[0].Viewport.height == firstheight)
{
@ -511,8 +511,8 @@ void PPCameraExposure::UpdateTextures(int width, int height)
int i = 0;
do
{
width = MAX(width / 2, 1);
height = MAX(height / 2, 1);
width = max(width / 2, 1);
height = max(height / 2, 1);
PPExposureLevel blevel;
blevel.Viewport.left = 0;
@ -746,7 +746,7 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW
LinearDepthUniforms linearUniforms;
linearUniforms.SampleIndex = 0;
linearUniforms.LinearizeDepthA = 1.0f / screen->GetZFar() - 1.0f / screen->GetZNear();
linearUniforms.LinearizeDepthB = MAX(1.0f / screen->GetZNear(), 1.e-8f);
linearUniforms.LinearizeDepthB = max(1.0f / screen->GetZNear(), 1.e-8f);
linearUniforms.InverseDepthRangeA = 1.0f;
linearUniforms.InverseDepthRangeB = 0.0f;
linearUniforms.Scale = sceneScale;

View file

@ -1,6 +1,6 @@
#pragma once
#include "templates.h"
struct FModelVertex
{

View file

@ -56,7 +56,7 @@ void PolyBuffer::Reset()
{
}
void PolyBuffer::SetData(size_t size, const void *data, bool staticdata)
void PolyBuffer::SetData(size_t size, const void *data, BufferUsageType usage)
{
mData.resize(size);
map = mData.data();

View file

@ -20,7 +20,7 @@ public:
static void ResetAll();
void Reset();
void SetData(size_t size, const void *data, bool staticdata) override;
void SetData(size_t size, const void *data, BufferUsageType usage) override;
void SetSubData(size_t offset, size_t size, const void *data) override;
void Resize(size_t newsize) override;

View file

@ -22,7 +22,7 @@
#include "v_video.h"
#include "m_png.h"
#include "templates.h"
#include "r_videoscale.h"
#include "i_time.h"
#include "v_text.h"
@ -111,7 +111,7 @@ void PolyFrameBuffer::InitializeState()
mScreenQuad.VertexBuffer->SetFormat(1, 3, sizeof(ScreenQuadVertex), format);
mScreenQuad.IndexBuffer = screen->CreateIndexBuffer();
mScreenQuad.IndexBuffer->SetData(6 * sizeof(uint32_t), indices, false);
mScreenQuad.IndexBuffer->SetData(6 * sizeof(uint32_t), indices, BufferUsageType::Stream);
CheckCanvas();
}
@ -219,8 +219,8 @@ void PolyFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function<void(
IntRect bounds;
bounds.left = bounds.top = 0;
bounds.width = std::min(tex->GetWidth(), image->GetWidth());
bounds.height = std::min(tex->GetHeight(), image->GetHeight());
bounds.width = min(tex->GetWidth(), image->GetWidth());
bounds.height = min(tex->GetHeight(), image->GetHeight());
renderFunc(bounds);
@ -254,7 +254,7 @@ void PolyFrameBuffer::PostProcessScene(bool swscene, int fixedcm, float flash, c
{ 0.0f, (float)mScreenViewport.height, 0.0f, 1.0f },
{ (float)mScreenViewport.width, (float)mScreenViewport.height, 1.0f, 1.0f }
};
mScreenQuad.VertexBuffer->SetData(4 * sizeof(ScreenQuadVertex), vertices, false);
mScreenQuad.VertexBuffer->SetData(4 * sizeof(ScreenQuadVertex), vertices, BufferUsageType::Stream);
mRenderState->SetVertexBuffer(mScreenQuad.VertexBuffer, 0, 0);
mRenderState->SetIndexBuffer(mScreenQuad.IndexBuffer);

View file

@ -20,7 +20,7 @@
**
*/
#include "templates.h"
#include "c_cvars.h"
#include "hw_material.h"
#include "hw_cvars.h"

View file

@ -23,7 +23,7 @@
#include "polyrenderer/backend/poly_renderstate.h"
#include "polyrenderer/backend/poly_framebuffer.h"
#include "polyrenderer/backend/poly_hwtexture.h"
#include "templates.h"
#include "hw_skydome.h"
#include "hw_viewpointuniforms.h"
#include "hw_lightbuffer.h"

View file

@ -21,7 +21,7 @@
*/
#include <stddef.h>
#include "templates.h"
#include "filesystem.h"
#include "v_video.h"
@ -100,10 +100,10 @@ void PolyTriangleThreadData::SetScissor(int x, int y, int w, int h)
void PolyTriangleThreadData::UpdateClip()
{
clip.left = MAX(MAX(viewport_x, scissor.left), 0);
clip.top = MAX(MAX(viewport_y, scissor.top), 0);
clip.right = MIN(MIN(viewport_x + viewport_width, scissor.right), dest_width);
clip.bottom = MIN(MIN(viewport_y + viewport_height, scissor.bottom), dest_height);
clip.left = max(max(viewport_x, scissor.left), 0);
clip.top = max(max(viewport_y, scissor.top), 0);
clip.right = min(min(viewport_x + viewport_width, scissor.right), dest_width);
clip.bottom = min(min(viewport_y + viewport_height, scissor.bottom), dest_height);
}
void PolyTriangleThreadData::PushStreamData(const StreamData &data, const PolyPushConstants &constants)
@ -206,11 +206,11 @@ void PolyTriangleThreadData::SetStencil(int stencilRef, int op)
StencilTestValue = stencilRef;
if (op == SOP_Increment)
{
StencilWriteValue = MIN(stencilRef + 1, (int)255);
StencilWriteValue = min(stencilRef + 1, (int)255);
}
else if (op == SOP_Decrement)
{
StencilWriteValue = MAX(stencilRef - 1, (int)0);
StencilWriteValue = max(stencilRef - 1, (int)0);
}
else // SOP_Keep
{
@ -453,8 +453,8 @@ void PolyTriangleThreadData::DrawShadedLine(const ShadedTriVertex *const* vert)
{
float clipdistance1 = clipdistance[0 * numclipdistances + p];
float clipdistance2 = clipdistance[1 * numclipdistances + p];
if (clipdistance1 < 0.0f) t1 = MAX(-clipdistance1 / (clipdistance2 - clipdistance1), t1);
if (clipdistance2 < 0.0f) t2 = MIN(1.0f + clipdistance2 / (clipdistance1 - clipdistance2), t2);
if (clipdistance1 < 0.0f) t1 = max(-clipdistance1 / (clipdistance2 - clipdistance1), t1);
if (clipdistance2 < 0.0f) t2 = min(1.0f + clipdistance2 / (clipdistance1 - clipdistance2), t2);
if (t1 >= t2)
return;
}
@ -792,8 +792,8 @@ int PolyTriangleThreadData::ClipEdge(const ShadedTriVertex *const* verts)
// Clip halfspace
if ((clipdistance1 >= 0.0f || clipdistance2 >= 0.0f) && outputverts + 1 < max_additional_vertices)
{
float t1 = (clipdistance1 < 0.0f) ? MAX(-clipdistance1 / (clipdistance2 - clipdistance1), 0.0f) : 0.0f;
float t2 = (clipdistance2 < 0.0f) ? MIN(1.0f + clipdistance2 / (clipdistance1 - clipdistance2), 1.0f) : 1.0f;
float t1 = (clipdistance1 < 0.0f) ? max(-clipdistance1 / (clipdistance2 - clipdistance1), 0.0f) : 0.0f;
float t2 = (clipdistance2 < 0.0f) ? min(1.0f + clipdistance2 / (clipdistance1 - clipdistance2), 1.0f) : 1.0f;
// add t1 vertex
for (int k = 0; k < 3; k++)

View file

@ -85,16 +85,16 @@ public:
int skipped_by_thread(int first_line)
{
int clip_first_line = MAX(first_line, numa_start_y);
int clip_first_line = max(first_line, numa_start_y);
int core_skip = (num_cores - (clip_first_line - core) % num_cores) % num_cores;
return clip_first_line + core_skip - first_line;
}
int count_for_thread(int first_line, int count)
{
count = MIN(count, numa_end_y - first_line);
count = min(count, numa_end_y - first_line);
int c = (count - skipped_by_thread(first_line) + num_cores - 1) / num_cores;
return MAX(c, 0);
return max(c, 0);
}
struct Scanline

View file

@ -21,7 +21,7 @@
*/
#include <stddef.h>
#include "templates.h"
#include "filesystem.h"
#include "v_video.h"

View file

@ -336,10 +336,10 @@ void BlendColorAdd_Src_One(int y, int x0, int x1, PolyTriangleThreadData* thread
uint32_t srcscale = APART(src);
srcscale += srcscale >> 7;
uint32_t a = MIN<int32_t>((((APART(src) * srcscale) + 127) >> 8) + APART(dst), 255);
uint32_t r = MIN<int32_t>((((RPART(src) * srcscale) + 127) >> 8) + RPART(dst), 255);
uint32_t g = MIN<int32_t>((((GPART(src) * srcscale) + 127) >> 8) + GPART(dst), 255);
uint32_t b = MIN<int32_t>((((BPART(src) * srcscale) + 127) >> 8) + BPART(dst), 255);
uint32_t a = min<int32_t>((((APART(src) * srcscale) + 127) >> 8) + APART(dst), 255);
uint32_t r = min<int32_t>((((RPART(src) * srcscale) + 127) >> 8) + RPART(dst), 255);
uint32_t g = min<int32_t>((((GPART(src) * srcscale) + 127) >> 8) + GPART(dst), 255);
uint32_t b = min<int32_t>((((BPART(src) * srcscale) + 127) >> 8) + BPART(dst), 255);
line[x] = MAKEARGB(a, r, g, b);
}
@ -382,10 +382,10 @@ void BlendColorAdd_SrcCol_One(int y, int x0, int x1, PolyTriangleThreadData* thr
srcscale_g += srcscale_g >> 7;
srcscale_b += srcscale_b >> 7;
uint32_t a = MIN<int32_t>((((APART(src) * srcscale_a) + 127) >> 8) + APART(dst), 255);
uint32_t r = MIN<int32_t>((((RPART(src) * srcscale_r) + 127) >> 8) + RPART(dst), 255);
uint32_t g = MIN<int32_t>((((GPART(src) * srcscale_g) + 127) >> 8) + GPART(dst), 255);
uint32_t b = MIN<int32_t>((((BPART(src) * srcscale_b) + 127) >> 8) + BPART(dst), 255);
uint32_t a = min<int32_t>((((APART(src) * srcscale_a) + 127) >> 8) + APART(dst), 255);
uint32_t r = min<int32_t>((((RPART(src) * srcscale_r) + 127) >> 8) + RPART(dst), 255);
uint32_t g = min<int32_t>((((GPART(src) * srcscale_g) + 127) >> 8) + GPART(dst), 255);
uint32_t b = min<int32_t>((((BPART(src) * srcscale_b) + 127) >> 8) + BPART(dst), 255);
line[x] = MAKEARGB(a, r, g, b);
}
@ -514,10 +514,10 @@ void BlendColorRevSub_Src_One(int y, int x0, int x1, PolyTriangleThreadData* thr
uint32_t srcscale = APART(src);
srcscale += srcscale >> 7;
uint32_t a = MAX<int32_t>(APART(dst) - (((APART(src) * srcscale) + 127) >> 8), 0);
uint32_t r = MAX<int32_t>(RPART(dst) - (((RPART(src) * srcscale) + 127) >> 8), 0);
uint32_t g = MAX<int32_t>(GPART(dst) - (((GPART(src) * srcscale) + 127) >> 8), 0);
uint32_t b = MAX<int32_t>(BPART(dst) - (((BPART(src) * srcscale) + 127) >> 8), 0);
uint32_t a = max<int32_t>(APART(dst) - (((APART(src) * srcscale) + 127) >> 8), 0);
uint32_t r = max<int32_t>(RPART(dst) - (((RPART(src) * srcscale) + 127) >> 8), 0);
uint32_t g = max<int32_t>(GPART(dst) - (((GPART(src) * srcscale) + 127) >> 8), 0);
uint32_t b = max<int32_t>(BPART(dst) - (((BPART(src) * srcscale) + 127) >> 8), 0);
line[x] = MAKEARGB(a, r, g, b);
}

View file

@ -21,7 +21,7 @@
*/
#include <stddef.h>
#include "templates.h"
#include "poly_thread.h"
#include "screen_scanline_setup.h"
#include <cmath>
@ -124,7 +124,7 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
// L = light-pos
// dist = sqrt(dot(L, L))
// distance_attenuation = 1 - MIN(dist * (1/radius), 1)
// distance_attenuation = 1 - min(dist * (1/radius), 1)
__m128 Lx = _mm_sub_ps(lightposX, _mm_loadu_ps(&worldposX[x]));
__m128 Ly = _mm_sub_ps(lightposY, _mm_loadu_ps(&worldposY[x]));
__m128 Lz = _mm_sub_ps(lightposZ, _mm_loadu_ps(&worldposZ[x]));
@ -179,7 +179,7 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
// L = light-pos
// dist = sqrt(dot(L, L))
// distance_attenuation = 1 - MIN(dist * (1/radius), 1)
// distance_attenuation = 1 - min(dist * (1/radius), 1)
float Lx = lightposX - worldposX[x];
float Ly = lightposY - worldposY[x];
float Lz = lightposZ - worldposZ[x];
@ -191,7 +191,7 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
float rcp_dist = _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(dist2)));
#endif
float dist = dist2 * rcp_dist;
float distance_attenuation = 256.0f - MIN(dist * light_radius, 256.0f);
float distance_attenuation = 256.0f - min(dist * light_radius, 256.0f);
// The simple light type
float simple_attenuation = distance_attenuation;
@ -202,7 +202,7 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
Ly *= rcp_dist;
Lz *= rcp_dist;
float dotNL = worldnormalX * Lx + worldnormalY * Ly + worldnormalZ * Lz;
float point_attenuation = MAX(dotNL, 0.0f) * distance_attenuation;
float point_attenuation = max(dotNL, 0.0f) * distance_attenuation;
uint32_t attenuation = (uint32_t)(is_attenuated ? (int32_t)point_attenuation : (int32_t)simple_attenuation);
@ -211,9 +211,9 @@ static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
lit_b += (BPART(light_color) * attenuation) >> 8;
}
lit_r = MIN<uint32_t>(lit_r, 255);
lit_g = MIN<uint32_t>(lit_g, 255);
lit_b = MIN<uint32_t>(lit_b, 255);
lit_r = min<uint32_t>(lit_r, 255);
lit_g = min<uint32_t>(lit_g, 255);
lit_b = min<uint32_t>(lit_b, 255);
lightarray[x] = MAKEARGB(lit_a, lit_r, lit_g, lit_b);
// Palette version:
@ -255,7 +255,7 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
uint32_t* lightarray = thread->scanline.lightarray;
for (int x = x0; x < x1; x++)
{
uint32_t l = MIN(lightpos >> 8, 256);
uint32_t l = min(lightpos >> 8, 256);
uint32_t r = vColorR[x];
uint32_t g = vColorG[x];
@ -273,9 +273,9 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
g += (uint32_t)(constants->uDynLightColor.Y * 255.0f);
b += (uint32_t)(constants->uDynLightColor.Z * 255.0f);
r = MIN<uint32_t>(r, 255);
g = MIN<uint32_t>(g, 255);
b = MIN<uint32_t>(b, 255);
r = min<uint32_t>(r, 255);
g = min<uint32_t>(g, 255);
b = min<uint32_t>(b, 255);
}
lightarray[x] = MAKEARGB(a, r, g, b);
@ -287,7 +287,7 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
uint32_t* lightarray = thread->scanline.lightarray;
for (int x = x0; x < x1; x++)
{
uint32_t l = MIN((FRACUNIT - clamp<fixed_t>(shade - MIN(maxvis, lightpos), 0, maxlight)) >> 8, 256);
uint32_t l = min((FRACUNIT - clamp<fixed_t>(shade - min(maxvis, lightpos), 0, maxlight)) >> 8, 256);
uint32_t r = vColorR[x];
uint32_t g = vColorG[x];
uint32_t b = vColorB[x];
@ -304,9 +304,9 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
g += (uint32_t)(constants->uDynLightColor.Y * 255.0f);
b += (uint32_t)(constants->uDynLightColor.Z * 255.0f);
r = MIN<uint32_t>(r, 255);
g = MIN<uint32_t>(g, 255);
b = MIN<uint32_t>(b, 255);
r = min<uint32_t>(r, 255);
g = min<uint32_t>(g, 255);
b = min<uint32_t>(b, 255);
}
lightarray[x] = MAKEARGB(a, r, g, b);
@ -327,7 +327,7 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
uint32_t g = thread->scanline.vColorG[x];
uint32_t b = thread->scanline.vColorB[x];
float fogdist = MAX(16.0f, w[x]);
float fogdist = max(16.0f, w[x]);
float fogfactor = std::exp2(constants->uFogDensity * fogdist);
// brightening around the player for light mode 2:
@ -365,9 +365,9 @@ static void WriteLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* ar
g += (uint32_t)(constants->uDynLightColor.Y * 255.0f);
b += (uint32_t)(constants->uDynLightColor.Z * 255.0f);
r = MIN<uint32_t>(r, 255);
g = MIN<uint32_t>(g, 255);
b = MIN<uint32_t>(b, 255);
r = min<uint32_t>(r, 255);
g = min<uint32_t>(g, 255);
b = min<uint32_t>(b, 255);
}
lightarray[x] = MAKEARGB(a, r, g, b);

View file

@ -21,7 +21,7 @@
*/
#include <stddef.h>
#include "templates.h"
#include "poly_thread.h"
#include "screen_scanline_setup.h"
#include <cmath>
@ -291,9 +291,9 @@ static void FuncNormal_AddColor(int x0, int x1, PolyTriangleThreadData* thread)
uint32_t texel = fragcolor[x];
fragcolor[x] = MAKEARGB(
APART(texel),
MIN(r + RPART(texel), (uint32_t)255),
MIN(g + GPART(texel), (uint32_t)255),
MIN(b + BPART(texel), (uint32_t)255));
min(r + RPART(texel), (uint32_t)255),
min(g + GPART(texel), (uint32_t)255),
min(b + BPART(texel), (uint32_t)255));
}
}
@ -309,9 +309,9 @@ static void FuncNormal_AddObjectColor(int x0, int x1, PolyTriangleThreadData* th
uint32_t texel = fragcolor[x];
fragcolor[x] = MAKEARGB(
APART(texel),
MIN((r * RPART(texel)) >> 8, (uint32_t)255),
MIN((g * GPART(texel)) >> 8, (uint32_t)255),
MIN((b * BPART(texel)) >> 8, (uint32_t)255));
min((r * RPART(texel)) >> 8, (uint32_t)255),
min((g * GPART(texel)) >> 8, (uint32_t)255),
min((b * BPART(texel)) >> 8, (uint32_t)255));
}
}
@ -331,9 +331,9 @@ static void FuncNormal_AddObjectColor2(int x0, int x1, PolyTriangleThreadData* t
uint32_t texel = fragcolor[x];
fragcolor[x] = MAKEARGB(
APART(texel),
MIN((r * RPART(texel)) >> 8, (uint32_t)255),
MIN((g * GPART(texel)) >> 8, (uint32_t)255),
MIN((b * BPART(texel)) >> 8, (uint32_t)255));
min((r * RPART(texel)) >> 8, (uint32_t)255),
min((g * GPART(texel)) >> 8, (uint32_t)255),
min((b * BPART(texel)) >> 8, (uint32_t)255));
}
}
@ -473,7 +473,7 @@ static void GetLightColor(int x0, int x1, PolyTriangleThreadData* thread)
mulG += mulG >> 7;
mulB += mulB >> 7;
float fogdist = MAX(16.0f, w[x]);
float fogdist = max(16.0f, w[x]);
float fogfactor = std::exp2(uFogDensity * fogdist);
uint32_t a = (APART(fg) * mulA + 127) >> 8;
@ -512,7 +512,7 @@ static void MainFP(int x0, int x1, PolyTriangleThreadData* thread)
float fogfactor = 0.0f;
if (constants->uFogEnabled != 0)
{
fogdist = MAX(16.0f, w[x]);
fogdist = max(16.0f, w[x]);
fogfactor = std::exp2(constants->uFogDensity * fogdist);
}
frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a);*/
@ -594,9 +594,9 @@ static void MainFP(int x0, int x1, PolyTriangleThreadData* thread)
b = (BPART(fragcolor[x]) * b + 127) >> 8;
// frag.rgb = frag.rgb + uFogColor.rgb;
r = MIN(r + fogR, (uint32_t)255);
g = MIN(g + fogG, (uint32_t)255);
b = MIN(b + fogB, (uint32_t)255);
r = min(r + fogR, (uint32_t)255);
g = min(g + fogG, (uint32_t)255);
b = min(b + fogB, (uint32_t)255);
fragcolor[x] = MAKEARGB(a, r, g, b);
}

View file

@ -21,7 +21,7 @@
*/
#include <stddef.h>
#include "templates.h"
#include "filesystem.h"
#include "v_video.h"
@ -207,17 +207,17 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs* args, PolyTriangleThreadDat
SortVertices(args, sortedVertices);
int clipleft = thread->clip.left;
int cliptop = MAX(thread->clip.top, thread->numa_start_y);
int cliptop = max(thread->clip.top, thread->numa_start_y);
int clipright = thread->clip.right;
int clipbottom = MIN(thread->clip.bottom, thread->numa_end_y);
int clipbottom = min(thread->clip.bottom, thread->numa_end_y);
int topY = (int)(sortedVertices[0]->y + 0.5f);
int midY = (int)(sortedVertices[1]->y + 0.5f);
int bottomY = (int)(sortedVertices[2]->y + 0.5f);
topY = MAX(topY, cliptop);
midY = MIN(midY, clipbottom);
bottomY = MIN(bottomY, clipbottom);
topY = max(topY, cliptop);
midY = min(midY, clipbottom);
bottomY = min(bottomY, clipbottom);
if (topY >= bottomY)
return;

View file

@ -21,7 +21,7 @@
*/
#include <stddef.h>
#include "templates.h"
#include "i_system.h"
#include "filesystem.h"
#include "v_video.h"

View file

@ -27,7 +27,7 @@
#include <thread>
#include <mutex>
#include <condition_variable>
#include "templates.h"
#include "c_cvars.h"
#include "basics.h"
@ -78,7 +78,7 @@ public:
// The number of lines to skip to reach the first line to be rendered by this thread
int skipped_by_thread(int first_line)
{
int clip_first_line = MAX(first_line, numa_start_y);
int clip_first_line = max(first_line, numa_start_y);
int core_skip = (num_cores - (clip_first_line - core) % num_cores) % num_cores;
return clip_first_line + core_skip - first_line;
}
@ -86,9 +86,9 @@ public:
// The number of lines to be rendered by this thread
int count_for_thread(int first_line, int count)
{
count = MIN(count, numa_end_y - first_line);
count = min(count, numa_end_y - first_line);
int c = (count - skipped_by_thread(first_line) + num_cores - 1) / num_cores;
return MAX(c, 0);
return max(c, 0);
}
// Calculate the dest address for the first line to be rendered by this thread

View file

@ -34,7 +34,7 @@
#include "c_dispatch.h"
#include "c_cvars.h"
#include "v_video.h"
#include "templates.h"
#include "r_videoscale.h"
#include "cmdlib.h"
#include "v_draw.h"
@ -193,7 +193,7 @@ int ViewportScaledWidth(int width, int height)
width = ((float)width/height > ActiveRatio(width, height)) ? (int)(height * ActiveRatio(width, height)) : width;
height = ((float)width/height < ActiveRatio(width, height)) ? (int)(width / ActiveRatio(width, height)) : height;
}
return (int)std::max((int32_t)min_width, (int32_t)(vid_scalefactor * vScaleTable[vid_scalemode].GetScaledWidth(width, height)));
return (int)max((int32_t)min_width, (int32_t)(vid_scalefactor * vScaleTable[vid_scalemode].GetScaledWidth(width, height)));
}
int ViewportScaledHeight(int width, int height)
@ -205,7 +205,7 @@ int ViewportScaledHeight(int width, int height)
height = ((float)width/height < ActiveRatio(width, height)) ? (int)(width / ActiveRatio(width, height)) : height;
width = ((float)width/height > ActiveRatio(width, height)) ? (int)(height * ActiveRatio(width, height)) : width;
}
return (int)std::max((int32_t)min_height, (int32_t)(vid_scalefactor * vScaleTable[vid_scalemode].GetScaledHeight(width, height)));
return (int)max((int32_t)min_height, (int32_t)(vid_scalefactor * vScaleTable[vid_scalemode].GetScaledHeight(width, height)));
}
float ViewportPixelAspect()

View file

@ -186,7 +186,7 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds)
int screenWidth = GetWidth();
int screenHeight = GetHeight();
float scaleX, scaleY;
scaleX = std::min(clientWidth / (float)screenWidth, clientHeight / ((float)screenHeight * ViewportPixelAspect()));
scaleX = min(clientWidth / (float)screenWidth, clientHeight / ((float)screenHeight * ViewportPixelAspect()));
scaleY = scaleX * ViewportPixelAspect();
mOutputLetterbox.width = (int)round(screenWidth * scaleX);
mOutputLetterbox.height = (int)round(screenHeight * scaleY);

View file

@ -61,7 +61,7 @@
#include "texturemanager.h"
#include "i_interface.h"
#include "v_draw.h"
#include "templates.h"
EXTERN_CVAR(Int, menu_resolution_custom_width)
EXTERN_CVAR(Int, menu_resolution_custom_height)
@ -252,7 +252,7 @@ void DCanvas::Resize(int width, int height, bool optimizepitch)
}
else
{
Pitch = width + MAX(0, CPU.DataL1LineSize - 8);
Pitch = width + max(0, CPU.DataL1LineSize - 8);
}
}
int bytes_per_pixel = Bgra ? 4 : 1;
@ -275,7 +275,7 @@ void V_UpdateModeSize (int width, int height)
// This reference size is being used so that on 800x450 (small 16:9) a scale of 2 gets used.
CleanXfac = std::max(std::min(screen->GetWidth() / 400, screen->GetHeight() / 240), 1);
CleanXfac = max(min(screen->GetWidth() / 400, screen->GetHeight() / 240), 1);
if (CleanXfac >= 4) CleanXfac--; // Otherwise we do not have enough space for the episode/skill menus in some languages.
CleanYfac = CleanXfac;
CleanWidth = screen->GetWidth() / CleanXfac;
@ -292,7 +292,7 @@ void V_UpdateModeSize (int width, int height)
else if (w < 1920) factor = 2;
else factor = int(factor * 0.7);
CleanYfac_1 = CleanXfac_1 = factor;// MAX(1, int(factor * 0.7));
CleanYfac_1 = CleanXfac_1 = factor;// max(1, int(factor * 0.7));
CleanWidth_1 = width / CleanXfac_1;
CleanHeight_1 = height / CleanYfac_1;

View file

@ -240,13 +240,8 @@ void VkRenderBuffers::CreateShadowmap()
ImageBuilder builder;
builder.setSize(gl_shadowmap_quality, 1024);
builder.setFormat(SceneNormalFormat);
builder.setFormat(VK_FORMAT_R32_SFLOAT);
builder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
if (!builder.isFormatSupported(fb->device, VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
{
SceneNormalFormat = VK_FORMAT_R8G8B8A8_UNORM;
builder.setFormat(SceneNormalFormat);
}
Shadowmap.Image = builder.create(fb->device);
Shadowmap.Image->SetDebugName("VkRenderBuffers.Shadowmap");

View file

@ -228,7 +228,7 @@ void VkRenderState::ApplyRenderPass(int dt)
pipelineKey.ColorMask = mColorMask;
pipelineKey.CullMode = mCullMode;
pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->NumLayers() : 0;
pipelineKey.NumTextureLayers = std::max(pipelineKey.NumTextureLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS);// Always force minimum 8 textures as the shader requires it
pipelineKey.NumTextureLayers = max(pipelineKey.NumTextureLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS);// Always force minimum 8 textures as the shader requires it
if (mSpecialEffect > EFF_NONE)
{
pipelineKey.SpecialEffect = mSpecialEffect;

View file

@ -30,7 +30,7 @@ VkStreamBuffer::VkStreamBuffer(size_t structSize, size_t count)
mBlockSize = static_cast<uint32_t>((structSize + screen->uniformblockalignment - 1) / screen->uniformblockalignment * screen->uniformblockalignment);
UniformBuffer = (VKDataBuffer*)GetVulkanFrameBuffer()->CreateDataBuffer(-1, false, false);
UniformBuffer->SetData(mBlockSize * count, nullptr, false);
UniformBuffer->SetData(mBlockSize * count, nullptr, BufferUsageType::Persistent);
}
VkStreamBuffer::~VkStreamBuffer()

View file

@ -46,8 +46,13 @@ VKBuffer::~VKBuffer()
mBuffer->Unmap();
auto fb = GetVulkanFrameBuffer();
if (fb && mBuffer)
fb->FrameDeleteList.Buffers.push_back(std::move(mBuffer));
if (fb)
{
if (mBuffer)
fb->FrameDeleteList.Buffers.push_back(std::move(mBuffer));
if (mStaging)
fb->FrameDeleteList.Buffers.push_back(std::move(mStaging));
}
}
void VKBuffer::ResetAll()
@ -64,67 +69,91 @@ void VKBuffer::Reset()
mStaging.reset();
}
void VKBuffer::SetData(size_t size, const void *data, bool staticdata)
void VKBuffer::SetData(size_t size, const void *data, BufferUsageType usage)
{
auto fb = GetVulkanFrameBuffer();
size = std::max(size, (size_t)16); // For supporting zero byte buffers
size_t bufsize = max(size, (size_t)16); // For supporting zero byte buffers
if (staticdata)
// If SetData is called multiple times we have to keep the old buffers alive as there might still be draw commands referencing them
if (mBuffer)
{
fb->FrameDeleteList.Buffers.push_back(std::move(mBuffer));
mBuffer = {};
}
if (mStaging)
{
fb->FrameDeleteList.Buffers.push_back(std::move(mStaging));
mStaging = {};
}
if (usage == BufferUsageType::Static || usage == BufferUsageType::Stream)
{
// Note: we could recycle buffers here for the stream usage type to improve performance
mPersistent = false;
{
BufferBuilder builder;
builder.setUsage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | mBufferType, VMA_MEMORY_USAGE_GPU_ONLY);
builder.setSize(size);
mBuffer = builder.create(fb->device);
}
BufferBuilder builder;
builder.setUsage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | mBufferType, VMA_MEMORY_USAGE_GPU_ONLY);
builder.setSize(bufsize);
mBuffer = builder.create(fb->device);
{
BufferBuilder builder;
builder.setUsage(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY);
builder.setSize(size);
mStaging = builder.create(fb->device);
}
BufferBuilder builder2;
builder2.setUsage(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY);
builder2.setSize(bufsize);
mStaging = builder2.create(fb->device);
void *dst = mStaging->Map(0, size);
memcpy(dst, data, size);
mStaging->Unmap();
if (data)
{
void* dst = mStaging->Map(0, bufsize);
memcpy(dst, data, size);
mStaging->Unmap();
}
fb->GetTransferCommands()->copyBuffer(mStaging.get(), mBuffer.get());
}
else
else if (usage == BufferUsageType::Persistent)
{
mPersistent = screen->BuffersArePersistent();
mPersistent = true;
BufferBuilder builder;
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_UNKNOWN, mPersistent ? VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT : 0);
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
builder.setMemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
builder.setSize(size);
builder.setSize(bufsize);
mBuffer = builder.create(fb->device);
if (mPersistent)
map = mBuffer->Map(0, bufsize);
if (data)
memcpy(map, data, size);
}
else if (usage == BufferUsageType::Mappable)
{
mPersistent = false;
BufferBuilder builder;
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_UNKNOWN, 0);
builder.setMemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
builder.setSize(bufsize);
mBuffer = builder.create(fb->device);
if (data)
{
map = mBuffer->Map(0, size);
if (data)
memcpy(map, data, size);
}
else if (data)
{
void *dst = mBuffer->Map(0, size);
void* dst = mBuffer->Map(0, bufsize);
memcpy(dst, data, size);
mBuffer->Unmap();
}
}
buffersize = size;
}
void VKBuffer::SetSubData(size_t offset, size_t size, const void *data)
{
size = std::max(size, (size_t)16); // For supporting zero byte buffers
size = max(size, (size_t)16); // For supporting zero byte buffers
auto fb = GetVulkanFrameBuffer();
if (mStaging)
@ -145,7 +174,7 @@ void VKBuffer::SetSubData(size_t offset, size_t size, const void *data)
void VKBuffer::Resize(size_t newsize)
{
newsize = std::max(newsize, (size_t)16); // For supporting zero byte buffers
newsize = max(newsize, (size_t)16); // For supporting zero byte buffers
auto fb = GetVulkanFrameBuffer();
@ -193,7 +222,7 @@ void VKBuffer::Unmap()
void *VKBuffer::Lock(unsigned int size)
{
size = std::max(size, (unsigned int)16); // For supporting zero byte buffers
size = max(size, (unsigned int)16); // For supporting zero byte buffers
if (!mBuffer)
{
@ -214,7 +243,7 @@ void VKBuffer::Unlock()
if (!mBuffer)
{
map = nullptr;
SetData(mStaticUpload.Size(), mStaticUpload.Data(), true);
SetData(mStaticUpload.Size(), mStaticUpload.Data(), BufferUsageType::Static);
mStaticUpload.Clear();
}
else if (!mPersistent)

View file

@ -19,7 +19,7 @@ public:
static void ResetAll();
void Reset();
void SetData(size_t size, const void *data, bool staticdata) override;
void SetData(size_t size, const void *data, BufferUsageType usage) override;
void SetSubData(size_t offset, size_t size, const void *data) override;
void Resize(size_t newsize) override;

View file

@ -578,7 +578,7 @@ inline BufferBuilder::BufferBuilder()
inline void BufferBuilder::setSize(size_t size)
{
bufferInfo.size = std::max(size, (size_t)16);
bufferInfo.size = max(size, (size_t)16);
}
inline void BufferBuilder::setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags allocFlags)

View file

@ -377,9 +377,11 @@ VkBool32 VulkanDevice::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT mess
seenMessages.insert(msg);
const char *typestr;
bool showcallstack = false;
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
{
typestr = "vulkan error";
showcallstack = true;
}
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
{
@ -398,11 +400,12 @@ VkBool32 VulkanDevice::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT mess
typestr = "vulkan";
}
Printf("\n");
if (showcallstack)
Printf("\n");
Printf(TEXTCOLOR_RED "[%s] ", typestr);
Printf(TEXTCOLOR_WHITE "%s\n", msg.GetChars());
if (vk_debug_callstack)
if (vk_debug_callstack && showcallstack)
{
FString callstack = JitCaptureStackTrace(0, true);
if (!callstack.IsEmpty())

View file

@ -309,7 +309,7 @@ void VulkanFrameBuffer::WaitForCommands(bool finish, bool uploadOnly)
swapChain->QueuePresent(presentImageIndex, mRenderFinishedSemaphore.get());
}
int numWaitFences = MIN(mNextSubmit, (int)maxConcurrentSubmitCount);
int numWaitFences = min(mNextSubmit, (int)maxConcurrentSubmitCount);
if (numWaitFences > 0)
{
@ -345,8 +345,8 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function<voi
IntRect bounds;
bounds.left = bounds.top = 0;
bounds.width = std::min(tex->GetWidth(), image->Image->width);
bounds.height = std::min(tex->GetHeight(), image->Image->height);
bounds.width = min(tex->GetWidth(), image->Image->width);
bounds.height = min(tex->GetHeight(), image->Image->height);
renderFunc(bounds);
@ -703,7 +703,7 @@ void VulkanFrameBuffer::UpdateGpuStats()
if (q.endIndex <= q.startIndex)
continue;
int64_t timeElapsed = std::max(static_cast<int64_t>(timestamps[q.endIndex] - timestamps[q.startIndex]), (int64_t)0);
int64_t timeElapsed = max(static_cast<int64_t>(timestamps[q.endIndex] - timestamps[q.startIndex]), (int64_t)0);
double timeNS = timeElapsed * timestampPeriod;
FString out;
@ -796,7 +796,7 @@ void VulkanFrameBuffer::CreateFanToTrisIndexBuffer()
}
FanToTrisIndexBuffer.reset(CreateIndexBuffer());
FanToTrisIndexBuffer->SetData(sizeof(uint32_t) * data.Size(), data.Data());
FanToTrisIndexBuffer->SetData(sizeof(uint32_t) * data.Size(), data.Data(), BufferUsageType::Static);
}
void VulkanFrameBuffer::UpdateShadowMap()

View file

@ -161,8 +161,8 @@ bool VulkanSwapChain::CreateSwapChain(VkSwapchainKHR oldSwapChain)
VkSurfaceCapabilitiesKHR surfaceCapabilities = GetSurfaceCapabilities();
actualExtent = { static_cast<uint32_t>(width), static_cast<uint32_t>(height) };
actualExtent.width = std::max(surfaceCapabilities.minImageExtent.width, std::min(surfaceCapabilities.maxImageExtent.width, actualExtent.width));
actualExtent.height = std::max(surfaceCapabilities.minImageExtent.height, std::min(surfaceCapabilities.maxImageExtent.height, actualExtent.height));
actualExtent.width = max(surfaceCapabilities.minImageExtent.width, min(surfaceCapabilities.maxImageExtent.width, actualExtent.width));
actualExtent.height = max(surfaceCapabilities.minImageExtent.height, min(surfaceCapabilities.maxImageExtent.height, actualExtent.height));
if (actualExtent.width == 0 || actualExtent.height == 0)
{
swapChain = VK_NULL_HANDLE;
@ -176,9 +176,9 @@ bool VulkanSwapChain::CreateSwapChain(VkSwapchainKHR oldSwapChain)
// When vsync is on we only want two images. This creates a slight performance penalty in exchange for reduced input latency (less mouse lag).
// When vsync is off we want three images as it allows us to generate new images even during the vertical blanking period where one entry is being used by the presentation engine.
if (swapChainPresentMode == VK_PRESENT_MODE_MAILBOX_KHR || swapChainPresentMode == VK_PRESENT_MODE_IMMEDIATE_KHR)
imageCount = std::min(imageCount, (uint32_t)3);
imageCount = min(imageCount, (uint32_t)3);
else
imageCount = std::min(imageCount, (uint32_t)2);
imageCount = min(imageCount, (uint32_t)2);
VkSwapchainCreateInfoKHR swapChainCreateInfo = {};
swapChainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;

View file

@ -218,8 +218,8 @@ int VkHardwareTexture::GetMipLevels(int w, int h)
int levels = 1;
while (w > 1 || h > 1)
{
w = std::max(w >> 1, 1);
h = std::max(h >> 1, 1);
w = max(w >> 1, 1);
h = max(h >> 1, 1);
levels++;
}
return levels;
@ -391,7 +391,7 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)
int numLayers = NumLayers();
auto fb = GetVulkanFrameBuffer();
auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(std::max(numLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS));
auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(max(numLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS));
descriptor->SetDebugName("VkHardwareTexture.mDescriptorSets");
@ -400,14 +400,16 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)
WriteDescriptors update;
MaterialLayerInfo *layer;
auto systex = static_cast<VkHardwareTexture*>(GetLayer(0, state.mTranslation, &layer));
update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, state.mTranslation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout);
auto systeximage = systex->GetImage(layer->layerTexture, state.mTranslation, layer->scaleFlags);
update.addCombinedImageSampler(descriptor.get(), 0, systeximage->View.get(), sampler, systeximage->Layout);
if (!(layer->scaleFlags & CTF_Indexed))
{
for (int i = 1; i < numLayers; i++)
{
auto systex = static_cast<VkHardwareTexture*>(GetLayer(i, 0, &layer));
update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer->layerTexture, 0, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout);
auto systeximage = systex->GetImage(layer->layerTexture, 0, layer->scaleFlags);
update.addCombinedImageSampler(descriptor.get(), i, systeximage->View.get(), sampler, systeximage->Layout);
}
}
else
@ -415,7 +417,8 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)
for (int i = 1; i < 3; i++)
{
auto systex = static_cast<VkHardwareTexture*>(GetLayer(i, translation, &layer));
update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer->layerTexture, 0, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout);
auto systeximage = systex->GetImage(layer->layerTexture, 0, layer->scaleFlags);
update.addCombinedImageSampler(descriptor.get(), i, systeximage->View.get(), sampler, systeximage->Layout);
}
numLayers = 3;
}
@ -423,7 +426,7 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)
auto dummyImage = fb->GetRenderPassManager()->GetNullTextureView();
for (int i = numLayers; i < SHADER_MIN_REQUIRED_TEXTURE_LAYERS; i++)
{
update.addCombinedImageSampler(descriptor.get(), i, dummyImage, sampler, systex->mImage.Layout);
update.addCombinedImageSampler(descriptor.get(), i, dummyImage, sampler, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
update.updateSets(fb->device);

View file

@ -117,8 +117,8 @@ void VkTextureImage::GenerateMipmaps(VulkanCommandBuffer *cmdbuffer)
barrier0.execute(cmdbuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
Layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
int nextWidth = std::max(mipWidth >> 1, 1);
int nextHeight = std::max(mipHeight >> 1, 1);
int nextWidth = max(mipWidth >> 1, 1);
int nextHeight = max(mipHeight >> 1, 1);
VkImageBlit blit = {};
blit.srcOffsets[0] = { 0, 0, 0 };