Revert "-got rid of shared_ptr in postprocessing system"

This reverts commit 40872a2b21.

This crashed on Vulkan in a very weird way.
This commit is contained in:
Christoph Oelckers 2022-06-09 09:16:58 +02:00
parent 86a5545fa8
commit 013f2003e8
4 changed files with 28 additions and 42 deletions

View file

@ -807,8 +807,8 @@ PPGLTextureBackend *GLPPRenderState::GetGLTexture(PPTexture *texture)
case PixelFormat::Rgba16_snorm: glformat = GL_RGBA16_SNORM; break;
}
if (texture->Data.Size())
backend->Tex = buffers->Create2DTexture("PPTexture", glformat, texture->Width, texture->Height, texture->Data.Data());
if (texture->Data)
backend->Tex = buffers->Create2DTexture("PPTexture", glformat, texture->Width, texture->Height, texture->Data.get());
else
backend->Tex = buffers->Create2DTexture("PPTexture", glformat, texture->Width, texture->Height);
@ -990,4 +990,4 @@ int FGLRenderBuffers::NextEye(int eyeCount)
return mCurrentEye;
}
} // namespace OpenGLRenderer
} // namespace OpenGLRenderer

View file

@ -570,9 +570,11 @@ void PPColormap::Render(PPRenderState *renderstate, int fixedcm, float flash)
void PPTonemap::UpdateTextures()
{
if (gl_tonemap == Palette && !PaletteTexture.Data.Size())
if (gl_tonemap == Palette && !PaletteTexture.Data)
{
uint8_t *lut = PaletteTexture.SetBuffer(512, 512, PixelFormat::Rgba8);
std::shared_ptr<void> data(new uint32_t[512 * 512], [](void *p) { delete[](uint32_t*)p; });
uint8_t *lut = (uint8_t *)data.get();
for (int r = 0; r < 64; r++)
{
for (int g = 0; g < 64; g++)
@ -589,6 +591,8 @@ void PPTonemap::UpdateTextures()
}
}
}
PaletteTexture = { 512, 512, PixelFormat::Rgba8, data };
}
}
@ -638,7 +642,8 @@ PPAmbientOcclusion::PPAmbientOcclusion()
std::uniform_real_distribution<double> distribution(0.0, 1.0);
for (int quality = 0; quality < NumAmbientRandomTextures; quality++)
{
int16_t *randomValues = (int16_t *)AmbientRandomTexture[quality].SetBuffer(4, 4, PixelFormat::Rgba16_snorm);
std::shared_ptr<void> data(new int16_t[16 * 4], [](void *p) { delete[](int16_t*)p; });
int16_t *randomValues = (int16_t *)data.get();
for (int i = 0; i < 16; i++)
{
@ -653,6 +658,8 @@ PPAmbientOcclusion::PPAmbientOcclusion()
randomValues[i * 4 + 2] = (int16_t)clamp(z * 32767.0, -32768.0, 32767.0);
randomValues[i * 4 + 3] = (int16_t)clamp(w * 32767.0, -32768.0, 32767.0);
}
AmbientRandomTexture[quality] = { 4, 4, PixelFormat::Rgba16_snorm, data };
}
}
@ -857,8 +864,9 @@ PPPresent::PPPresent()
.8515625, .6015625, .9765625, .7265625, .8671875, .6171875, .9921875, .7421875,
};
auto p = Dither.SetBuffer(8, 8, PixelFormat::R32f);
memcpy(p, data, 64 * sizeof(float));
std::shared_ptr<void> pixels(new float[64], [](void *p) { delete[](float*)p; });
memcpy(pixels.get(), data, 64 * sizeof(float));
Dither = { 8, 8, PixelFormat::R32f, pixels };
}
/////////////////////////////////////////////////////////////////////////////
@ -1015,10 +1023,11 @@ void PPCustomShaderInstance::SetTextures(PPRenderState *renderstate)
if (!pptex)
{
auto buffer = tex->CreateTexBuffer(0);
pptex = std::make_unique<PPTexture>();
auto pixels = pptex->SetBuffer(buffer.mWidth, buffer.mHeight, PixelFormat::Rgba8);
std::shared_ptr<void> data(new uint32_t[buffer.mWidth * buffer.mHeight], [](void *p) { delete[](uint32_t*)p; });
int count = buffer.mWidth * buffer.mHeight;
uint8_t *pixels = (uint8_t *)data.get();
for (int i = 0; i < count; i++)
{
int pos = i << 2;
@ -1028,6 +1037,7 @@ void PPCustomShaderInstance::SetTextures(PPRenderState *renderstate)
pixels[pos + 3] = buffer.mBuffer[pos + 3];
}
pptex = std::make_unique<PPTexture>(buffer.mWidth, buffer.mHeight, PixelFormat::Rgba8, data);
}
renderstate->SetInputTexture(textureIndex, pptex.get(), PPFilterMode::Linear, PPWrapMode::Repeat);

View file

@ -277,41 +277,17 @@ public:
class PPTexture : public PPResource
{
public:
PPTexture() = default;
PPTexture(int width, int height, PixelFormat format, std::shared_ptr<void> data = {}) : Width(width), Height(height), Format(format), Data(data) { }
void ResetBackend() override { Backend.reset(); }
int Width;
int Height;
PixelFormat Format;
TArray<uint8_t> Data;
std::shared_ptr<void> Data;
std::unique_ptr<PPTextureBackend> Backend;
explicit PPTexture() = default;
PPTexture(int w, int h, PixelFormat f)
{
Width = w;
Height = h;
Format = f;
}
void Clear()
{
Width = Height = 0;
Format = PixelFormat::Rgba8;
Data.Reset();
}
uint8_t* SetBuffer(int w, int h, PixelFormat f)
{
Width = w;
Height = h;
Format = f;
unsigned size = f == PixelFormat::Rgba16f || f == PixelFormat::Rgba16_snorm? 8 : 4;
Data.Resize(w * h * size);
return Data.Data();
}
};
class PPShaderBackend
@ -521,7 +497,7 @@ class PPCameraExposure
public:
void Render(PPRenderState *renderstate, int sceneWidth, int sceneHeight);
PPTexture CameraTexture;// = { 1, 1, PixelFormat::R32f };
PPTexture CameraTexture = { 1, 1, PixelFormat::R32f };
private:
void UpdateTextures(int width, int height);
@ -566,7 +542,7 @@ class PPTonemap
{
public:
void Render(PPRenderState *renderstate);
void ClearTonemapPalette() { PaletteTexture.Clear(); }
void ClearTonemapPalette() { PaletteTexture = {}; }
private:
void UpdateTextures();

View file

@ -364,7 +364,7 @@ VkPPTexture::VkPPTexture(PPTexture *texture)
ImageBuilder imgbuilder;
imgbuilder.setFormat(format);
imgbuilder.setSize(texture->Width, texture->Height);
if (texture->Data.Size())
if (texture->Data)
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
else
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
@ -379,7 +379,7 @@ VkPPTexture::VkPPTexture(PPTexture *texture)
TexImage.View = viewbuilder.create(fb->device);
TexImage.View->SetDebugName("VkPPTextureView");
if (texture->Data.Size())
if (texture->Data)
{
size_t totalsize = texture->Width * texture->Height * pixelsize;
BufferBuilder stagingbuilder;
@ -393,7 +393,7 @@ VkPPTexture::VkPPTexture(PPTexture *texture)
barrier0.execute(fb->GetTransferCommands());
void *data = Staging->Map(0, totalsize);
memcpy(data, texture->Data.Data(), totalsize);
memcpy(data, texture->Data.get(), totalsize);
Staging->Unmap();
VkBufferImageCopy region = {};