Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef sw_Context_hpp |
| 16 | #define sw_Context_hpp |
| 17 | |
Alexis Hetu | f60a2d5 | 2019-05-09 14:16:05 -0400 | [diff] [blame] | 18 | #include "Config.hpp" |
Nicolas Capens | 69ffc31 | 2019-08-30 09:54:19 -0400 | [diff] [blame] | 19 | #include "Memset.hpp" |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 20 | #include "Stream.hpp" |
Nicolas Capens | 1d8c8db | 2018-11-05 16:30:42 -0500 | [diff] [blame] | 21 | #include "System/Types.hpp" |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 22 | #include "Vulkan/VkConfig.hpp" |
Ben Clayton | fccfc56 | 2019-12-17 20:37:31 +0000 | [diff] [blame] | 23 | #include "Vulkan/VkDescriptorSet.hpp" |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 24 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 25 | namespace vk { |
| 26 | |
| 27 | class ImageView; |
| 28 | class PipelineLayout; |
| 29 | |
| 30 | } // namespace vk |
| 31 | |
| 32 | namespace sw { |
| 33 | |
| 34 | class SpirvShader; |
| 35 | |
| 36 | struct PushConstantStorage |
Alexis Hetu | 6159a85 | 2019-02-26 14:42:36 -0500 | [diff] [blame] | 37 | { |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 38 | unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE]; |
| 39 | }; |
Alexis Hetu | 6159a85 | 2019-02-26 14:42:36 -0500 | [diff] [blame] | 40 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 41 | struct BlendState : Memset<BlendState> |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 42 | { |
Ben Clayton | fccfc56 | 2019-12-17 20:37:31 +0000 | [diff] [blame] | 43 | BlendState() |
| 44 | : Memset(this, 0) |
| 45 | {} |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 46 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 47 | BlendState(bool alphaBlendEnable, |
| 48 | VkBlendFactor sourceBlendFactor, |
| 49 | VkBlendFactor destBlendFactor, |
| 50 | VkBlendOp blendOperation, |
| 51 | VkBlendFactor sourceBlendFactorAlpha, |
| 52 | VkBlendFactor destBlendFactorAlpha, |
Ben Clayton | fccfc56 | 2019-12-17 20:37:31 +0000 | [diff] [blame] | 53 | VkBlendOp blendOperationAlpha) |
| 54 | : Memset(this, 0) |
| 55 | , alphaBlendEnable(alphaBlendEnable) |
| 56 | , sourceBlendFactor(sourceBlendFactor) |
| 57 | , destBlendFactor(destBlendFactor) |
| 58 | , blendOperation(blendOperation) |
| 59 | , sourceBlendFactorAlpha(sourceBlendFactorAlpha) |
| 60 | , destBlendFactorAlpha(destBlendFactorAlpha) |
| 61 | , blendOperationAlpha(blendOperationAlpha) |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 62 | {} |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 63 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 64 | bool alphaBlendEnable; |
| 65 | VkBlendFactor sourceBlendFactor; |
| 66 | VkBlendFactor destBlendFactor; |
| 67 | VkBlendOp blendOperation; |
| 68 | VkBlendFactor sourceBlendFactorAlpha; |
| 69 | VkBlendFactor destBlendFactorAlpha; |
| 70 | VkBlendOp blendOperationAlpha; |
| 71 | }; |
Nicolas Capens | 69ffc31 | 2019-08-30 09:54:19 -0400 | [diff] [blame] | 72 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 73 | class Context |
| 74 | { |
| 75 | public: |
Nicolas Capens | 15d3dda | 2020-06-11 21:40:43 -0400 | [diff] [blame] | 76 | Context() = default; |
Alexis Hetu | 51d5108 | 2019-07-15 17:20:40 -0400 | [diff] [blame] | 77 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 78 | bool isDrawPoint(bool polygonModeAware) const; |
| 79 | bool isDrawLine(bool polygonModeAware) const; |
| 80 | bool isDrawTriangle(bool polygonModeAware) const; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 81 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 82 | bool depthWriteActive() const; |
| 83 | bool depthBufferActive() const; |
| 84 | bool stencilActive() const; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 85 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 86 | bool allTargetsColorClamp() const; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 87 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 88 | void setBlendState(int index, BlendState state); |
| 89 | BlendState getBlendState(int index) const; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 90 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 91 | VkPrimitiveTopology topology; |
| 92 | VkProvokingVertexModeEXT provokingVertexMode; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 93 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 94 | bool stencilEnable; |
| 95 | VkStencilOpState frontStencil; |
| 96 | VkStencilOpState backStencil; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 97 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 98 | // Pixel processor states |
| 99 | VkCullModeFlags cullMode; |
| 100 | VkFrontFace frontFace; |
| 101 | VkPolygonMode polygonMode; |
| 102 | VkLineRasterizationModeEXT lineRasterizationMode; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 103 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 104 | float depthBias; |
| 105 | float slopeDepthBias; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 106 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 107 | VkFormat renderTargetInternalFormat(int index) const; |
| 108 | int colorWriteActive(int index) const; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 109 | |
Alexis Hetu | 4f438a5 | 2020-06-15 16:13:51 -0400 | [diff] [blame] | 110 | vk::DescriptorSet::Array descriptorSetObjects = {}; |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 111 | vk::DescriptorSet::Bindings descriptorSets = {}; |
| 112 | vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets = {}; |
| 113 | Stream input[MAX_INTERFACE_COMPONENTS / 4]; |
| 114 | bool robustBufferAccess; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 115 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 116 | vk::ImageView *renderTarget[RENDERTARGETS]; |
| 117 | vk::ImageView *depthBuffer; |
| 118 | vk::ImageView *stencilBuffer; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 119 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 120 | vk::PipelineLayout const *pipelineLayout; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 121 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 122 | // Shaders |
| 123 | const SpirvShader *pixelShader; |
| 124 | const SpirvShader *vertexShader; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 125 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 126 | bool occlusionEnabled; |
Ben Clayton | 76e9bc0 | 2019-02-26 15:02:18 +0000 | [diff] [blame] | 127 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 128 | // Pixel processor states |
| 129 | bool rasterizerDiscard; |
| 130 | bool depthBoundsTestEnable; |
| 131 | bool depthBufferEnable; |
| 132 | VkCompareOp depthCompareMode; |
| 133 | bool depthWriteEnable; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 134 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 135 | float lineWidth; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 136 | |
Ben Clayton | fccfc56 | 2019-12-17 20:37:31 +0000 | [diff] [blame] | 137 | int colorWriteMask[RENDERTARGETS]; // RGBA |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 138 | unsigned int sampleMask; |
| 139 | unsigned int multiSampleMask; |
| 140 | int sampleCount; |
| 141 | bool alphaToCoverage; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 142 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 143 | private: |
| 144 | bool colorWriteActive() const; |
| 145 | bool colorUsed() const; |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 146 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 147 | bool alphaBlendActive(int index) const; |
| 148 | VkBlendFactor sourceBlendFactor(int index) const; |
| 149 | VkBlendFactor destBlendFactor(int index) const; |
| 150 | VkBlendOp blendOperation(int index) const; |
Alexis Hetu | 51d5108 | 2019-07-15 17:20:40 -0400 | [diff] [blame] | 151 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 152 | VkBlendFactor sourceBlendFactorAlpha(int index) const; |
| 153 | VkBlendFactor destBlendFactorAlpha(int index) const; |
| 154 | VkBlendOp blendOperationAlpha(int index) const; |
Alexis Hetu | 51d5108 | 2019-07-15 17:20:40 -0400 | [diff] [blame] | 155 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 156 | BlendState blendState[RENDERTARGETS]; |
| 157 | }; |
Alexis Hetu | 51d5108 | 2019-07-15 17:20:40 -0400 | [diff] [blame] | 158 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 159 | } // namespace sw |
Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 160 | |
Ben Clayton | fccfc56 | 2019-12-17 20:37:31 +0000 | [diff] [blame] | 161 | #endif // sw_Context_hpp |