vulkan: implement Shader::getVertexAttributeIndex

This commit is contained in:
niki
2022-09-10 15:27:45 +02:00
parent 2010675bff
commit 57207606c0
3 changed files with 21 additions and 3 deletions
+6
View File
@@ -322,6 +322,8 @@ bool Graphics::setMode(void* context, int width, int height, int pixelwidth, int
currentFrame = 0;
created = true;
drawCalls = 0;
drawCallsBatched = 0;
return true;
}
@@ -462,6 +464,7 @@ void Graphics::draw(const DrawCommand& cmd) {
prepareDraw(*cmd.attributes, *cmd.buffers, cmd.texture, cmd.primitiveType, cmd.cullMode);
vkCmdDraw(commandBuffers.at(currentFrame), static_cast<uint32_t>(cmd.vertexCount), static_cast<uint32_t>(cmd.instanceCount), static_cast<uint32_t>(cmd.vertexStart), 0);
drawCalls++;
}
void Graphics::draw(const DrawIndexedCommand& cmd) {
@@ -469,6 +472,7 @@ void Graphics::draw(const DrawIndexedCommand& cmd) {
vkCmdBindIndexBuffer(commandBuffers.at(currentFrame), (VkBuffer)cmd.indexBuffer->getHandle(), static_cast<VkDeviceSize>(cmd.indexBufferOffset), Vulkan::getVulkanIndexBufferType(cmd.indexType));
vkCmdDrawIndexed(commandBuffers.at(currentFrame), static_cast<uint32_t>(cmd.indexCount), static_cast<uint32_t>(cmd.instanceCount), 0, 0, 0);
drawCalls++;
}
void Graphics::drawQuads(int start, int count, const VertexAttributes& attributes, const BufferBindings& buffers, graphics::Texture* texture) {
@@ -486,6 +490,8 @@ void Graphics::drawQuads(int start, int count, const VertexAttributes& attribute
vkCmdDrawIndexed(commandBuffers.at(currentFrame), static_cast<uint32_t>(quadcount * 6), 1, 0, baseVertex, 0);
baseVertex += quadcount * 4;
drawCalls++;
}
}
+13 -3
View File
@@ -118,7 +118,7 @@ static const TBuiltInResource defaultTBuiltInResource = {
};
static const uint32_t STREAMBUFFER_DEFAULT_SIZE = 16;
static const uint32_t DESCRIPTOR_POOL_SIZE = 16;
static const uint32_t DESCRIPTOR_POOL_SIZE = 1;
static VkShaderStageFlagBits getStageBit(ShaderStageType type) {
switch (type) {
@@ -394,7 +394,8 @@ void Shader::attach() {
}
int Shader::getVertexAttributeIndex(const std::string& name) {
return 0;
auto it = attributes.find(name);
return it == attributes.end() ? -1 : it->second;
}
const Shader::UniformInfo* Shader::getUniformInfo(const std::string& name) const {
@@ -564,7 +565,8 @@ void Shader::compileShaders() {
uniformInfos.clear();
for (int i = 0; i < SHADERSTAGE_MAX_ENUM; i++) {
auto glslangStage = getGlslShaderType((ShaderStageType)i);
auto shaderStage = (ShaderStageType)i;
auto glslangStage = getGlslShaderType(shaderStage);
auto intermediate = program->getIntermediate(glslangStage);
if (intermediate == nullptr) {
continue;
@@ -746,6 +748,14 @@ void Shader::compileShaders() {
uniformInfos[u.name] = u;
}
if (shaderStage == SHADERSTAGE_VERTEX) {
for (const auto& r : shaderResources.stage_inputs) {
const auto& name = r.name;
const int attributeLocation = static_cast<int>(comp.get_decoration(r.id, spv::DecorationLocation));
attributes[name] = attributeLocation;
}
}
}
delete program;
+2
View File
@@ -107,6 +107,8 @@ private:
uint32_t uniformLocation;
size_t builtinUniformDataOffset;
std::unordered_map<std::string, int> attributes;
uint32_t currentFrame;
uint32_t currentUsedUniformStreamBuffersCount;
uint32_t currentUsedDescriptorSetsCount;