Browse Source

More code...

pull/202/head
Squareys 10 years ago
parent
commit
d4398e5784
  1. 3
      src/Magnum/Vk/Buffer.h
  2. 63
      src/Magnum/Vk/DescriptorSet.h
  3. 1
      src/Magnum/Vk/Image.h
  4. 14
      src/Magnum/Vk/Pipeline.h
  5. 2
      src/Magnum/Vk/RenderPass.h

3
src/Magnum/Vk/Buffer.h

@ -155,8 +155,7 @@ class MAGNUM_VK_EXPORT Buffer {
auto cmdFullCopyTo(Image& dest) { auto cmdFullCopyTo(Image& dest) {
const VkBuffer source = _buffer; const VkBuffer source = _buffer;
const UnsignedInt size = _size; return [source, &dest](VkCommandBuffer cmdBuffer){
return [source, &dest, size](VkCommandBuffer cmdBuffer){
VkBufferImageCopy copy{}; VkBufferImageCopy copy{};
copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy.imageSubresource.mipLevel = 0; copy.imageSubresource.mipLevel = 0;

63
src/Magnum/Vk/DescriptorSet.h

@ -166,49 +166,42 @@ class MAGNUM_VK_EXPORT DescriptorSet {
class MAGNUM_VK_EXPORT DescriptorSetUpdate { class MAGNUM_VK_EXPORT DescriptorSetUpdate {
public: public:
DescriptorSetUpdate() { DescriptorSetUpdate(Device& device, DescriptorSet& descriptorSet,
_buffers.reserve(4); std::initializer_list<std::pair<UnsignedInt, std::reference_wrapper<Buffer>>> buffers,
_images.reserve(4); std::initializer_list<std::pair<UnsignedInt, std::reference_wrapper<Texture>>> images):
_writes.reserve(8); _images{Containers::NoInit, images.size()},
} _buffers{Containers::NoInit, buffers.size()},
_writes{Containers::NoInit, images.size() + buffers.size()}
{
void run(Device& device) { UnsignedInt dstArrayElement = 0;
if(_writes.empty()) { Int i = 0; /* Image index */
return; Int b = 0; /* Buffer index */
Int w = 0; /* Write index */
for(auto& buf : buffers) {
_buffers[b] = buf.second.get().getDescriptor();
_writes[w] = VkWriteDescriptorSet{
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, descriptorSet, buf.first, dstArrayElement, 1,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, nullptr, &_buffers[b], nullptr};
++b, ++w;
} }
// TODO: Error check?
vkUpdateDescriptorSets(device, UnsignedInt(_writes.size()), _writes.data(), 0, NULL);
}
DescriptorSetUpdate& useDescriptorSet(DescriptorSet& ds) { for(auto& tex : images) {
_descriptorSet = &ds; _images[i] = tex.second.get().getDescriptor();
return *this; _writes[w] = VkWriteDescriptorSet{
} VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, descriptorSet, tex.first, dstArrayElement, 1,
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &_images[i], nullptr, nullptr};
DescriptorSetUpdate& bindUniformBuffer(Buffer& buffer, UnsignedInt dstBinding, UnsignedInt dstArrayElement=0) { ++i, ++w;
const VkDescriptorBufferInfo descriptor = buffer.getDescriptor(); }
_buffers.push_back(descriptor);
_writes.push_back(VkWriteDescriptorSet{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, *_descriptorSet,
dstBinding, dstArrayElement, 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, nullptr, &_buffers.back(), nullptr});
return *this;
}
DescriptorSetUpdate& bindTexture(Vk::Texture& texture, UnsignedInt dstBinding, UnsignedInt dstArrayElement=0) { vkUpdateDescriptorSets(device, UnsignedInt(_writes.size()), _writes.data(), 0, nullptr);
const VkDescriptorImageInfo descriptor = texture.getDescriptor();
_images.push_back(descriptor);
_writes.push_back(VkWriteDescriptorSet{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, *_descriptorSet,
dstBinding, dstArrayElement, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &_images.back(), nullptr, nullptr});
return *this;
} }
private: private:
std::vector<VkDescriptorImageInfo> _images; Containers::Array<VkDescriptorImageInfo> _images;
std::vector<VkDescriptorBufferInfo> _buffers; Containers::Array<VkDescriptorBufferInfo> _buffers;
std::vector<VkBufferView> _bufferViews;
std::vector<VkWriteDescriptorSet> _writes; Containers::Array<VkWriteDescriptorSet> _writes;
// TODO copies
DescriptorSet* _descriptorSet;
}; };
}} }}

1
src/Magnum/Vk/Image.h

@ -127,6 +127,7 @@ class MAGNUM_VK_EXPORT Image {
image.samples = VK_SAMPLE_COUNT_1_BIT; image.samples = VK_SAMPLE_COUNT_1_BIT;
image.mipLevels = 1; image.mipLevels = 1;
image.arrayLayers = 1; image.arrayLayers = 1;
image.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
image.tiling = VK_IMAGE_TILING_OPTIMAL; image.tiling = VK_IMAGE_TILING_OPTIMAL;
image.usage = UnsignedInt(usage); image.usage = UnsignedInt(usage);
image.sharingMode = VK_SHARING_MODE_EXCLUSIVE; image.sharingMode = VK_SHARING_MODE_EXCLUSIVE;

14
src/Magnum/Vk/Pipeline.h

@ -206,7 +206,7 @@ class MAGNUM_VK_EXPORT Pipeline {
/** /**
@brief Graphics pipeline builder @brief Graphics pipeline builder
Contains properties to create a @ref Pipeline. While the pipeline cannot be changed after it is created, Contains properties to create a @ref Pipeline. While the pipeline cannot be changed after it is created,
the pipeline builder can be used to create another one. the pipeline builder can be used to create another one.
*/ */
class MAGNUM_VK_EXPORT GraphicsPipelineBuilder { class MAGNUM_VK_EXPORT GraphicsPipelineBuilder {
@ -246,7 +246,7 @@ class MAGNUM_VK_EXPORT GraphicsPipelineBuilder {
VK_CULL_MODE_NONE, /* cull mode */ VK_CULL_MODE_NONE, /* cull mode */
VK_FRONT_FACE_COUNTER_CLOCKWISE, /* front face */ VK_FRONT_FACE_COUNTER_CLOCKWISE, /* front face */
VK_FALSE, /* depth bias enable */ VK_FALSE, /* depth bias enable */
0.0f, 0.0f, 0.0f, 0.0f 0.0f, 0.0f, 0.0f, 1.0f
}; };
VkPipelineColorBlendAttachmentState blendAttachmentState = { VkPipelineColorBlendAttachmentState blendAttachmentState = {
@ -328,6 +328,16 @@ class MAGNUM_VK_EXPORT GraphicsPipelineBuilder {
return *this; return *this;
} }
GraphicsPipelineBuilder& enableRasterizerDiscard(bool b) {
_rasterizationState.rasterizerDiscardEnable = b;
return *this;
}
GraphicsPipelineBuilder& setCullMode(VkCullModeFlags mode) {
_rasterizationState.cullMode = mode;
return *this;
}
GraphicsPipelineBuilder& setDynamicStates(std::initializer_list<DynamicState> states) { GraphicsPipelineBuilder& setDynamicStates(std::initializer_list<DynamicState> states) {
_dynamicStates = std::vector<DynamicState>(states); _dynamicStates = std::vector<DynamicState>(states);
return *this; return *this;

2
src/Magnum/Vk/RenderPass.h

@ -49,6 +49,7 @@ class MAGNUM_VK_EXPORT RenderPass {
VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT; VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
VkAttachmentDescription attachments[2]; VkAttachmentDescription attachments[2];
attachments[0].flags = 0;
attachments[0].format = VK_FORMAT_B8G8R8A8_UNORM; attachments[0].format = VK_FORMAT_B8G8R8A8_UNORM;
attachments[0].samples = sampleCount; attachments[0].samples = sampleCount;
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
@ -58,6 +59,7 @@ class MAGNUM_VK_EXPORT RenderPass {
attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachments[1].flags = 0;
attachments[1].format = VkFormat(depthFormat); attachments[1].format = VkFormat(depthFormat);
attachments[1].samples = sampleCount; attachments[1].samples = sampleCount;
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;

Loading…
Cancel
Save