mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-03-21 18:31:10 +00:00
- create an array for the stream data
This commit is contained in:
parent
656a3b8fba
commit
0c9d27d078
8 changed files with 91 additions and 56 deletions
|
@ -112,7 +112,6 @@ void VkRenderPassManager::CreateDynamicSetLayout()
|
|||
builder.addBinding(1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
builder.addBinding(2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
builder.addBinding(3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
builder.addBinding(4, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
DynamicSetLayout = builder.create(GetVulkanFrameBuffer()->device);
|
||||
}
|
||||
|
||||
|
@ -139,7 +138,7 @@ void VkRenderPassManager::CreatePipelineLayout()
|
|||
void VkRenderPassManager::CreateDescriptorPool()
|
||||
{
|
||||
DescriptorPoolBuilder builder;
|
||||
builder.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 4);
|
||||
builder.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 3);
|
||||
builder.addPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1);
|
||||
builder.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 5000 * 6);
|
||||
builder.setMaxSets(5000);
|
||||
|
@ -155,8 +154,7 @@ void VkRenderPassManager::CreateDynamicSet()
|
|||
update.addBuffer(DynamicSet.get(), 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->ViewpointUBO->mBuffer.get(), 0, sizeof(HWViewpointUniforms));
|
||||
update.addBuffer(DynamicSet.get(), 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, fb->LightBufferSSO->mBuffer.get(), 0, 4096);
|
||||
update.addBuffer(DynamicSet.get(), 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->MatricesUBO->mBuffer.get(), 0, sizeof(MatricesUBO));
|
||||
update.addBuffer(DynamicSet.get(), 3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->ColorsUBO->mBuffer.get(), 0, sizeof(ColorsUBO));
|
||||
update.addBuffer(DynamicSet.get(), 4, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->GlowingWallsUBO->mBuffer.get(), 0, sizeof(GlowingWallsUBO));
|
||||
update.addBuffer(DynamicSet.get(), 3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, fb->StreamUBO->mBuffer.get(), 0, sizeof(StreamUBO));
|
||||
update.updateSets(fb->device);
|
||||
}
|
||||
|
||||
|
|
|
@ -319,18 +319,18 @@ void VkRenderState::Apply(int dt)
|
|||
}
|
||||
}
|
||||
|
||||
mColors.uDesaturationFactor = mDesaturation * normScale;
|
||||
mColors.uFogColor = { mFogColor.r * normScale, mFogColor.g * normScale, mFogColor.b * normScale, mFogColor.a * normScale };
|
||||
mColors.uAddColor = { mAddColor.r * normScale, mAddColor.g * normScale, mAddColor.b * normScale, mAddColor.a * normScale };
|
||||
mColors.uObjectColor = { mObjectColor.r * normScale, mObjectColor.g * normScale, mObjectColor.b * normScale, mObjectColor.a * normScale };
|
||||
mColors.uDynLightColor = mDynColor.vec;
|
||||
mColors.uInterpolationFactor = mInterpolationFactor;
|
||||
mStreamData.uDesaturationFactor = mDesaturation * normScale;
|
||||
mStreamData.uFogColor = { mFogColor.r * normScale, mFogColor.g * normScale, mFogColor.b * normScale, mFogColor.a * normScale };
|
||||
mStreamData.uAddColor = { mAddColor.r * normScale, mAddColor.g * normScale, mAddColor.b * normScale, mAddColor.a * normScale };
|
||||
mStreamData.uObjectColor = { mObjectColor.r * normScale, mObjectColor.g * normScale, mObjectColor.b * normScale, mObjectColor.a * normScale };
|
||||
mStreamData.uDynLightColor = mDynColor.vec;
|
||||
mStreamData.uInterpolationFactor = mInterpolationFactor;
|
||||
|
||||
mColors.useVertexData = passManager->VertexFormats[static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat].UseVertexData;
|
||||
mColors.uVertexColor = mColor.vec;
|
||||
mColors.uVertexNormal = mNormal.vec;
|
||||
mStreamData.useVertexData = passManager->VertexFormats[static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat].UseVertexData;
|
||||
mStreamData.uVertexColor = mColor.vec;
|
||||
mStreamData.uVertexNormal = mNormal.vec;
|
||||
|
||||
mColors.timer = 0.0f; // static_cast<float>((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.);
|
||||
mStreamData.timer = 0.0f; // static_cast<float>((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.);
|
||||
|
||||
int tempTM = TM_NORMAL;
|
||||
if (mMaterial.mMaterial && mMaterial.mMaterial->tex->isHardwareCanvas())
|
||||
|
@ -352,37 +352,37 @@ void VkRenderState::Apply(int dt)
|
|||
|
||||
if (mGlowEnabled)
|
||||
{
|
||||
mGlowingWalls.uGlowTopPlane = mGlowTopPlane.vec;
|
||||
mGlowingWalls.uGlowTopColor = mGlowTop.vec;
|
||||
mGlowingWalls.uGlowBottomPlane = mGlowBottomPlane.vec;
|
||||
mGlowingWalls.uGlowBottomColor = mGlowBottom.vec;
|
||||
mStreamData.uGlowTopPlane = mGlowTopPlane.vec;
|
||||
mStreamData.uGlowTopColor = mGlowTop.vec;
|
||||
mStreamData.uGlowBottomPlane = mGlowBottomPlane.vec;
|
||||
mStreamData.uGlowBottomColor = mGlowBottom.vec;
|
||||
}
|
||||
else
|
||||
{
|
||||
mGlowingWalls.uGlowTopColor = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
mGlowingWalls.uGlowBottomColor = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
mStreamData.uGlowTopColor = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
mStreamData.uGlowBottomColor = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
}
|
||||
|
||||
if (mGradientEnabled)
|
||||
{
|
||||
mColors.uObjectColor2 = { mObjectColor2.r * normScale, mObjectColor2.g * normScale, mObjectColor2.b * normScale, mObjectColor2.a * normScale };
|
||||
mGlowingWalls.uGradientTopPlane = mGradientTopPlane.vec;
|
||||
mGlowingWalls.uGradientBottomPlane = mGradientBottomPlane.vec;
|
||||
mStreamData.uObjectColor2 = { mObjectColor2.r * normScale, mObjectColor2.g * normScale, mObjectColor2.b * normScale, mObjectColor2.a * normScale };
|
||||
mStreamData.uGradientTopPlane = mGradientTopPlane.vec;
|
||||
mStreamData.uGradientBottomPlane = mGradientBottomPlane.vec;
|
||||
}
|
||||
else
|
||||
{
|
||||
mColors.uObjectColor2 = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
mStreamData.uObjectColor2 = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
}
|
||||
|
||||
if (mSplitEnabled)
|
||||
{
|
||||
mGlowingWalls.uSplitTopPlane = mSplitTopPlane.vec;
|
||||
mGlowingWalls.uSplitBottomPlane = mSplitBottomPlane.vec;
|
||||
mStreamData.uSplitTopPlane = mSplitTopPlane.vec;
|
||||
mStreamData.uSplitBottomPlane = mSplitBottomPlane.vec;
|
||||
}
|
||||
else
|
||||
{
|
||||
mGlowingWalls.uSplitTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
mGlowingWalls.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
mStreamData.uSplitTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
mStreamData.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
}
|
||||
|
||||
if (mTextureMatrixEnabled)
|
||||
|
@ -408,8 +408,17 @@ void VkRenderState::Apply(int dt)
|
|||
mPushConstants.uLightIndex = screen->mLights->BindUBO(mLightIndex);
|
||||
|
||||
CopyToBuffer(mMatricesOffset, mMatrices, fb->MatricesUBO);
|
||||
CopyToBuffer(mColorsOffset, mColors, fb->ColorsUBO);
|
||||
CopyToBuffer(mGlowingWallsOffset, mGlowingWalls, fb->GlowingWallsUBO);
|
||||
|
||||
mDataIndex++;
|
||||
if (mDataIndex == MAX_STREAM_DATA)
|
||||
{
|
||||
mDataIndex = 0;
|
||||
mStreamDataOffset += sizeof(StreamUBO);
|
||||
}
|
||||
uint8_t *ptr = (uint8_t*)fb->StreamUBO->Memory();
|
||||
memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &mStreamData, sizeof(StreamData));
|
||||
|
||||
mPushConstants.uDataIndex = mDataIndex;
|
||||
|
||||
mCommandBuffer->pushConstants(passManager->PipelineLayout.get(), VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, (uint32_t)sizeof(PushConstants), &mPushConstants);
|
||||
|
||||
|
@ -452,8 +461,8 @@ void VkRenderState::BindDescriptorSets()
|
|||
auto fb = GetVulkanFrameBuffer();
|
||||
auto passManager = fb->GetRenderPassManager();
|
||||
|
||||
uint32_t offsets[5] = { mViewpointOffset, mLightBufferOffset, mMatricesOffset, mColorsOffset, mGlowingWallsOffset };
|
||||
mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->PipelineLayout.get(), 0, passManager->DynamicSet.get(), 5, offsets);
|
||||
uint32_t offsets[4] = { mViewpointOffset, mLightBufferOffset, mMatricesOffset, mStreamDataOffset };
|
||||
mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->PipelineLayout.get(), 0, passManager->DynamicSet.get(), 4, offsets);
|
||||
mDescriptorsChanged = false;
|
||||
}
|
||||
|
||||
|
@ -467,7 +476,7 @@ void VkRenderState::EndRenderPass()
|
|||
|
||||
// To do: move this elsewhere or rename this function to make it clear this can only happen at the end of a frame
|
||||
mMatricesOffset = 0;
|
||||
mColorsOffset = 0;
|
||||
mGlowingWallsOffset = 0;
|
||||
mStreamDataOffset = 0;
|
||||
mDataIndex = -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,13 +62,12 @@ private:
|
|||
bool mDepthWrite = false;
|
||||
|
||||
MatricesUBO mMatrices = {};
|
||||
ColorsUBO mColors = {};
|
||||
GlowingWallsUBO mGlowingWalls = {};
|
||||
StreamData mStreamData = {};
|
||||
PushConstants mPushConstants = {};
|
||||
|
||||
uint32_t mViewpointOffset = 0;
|
||||
uint32_t mLightBufferOffset = 0;
|
||||
uint32_t mMatricesOffset = 0;
|
||||
uint32_t mColorsOffset = 0;
|
||||
uint32_t mGlowingWallsOffset = 0;
|
||||
uint32_t mDataIndex = -1;
|
||||
uint32_t mStreamDataOffset = 0;
|
||||
};
|
||||
|
|
|
@ -109,7 +109,8 @@ static const char *shaderBindings = R"(
|
|||
mat4 TextureMatrix;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 3, std140) uniform ColorsUBO {
|
||||
struct StreamData
|
||||
{
|
||||
vec4 uObjectColor;
|
||||
vec4 uObjectColor2;
|
||||
vec4 uDynLightColor;
|
||||
|
@ -121,9 +122,7 @@ static const char *shaderBindings = R"(
|
|||
int useVertexData;
|
||||
vec4 uVertexColor;
|
||||
vec4 uVertexNormal;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 4, std140) uniform GlowingWallsUBO {
|
||||
|
||||
vec4 uGlowTopPlane;
|
||||
vec4 uGlowTopColor;
|
||||
vec4 uGlowBottomPlane;
|
||||
|
@ -136,6 +135,10 @@ static const char *shaderBindings = R"(
|
|||
vec4 uSplitBottomPlane;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 3, std140) uniform StreamUBO {
|
||||
StreamData data[256];
|
||||
};
|
||||
|
||||
// textures
|
||||
layout(set = 1, binding = 0) uniform sampler2D tex;
|
||||
layout(set = 1, binding = 1) uniform sampler2D texture2;
|
||||
|
@ -164,6 +167,9 @@ static const char *shaderBindings = R"(
|
|||
|
||||
// Blinn glossiness and specular level
|
||||
vec2 uSpecularMaterial;
|
||||
|
||||
int uDataIndex;
|
||||
int padding1, padding2, padding3;
|
||||
};
|
||||
|
||||
// material types
|
||||
|
@ -181,6 +187,26 @@ static const char *shaderBindings = R"(
|
|||
#define brighttexture texture2
|
||||
#endif
|
||||
|
||||
#define uObjectColor data[uDataIndex].uObjectColor
|
||||
#define uObjectColor2 data[uDataIndex].uObjectColor2
|
||||
#define uDynLightColor data[uDataIndex].uDynLightColor
|
||||
#define uAddColor data[uDataIndex].uAddColor
|
||||
#define uFogColor data[uDataIndex].uFogColor
|
||||
#define uDesaturationFactor data[uDataIndex].uDesaturationFactor
|
||||
#define uInterpolationFactor data[uDataIndex].uInterpolationFactor
|
||||
#define timer data[uDataIndex].timer
|
||||
#define useVertexData data[uDataIndex].useVertexData
|
||||
#define uVertexColor data[uDataIndex].uVertexColor
|
||||
#define uVertexNormal data[uDataIndex].uVertexNormal
|
||||
#define uGlowTopPlane data[uDataIndex].uGlowTopPlane
|
||||
#define uGlowTopColor data[uDataIndex].uGlowTopColor
|
||||
#define uGlowBottomPlane data[uDataIndex].uGlowBottomPlane
|
||||
#define uGlowBottomColor data[uDataIndex].uGlowBottomColor
|
||||
#define uGradientTopPlane data[uDataIndex].uGradientTopPlane
|
||||
#define uGradientBottomPlane data[uDataIndex].uGradientBottomPlane
|
||||
#define uSplitTopPlane data[uDataIndex].uSplitTopPlane
|
||||
#define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane
|
||||
|
||||
// #define SUPPORTS_SHADOWMAPS
|
||||
#define VULKAN_COORDINATE_SYSTEM
|
||||
#define HAS_UNIFORM_VERTEX_DATA
|
||||
|
|
|
@ -19,7 +19,7 @@ struct MatricesUBO
|
|||
VSMatrix TextureMatrix;
|
||||
};
|
||||
|
||||
struct ColorsUBO
|
||||
struct StreamData
|
||||
{
|
||||
FVector4 uObjectColor;
|
||||
FVector4 uObjectColor2;
|
||||
|
@ -32,10 +32,7 @@ struct ColorsUBO
|
|||
int useVertexData;
|
||||
FVector4 uVertexColor;
|
||||
FVector4 uVertexNormal;
|
||||
};
|
||||
|
||||
struct GlowingWallsUBO
|
||||
{
|
||||
FVector4 uGlowTopPlane;
|
||||
FVector4 uGlowTopColor;
|
||||
FVector4 uGlowBottomPlane;
|
||||
|
@ -48,6 +45,13 @@ struct GlowingWallsUBO
|
|||
FVector4 uSplitBottomPlane;
|
||||
};
|
||||
|
||||
#define MAX_STREAM_DATA 256
|
||||
|
||||
struct StreamUBO
|
||||
{
|
||||
StreamData data[MAX_STREAM_DATA];
|
||||
};
|
||||
|
||||
struct PushConstants
|
||||
{
|
||||
int uTextureMode;
|
||||
|
@ -66,6 +70,9 @@ struct PushConstants
|
|||
|
||||
// Blinn glossiness and specular level
|
||||
FVector2 uSpecularMaterial;
|
||||
|
||||
int uDataIndex;
|
||||
int padding1, padding2, padding3;
|
||||
};
|
||||
|
||||
class VkShaderProgram
|
||||
|
|
|
@ -50,7 +50,7 @@ extern HWND Window;
|
|||
EXTERN_CVAR(Bool, vid_vsync);
|
||||
|
||||
#ifdef NDEBUG
|
||||
CVAR(Bool, vk_debug, true, 0); // this should be false, once the oversized model can be removed.
|
||||
CVAR(Bool, vk_debug, false, 0); // this should be false, once the oversized model can be removed.
|
||||
#else
|
||||
CVAR(Bool, vk_debug, true, 0);
|
||||
#endif
|
||||
|
|
|
@ -79,8 +79,7 @@ VulkanFrameBuffer::~VulkanFrameBuffer()
|
|||
cur->Reset();
|
||||
|
||||
delete MatricesUBO;
|
||||
delete ColorsUBO;
|
||||
delete GlowingWallsUBO;
|
||||
delete StreamUBO;
|
||||
delete mVertexData;
|
||||
delete mSkyData;
|
||||
delete mViewpoints;
|
||||
|
@ -103,12 +102,10 @@ void VulkanFrameBuffer::InitializeState()
|
|||
mLights = new FLightBuffer();
|
||||
|
||||
// To do: move this to HW renderer interface maybe?
|
||||
MatricesUBO = (VKDataBuffer*)CreateDataBuffer(1234, false);
|
||||
ColorsUBO = (VKDataBuffer*)CreateDataBuffer(1234, false);
|
||||
GlowingWallsUBO = (VKDataBuffer*)CreateDataBuffer(1234, false);
|
||||
MatricesUBO = (VKDataBuffer*)CreateDataBuffer(-1, false);
|
||||
StreamUBO = (VKDataBuffer*)CreateDataBuffer(-1, false);
|
||||
MatricesUBO->SetData(UniformBufferAlignment<::MatricesUBO>() * 50000, nullptr, false);
|
||||
ColorsUBO->SetData(UniformBufferAlignment<::ColorsUBO>() * 50000, nullptr, false);
|
||||
GlowingWallsUBO->SetData(UniformBufferAlignment<::GlowingWallsUBO>() * 50000, nullptr, false);
|
||||
StreamUBO->SetData(UniformBufferAlignment<::StreamUBO>() * 200, nullptr, false);
|
||||
|
||||
mShaderManager.reset(new VkShaderManager(device));
|
||||
mSamplerManager.reset(new VkSamplerManager(device));
|
||||
|
|
|
@ -31,8 +31,7 @@ public:
|
|||
VKDataBuffer *ViewpointUBO = nullptr;
|
||||
VKDataBuffer *LightBufferSSO = nullptr;
|
||||
VKDataBuffer *MatricesUBO = nullptr;
|
||||
VKDataBuffer *ColorsUBO = nullptr;
|
||||
VKDataBuffer *GlowingWallsUBO = nullptr;
|
||||
VKDataBuffer *StreamUBO = nullptr;
|
||||
|
||||
std::vector<std::unique_ptr<VulkanBuffer>> mFrameDeleteList;
|
||||
|
||||
|
|
Loading…
Reference in a new issue