[Vulkan] Add a few size checks on vertex bindings (max across all cards is 32)

This commit is contained in:
DrChat 2018-01-03 16:40:31 -06:00
parent 10f74fc45a
commit 3e157972cc
3 changed files with 18 additions and 2 deletions

View File

@ -1002,6 +1002,16 @@ PipelineCache::UpdateStatus PipelineCache::UpdateVertexInputState(
auto& vertex_attrib_descrs = update_vertex_input_state_attrib_descrs_; auto& vertex_attrib_descrs = update_vertex_input_state_attrib_descrs_;
uint32_t vertex_binding_count = 0; uint32_t vertex_binding_count = 0;
uint32_t vertex_attrib_count = 0; uint32_t vertex_attrib_count = 0;
// Check and make sure we don't overflow.
if (vertex_shader->vertex_bindings().size() >=
xe::countof(vertex_binding_descrs)) {
XELOGE("UpdateVertexInputState failed: too many bindings! (%zd >= %zd)",
vertex_shader->vertex_bindings().size(),
xe::countof(vertex_binding_descrs));
return UpdateStatus::kError;
}
for (const auto& vertex_binding : vertex_shader->vertex_bindings()) { for (const auto& vertex_binding : vertex_shader->vertex_bindings()) {
assert_true(vertex_binding_count < xe::countof(vertex_binding_descrs)); assert_true(vertex_binding_count < xe::countof(vertex_binding_descrs));
auto& vertex_binding_descr = vertex_binding_descrs[vertex_binding_count++]; auto& vertex_binding_descr = vertex_binding_descrs[vertex_binding_count++];

View File

@ -184,9 +184,9 @@ class PipelineCache {
void Reset() { std::memset(this, 0, sizeof(*this)); } void Reset() { std::memset(this, 0, sizeof(*this)); }
} update_vertex_input_state_regs_; } update_vertex_input_state_regs_;
VkPipelineVertexInputStateCreateInfo update_vertex_input_state_info_; VkPipelineVertexInputStateCreateInfo update_vertex_input_state_info_;
VkVertexInputBindingDescription update_vertex_input_state_binding_descrs_[64]; VkVertexInputBindingDescription update_vertex_input_state_binding_descrs_[32];
VkVertexInputAttributeDescription VkVertexInputAttributeDescription
update_vertex_input_state_attrib_descrs_[64]; update_vertex_input_state_attrib_descrs_[96];
struct UpdateInputAssemblyStateRegisters { struct UpdateInputAssemblyStateRegisters {
PrimitiveType primitive_type; PrimitiveType primitive_type;

View File

@ -827,6 +827,12 @@ bool VulkanCommandProcessor::PopulateVertexBuffers(
VkDeviceSize all_buffer_offsets[32]; VkDeviceSize all_buffer_offsets[32];
uint32_t buffer_index = 0; uint32_t buffer_index = 0;
if (vertex_bindings.size() >= xe::countof(all_buffers)) {
XELOGE("PopulateVertexBuffers failed: Too many bindings! (%zd >= %zd)",
vertex_bindings.size(), xe::countof(all_buffers));
return false;
}
for (const auto& vertex_binding : vertex_bindings) { for (const auto& vertex_binding : vertex_bindings) {
int r = XE_GPU_REG_SHADER_CONSTANT_FETCH_00_0 + int r = XE_GPU_REG_SHADER_CONSTANT_FETCH_00_0 +
(vertex_binding.fetch_constant / 3) * 6; (vertex_binding.fetch_constant / 3) * 6;