blob: 1c3120116a14f8ba43f64ab87ec4ce42b4127a84 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// 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 Hetuf60a2d52019-05-09 14:16:05 -040018#include "Config.hpp"
Nicolas Capens69ffc312019-08-30 09:54:19 -040019#include "Memset.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040020#include "Stream.hpp"
Nicolas Capens1d8c8db2018-11-05 16:30:42 -050021#include "System/Types.hpp"
Antonio Maiorano42fd1592020-04-27 11:30:40 -040022#include "Vulkan/VkConfig.hpp"
Ben Claytonfccfc562019-12-17 20:37:31 +000023#include "Vulkan/VkDescriptorSet.hpp"
Nicolas Capens68a82382018-10-02 13:16:55 -040024
Nicolas Capens157ba262019-12-10 17:49:14 -050025namespace vk {
26
27class ImageView;
28class PipelineLayout;
29
30} // namespace vk
31
32namespace sw {
33
34class SpirvShader;
35
36struct PushConstantStorage
Alexis Hetu6159a852019-02-26 14:42:36 -050037{
Nicolas Capens157ba262019-12-10 17:49:14 -050038 unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE];
39};
Alexis Hetu6159a852019-02-26 14:42:36 -050040
Nicolas Capens157ba262019-12-10 17:49:14 -050041struct BlendState : Memset<BlendState>
Nicolas Capens68a82382018-10-02 13:16:55 -040042{
Ben Claytonfccfc562019-12-17 20:37:31 +000043 BlendState()
44 : Memset(this, 0)
45 {}
Nicolas Capens68a82382018-10-02 13:16:55 -040046
Nicolas Capens157ba262019-12-10 17:49:14 -050047 BlendState(bool alphaBlendEnable,
48 VkBlendFactor sourceBlendFactor,
49 VkBlendFactor destBlendFactor,
50 VkBlendOp blendOperation,
51 VkBlendFactor sourceBlendFactorAlpha,
52 VkBlendFactor destBlendFactorAlpha,
Ben Claytonfccfc562019-12-17 20:37:31 +000053 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 Capens157ba262019-12-10 17:49:14 -050062 {}
Chris Forbesa30de542019-03-18 18:51:55 -070063
Nicolas Capens157ba262019-12-10 17:49:14 -050064 bool alphaBlendEnable;
65 VkBlendFactor sourceBlendFactor;
66 VkBlendFactor destBlendFactor;
67 VkBlendOp blendOperation;
68 VkBlendFactor sourceBlendFactorAlpha;
69 VkBlendFactor destBlendFactorAlpha;
70 VkBlendOp blendOperationAlpha;
71};
Nicolas Capens69ffc312019-08-30 09:54:19 -040072
Nicolas Capens157ba262019-12-10 17:49:14 -050073class Context
74{
75public:
Nicolas Capens15d3dda2020-06-11 21:40:43 -040076 Context() = default;
Alexis Hetu51d51082019-07-15 17:20:40 -040077
Nicolas Capens157ba262019-12-10 17:49:14 -050078 bool isDrawPoint(bool polygonModeAware) const;
79 bool isDrawLine(bool polygonModeAware) const;
80 bool isDrawTriangle(bool polygonModeAware) const;
Nicolas Capens68a82382018-10-02 13:16:55 -040081
Nicolas Capens157ba262019-12-10 17:49:14 -050082 bool depthWriteActive() const;
83 bool depthBufferActive() const;
84 bool stencilActive() const;
Nicolas Capens68a82382018-10-02 13:16:55 -040085
Nicolas Capens157ba262019-12-10 17:49:14 -050086 bool allTargetsColorClamp() const;
Nicolas Capens68a82382018-10-02 13:16:55 -040087
Nicolas Capens157ba262019-12-10 17:49:14 -050088 void setBlendState(int index, BlendState state);
89 BlendState getBlendState(int index) const;
Nicolas Capens68a82382018-10-02 13:16:55 -040090
Nicolas Capens157ba262019-12-10 17:49:14 -050091 VkPrimitiveTopology topology;
92 VkProvokingVertexModeEXT provokingVertexMode;
Nicolas Capens68a82382018-10-02 13:16:55 -040093
Nicolas Capens157ba262019-12-10 17:49:14 -050094 bool stencilEnable;
95 VkStencilOpState frontStencil;
96 VkStencilOpState backStencil;
Nicolas Capens68a82382018-10-02 13:16:55 -040097
Nicolas Capens157ba262019-12-10 17:49:14 -050098 // Pixel processor states
99 VkCullModeFlags cullMode;
100 VkFrontFace frontFace;
101 VkPolygonMode polygonMode;
102 VkLineRasterizationModeEXT lineRasterizationMode;
Nicolas Capens68a82382018-10-02 13:16:55 -0400103
Nicolas Capens157ba262019-12-10 17:49:14 -0500104 float depthBias;
105 float slopeDepthBias;
Nicolas Capens68a82382018-10-02 13:16:55 -0400106
Nicolas Capens157ba262019-12-10 17:49:14 -0500107 VkFormat renderTargetInternalFormat(int index) const;
108 int colorWriteActive(int index) const;
Nicolas Capens68a82382018-10-02 13:16:55 -0400109
Alexis Hetu4f438a52020-06-15 16:13:51 -0400110 vk::DescriptorSet::Array descriptorSetObjects = {};
Nicolas Capens157ba262019-12-10 17:49:14 -0500111 vk::DescriptorSet::Bindings descriptorSets = {};
112 vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets = {};
113 Stream input[MAX_INTERFACE_COMPONENTS / 4];
114 bool robustBufferAccess;
Nicolas Capens68a82382018-10-02 13:16:55 -0400115
Nicolas Capens157ba262019-12-10 17:49:14 -0500116 vk::ImageView *renderTarget[RENDERTARGETS];
117 vk::ImageView *depthBuffer;
118 vk::ImageView *stencilBuffer;
Nicolas Capens68a82382018-10-02 13:16:55 -0400119
Nicolas Capens157ba262019-12-10 17:49:14 -0500120 vk::PipelineLayout const *pipelineLayout;
Nicolas Capens68a82382018-10-02 13:16:55 -0400121
Nicolas Capens157ba262019-12-10 17:49:14 -0500122 // Shaders
123 const SpirvShader *pixelShader;
124 const SpirvShader *vertexShader;
Nicolas Capens68a82382018-10-02 13:16:55 -0400125
Nicolas Capens157ba262019-12-10 17:49:14 -0500126 bool occlusionEnabled;
Ben Clayton76e9bc02019-02-26 15:02:18 +0000127
Nicolas Capens157ba262019-12-10 17:49:14 -0500128 // Pixel processor states
129 bool rasterizerDiscard;
130 bool depthBoundsTestEnable;
131 bool depthBufferEnable;
132 VkCompareOp depthCompareMode;
133 bool depthWriteEnable;
Nicolas Capens68a82382018-10-02 13:16:55 -0400134
Nicolas Capens157ba262019-12-10 17:49:14 -0500135 float lineWidth;
Nicolas Capens68a82382018-10-02 13:16:55 -0400136
Ben Claytonfccfc562019-12-17 20:37:31 +0000137 int colorWriteMask[RENDERTARGETS]; // RGBA
Nicolas Capens157ba262019-12-10 17:49:14 -0500138 unsigned int sampleMask;
139 unsigned int multiSampleMask;
140 int sampleCount;
141 bool alphaToCoverage;
Nicolas Capens68a82382018-10-02 13:16:55 -0400142
Nicolas Capens157ba262019-12-10 17:49:14 -0500143private:
144 bool colorWriteActive() const;
145 bool colorUsed() const;
Nicolas Capens68a82382018-10-02 13:16:55 -0400146
Nicolas Capens157ba262019-12-10 17:49:14 -0500147 bool alphaBlendActive(int index) const;
148 VkBlendFactor sourceBlendFactor(int index) const;
149 VkBlendFactor destBlendFactor(int index) const;
150 VkBlendOp blendOperation(int index) const;
Alexis Hetu51d51082019-07-15 17:20:40 -0400151
Nicolas Capens157ba262019-12-10 17:49:14 -0500152 VkBlendFactor sourceBlendFactorAlpha(int index) const;
153 VkBlendFactor destBlendFactorAlpha(int index) const;
154 VkBlendOp blendOperationAlpha(int index) const;
Alexis Hetu51d51082019-07-15 17:20:40 -0400155
Nicolas Capens157ba262019-12-10 17:49:14 -0500156 BlendState blendState[RENDERTARGETS];
157};
Alexis Hetu51d51082019-07-15 17:20:40 -0400158
Nicolas Capens157ba262019-12-10 17:49:14 -0500159} // namespace sw
Nicolas Capens68a82382018-10-02 13:16:55 -0400160
Ben Claytonfccfc562019-12-17 20:37:31 +0000161#endif // sw_Context_hpp