- add support for specifying the topology

This commit is contained in:
Magnus Norddahl 2019-03-01 20:06:20 +01:00
parent 01c78d7238
commit ee8349d168
4 changed files with 30 additions and 4 deletions

View file

@ -200,10 +200,20 @@ void VkRenderPassSetup::CreatePipeline(const VkRenderPassKey &key)
VK_FORMAT_A2R10G10B10_SNORM_PACK32 VK_FORMAT_A2R10G10B10_SNORM_PACK32
}; };
bool inputLocations[6] = { false, false, false, false, false, false };
for (size_t i = 0; i < vfmt.Attrs.size(); i++) for (size_t i = 0; i < vfmt.Attrs.size(); i++)
{ {
const auto &attr = vfmt.Attrs[i]; const auto &attr = vfmt.Attrs[i];
builder.addVertexAttribute(attr.location, attr.binding, vkfmts[attr.format], attr.offset); builder.addVertexAttribute(attr.location, attr.binding, vkfmts[attr.format], attr.offset);
inputLocations[attr.location] = true;
}
// To do: does vulkan absolutely needs a binding for each location or not? What happens if it isn't specified? Better be safe than sorry..
for (int i = 0; i < 6; i++)
{
if (!inputLocations[i])
builder.addVertexAttribute(i, 0, VK_FORMAT_R32G32B32_SFLOAT, 0);
} }
builder.addDynamicState(VK_DYNAMIC_STATE_VIEWPORT); builder.addDynamicState(VK_DYNAMIC_STATE_VIEWPORT);
@ -219,6 +229,16 @@ void VkRenderPassSetup::CreatePipeline(const VkRenderPassKey &key)
builder.setViewport(0.0f, 0.0f, (float)SCREENWIDTH, (float)SCREENHEIGHT); builder.setViewport(0.0f, 0.0f, (float)SCREENWIDTH, (float)SCREENHEIGHT);
builder.setScissor(0, 0, SCREENWIDTH, SCREENHEIGHT); builder.setScissor(0, 0, SCREENWIDTH, SCREENHEIGHT);
static const VkPrimitiveTopology vktopology[] = {
VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
};
builder.setTopology(vktopology[key.DrawType]);
static const int blendstyles[] = { static const int blendstyles[] = {
VK_BLEND_FACTOR_ZERO, VK_BLEND_FACTOR_ZERO,
VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE,

View file

@ -14,14 +14,13 @@ public:
FRenderStyle RenderStyle; FRenderStyle RenderStyle;
int SpecialEffect; int SpecialEffect;
int EffectState; int EffectState;
bool AlphaTest; int AlphaTest;
int VertexFormat; int VertexFormat;
int DrawType;
bool operator<(const VkRenderPassKey &other) const bool operator<(const VkRenderPassKey &other) const
{ {
uint64_t a = RenderStyle.AsDWORD | (static_cast<uint64_t>(SpecialEffect) << 32) | (static_cast<uint64_t>(EffectState) << 40) | (static_cast<uint64_t>(AlphaTest) << 48) | (static_cast<uint64_t>(VertexFormat) << 56); return memcmp(this, &other, sizeof(VkRenderPassKey));
uint64_t b = other.RenderStyle.AsDWORD | (static_cast<uint64_t>(other.SpecialEffect) << 32) | (static_cast<uint64_t>(other.EffectState) << 40) | (static_cast<uint64_t>(other.AlphaTest) << 48) | (static_cast<uint64_t>(other.VertexFormat) << 56);
return a < b;
} }
}; };

View file

@ -140,6 +140,7 @@ void VkRenderState::Apply(int dt)
// Find a render pass that matches our state // Find a render pass that matches our state
VkRenderPassKey passKey; VkRenderPassKey passKey;
passKey.DrawType = dt;
passKey.VertexFormat = static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat; passKey.VertexFormat = static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat;
passKey.RenderStyle = mRenderStyle; passKey.RenderStyle = mRenderStyle;
if (mSpecialEffect > EFF_NONE) if (mSpecialEffect > EFF_NONE)

View file

@ -181,6 +181,7 @@ public:
void setSubpass(int subpass); void setSubpass(int subpass);
void setLayout(VulkanPipelineLayout *layout); void setLayout(VulkanPipelineLayout *layout);
void setRenderPass(VulkanRenderPass *renderPass); void setRenderPass(VulkanRenderPass *renderPass);
void setTopology(VkPrimitiveTopology topology);
void setViewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f); void setViewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f);
void setScissor(int x, int y, int width, int height); void setScissor(int x, int y, int width, int height);
@ -727,6 +728,11 @@ inline void GraphicsPipelineBuilder::setRenderPass(VulkanRenderPass *renderPass)
pipelineInfo.renderPass = renderPass->renderPass; pipelineInfo.renderPass = renderPass->renderPass;
} }
inline void GraphicsPipelineBuilder::setTopology(VkPrimitiveTopology topology)
{
inputAssembly.topology = topology;
}
inline void GraphicsPipelineBuilder::setViewport(float x, float y, float width, float height, float minDepth, float maxDepth) inline void GraphicsPipelineBuilder::setViewport(float x, float y, float width, float height, float minDepth, float maxDepth)
{ {
viewport.x = 0.0f; viewport.x = 0.0f;