OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrVkPipelineStateDataManager.h" | 8 #include "GrVkPipelineStateDataManager.h" |
9 | 9 |
10 #include "GrVkGpu.h" | 10 #include "GrVkGpu.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // owned by other objects will still match up here. | 25 // owned by other objects will still match up here. |
26 for (int i = 0; i < count; i++) { | 26 for (int i = 0; i < count; i++) { |
27 Uniform& uniform = fUniforms[i]; | 27 Uniform& uniform = fUniforms[i]; |
28 const GrVkUniformHandler::UniformInfo uniformInfo = uniforms[i]; | 28 const GrVkUniformHandler::UniformInfo uniformInfo = uniforms[i]; |
29 SkASSERT(GrGLSLShaderVar::kNonArray == uniformInfo.fVariable.getArrayCou
nt() || | 29 SkASSERT(GrGLSLShaderVar::kNonArray == uniformInfo.fVariable.getArrayCou
nt() || |
30 uniformInfo.fVariable.getArrayCount() > 0); | 30 uniformInfo.fVariable.getArrayCount() > 0); |
31 SkDEBUGCODE( | 31 SkDEBUGCODE( |
32 uniform.fArrayCount = uniformInfo.fVariable.getArrayCount(); | 32 uniform.fArrayCount = uniformInfo.fVariable.getArrayCount(); |
33 uniform.fType = uniformInfo.fVariable.getType(); | 33 uniform.fType = uniformInfo.fVariable.getType(); |
34 ); | 34 ); |
35 uniform.fBinding = | 35 uniform.fBinding = uniformInfo.fBinding; |
36 (kVertex_GrShaderFlag == uniformInfo.fVisibility) ? GrVkUniformHandl
er::kVertexBinding | |
37 : GrVkUniformHandl
er::kFragBinding; | |
38 uniform.fOffset = uniformInfo.fUBOffset; | 36 uniform.fOffset = uniformInfo.fUBOffset; |
| 37 SkDEBUGCODE( |
| 38 uniform.fSetNumber = uniformInfo.fSetNumber; |
| 39 ); |
39 } | 40 } |
40 } | 41 } |
41 | 42 |
42 void* GrVkPipelineStateDataManager::getBufferPtrAndMarkDirty(const Uniform& uni)
const { | 43 void* GrVkPipelineStateDataManager::getBufferPtrAndMarkDirty(const Uniform& uni)
const { |
43 void* buffer; | 44 void* buffer; |
44 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 45 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
45 buffer = fVertexUniformData.get(); | 46 buffer = fVertexUniformData.get(); |
46 fVertexUniformsDirty = true; | 47 fVertexUniformsDirty = true; |
47 } | 48 } |
48 else { | 49 else { |
49 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); | 50 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); |
50 buffer = fFragmentUniformData.get(); | 51 buffer = fFragmentUniformData.get(); |
51 fFragmentUniformsDirty = true; | 52 fFragmentUniformsDirty = true; |
52 } | 53 } |
53 buffer = static_cast<char*>(buffer)+uni.fOffset; | 54 buffer = static_cast<char*>(buffer)+uni.fOffset; |
54 return buffer; | 55 return buffer; |
55 } | 56 } |
56 | 57 |
57 void GrVkPipelineStateDataManager::set1f(UniformHandle u, float v0) const { | 58 void GrVkPipelineStateDataManager::set1f(UniformHandle u, float v0) const { |
58 const Uniform& uni = fUniforms[u.toIndex()]; | 59 const Uniform& uni = fUniforms[u.toIndex()]; |
59 SkASSERT(uni.fType == kFloat_GrSLType); | 60 SkASSERT(uni.fType == kFloat_GrSLType); |
60 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 61 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
| 62 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
61 void* buffer = this->getBufferPtrAndMarkDirty(uni); | 63 void* buffer = this->getBufferPtrAndMarkDirty(uni); |
62 SkASSERT(sizeof(float) == 4); | 64 SkASSERT(sizeof(float) == 4); |
63 memcpy(buffer, &v0, sizeof(float)); | 65 memcpy(buffer, &v0, sizeof(float)); |
64 } | 66 } |
65 | 67 |
66 void GrVkPipelineStateDataManager::set1fv(UniformHandle u, | 68 void GrVkPipelineStateDataManager::set1fv(UniformHandle u, |
67 int arrayCount, | 69 int arrayCount, |
68 const float v[]) const { | 70 const float v[]) const { |
69 const Uniform& uni = fUniforms[u.toIndex()]; | 71 const Uniform& uni = fUniforms[u.toIndex()]; |
70 SkASSERT(uni.fType == kFloat_GrSLType); | 72 SkASSERT(uni.fType == kFloat_GrSLType); |
71 SkASSERT(arrayCount > 0); | 73 SkASSERT(arrayCount > 0); |
72 SkASSERT(arrayCount <= uni.fArrayCount || | 74 SkASSERT(arrayCount <= uni.fArrayCount || |
73 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; | 75 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; |
| 76 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
74 | 77 |
75 void* buffer = this->getBufferPtrAndMarkDirty(uni); | 78 void* buffer = this->getBufferPtrAndMarkDirty(uni); |
76 SkASSERT(sizeof(float) == 4); | 79 SkASSERT(sizeof(float) == 4); |
77 for (int i = 0; i < arrayCount; ++i) { | 80 for (int i = 0; i < arrayCount; ++i) { |
78 const float* curVec = &v[i]; | 81 const float* curVec = &v[i]; |
79 memcpy(buffer, curVec, sizeof(float)); | 82 memcpy(buffer, curVec, sizeof(float)); |
80 buffer = static_cast<char*>(buffer) + 4*sizeof(float); | 83 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
81 } | 84 } |
82 } | 85 } |
83 | 86 |
84 void GrVkPipelineStateDataManager::set2f(UniformHandle u, float v0, float v1) co
nst { | 87 void GrVkPipelineStateDataManager::set2f(UniformHandle u, float v0, float v1) co
nst { |
85 const Uniform& uni = fUniforms[u.toIndex()]; | 88 const Uniform& uni = fUniforms[u.toIndex()]; |
86 SkASSERT(uni.fType == kVec2f_GrSLType); | 89 SkASSERT(uni.fType == kVec2f_GrSLType); |
87 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 90 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
| 91 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
88 void* buffer = this->getBufferPtrAndMarkDirty(uni); | 92 void* buffer = this->getBufferPtrAndMarkDirty(uni); |
89 SkASSERT(sizeof(float) == 4); | 93 SkASSERT(sizeof(float) == 4); |
90 float v[2] = { v0, v1 }; | 94 float v[2] = { v0, v1 }; |
91 memcpy(buffer, v, 2 * sizeof(float)); | 95 memcpy(buffer, v, 2 * sizeof(float)); |
92 } | 96 } |
93 | 97 |
94 void GrVkPipelineStateDataManager::set2fv(UniformHandle u, | 98 void GrVkPipelineStateDataManager::set2fv(UniformHandle u, |
95 int arrayCount, | 99 int arrayCount, |
96 const float v[]) const { | 100 const float v[]) const { |
97 const Uniform& uni = fUniforms[u.toIndex()]; | 101 const Uniform& uni = fUniforms[u.toIndex()]; |
98 SkASSERT(uni.fType == kVec2f_GrSLType); | 102 SkASSERT(uni.fType == kVec2f_GrSLType); |
99 SkASSERT(arrayCount > 0); | 103 SkASSERT(arrayCount > 0); |
100 SkASSERT(arrayCount <= uni.fArrayCount || | 104 SkASSERT(arrayCount <= uni.fArrayCount || |
101 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; | 105 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; |
| 106 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
102 | 107 |
103 void* buffer = this->getBufferPtrAndMarkDirty(uni); | 108 void* buffer = this->getBufferPtrAndMarkDirty(uni); |
104 SkASSERT(sizeof(float) == 4); | 109 SkASSERT(sizeof(float) == 4); |
105 for (int i = 0; i < arrayCount; ++i) { | 110 for (int i = 0; i < arrayCount; ++i) { |
106 const float* curVec = &v[2 * i]; | 111 const float* curVec = &v[2 * i]; |
107 memcpy(buffer, curVec, 2 * sizeof(float)); | 112 memcpy(buffer, curVec, 2 * sizeof(float)); |
108 buffer = static_cast<char*>(buffer) + 4*sizeof(float); | 113 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
109 } | 114 } |
110 } | 115 } |
111 | 116 |
112 void GrVkPipelineStateDataManager::set3f(UniformHandle u, float v0, float v1, fl
oat v2) const { | 117 void GrVkPipelineStateDataManager::set3f(UniformHandle u, float v0, float v1, fl
oat v2) const { |
113 const Uniform& uni = fUniforms[u.toIndex()]; | 118 const Uniform& uni = fUniforms[u.toIndex()]; |
114 SkASSERT(uni.fType == kVec3f_GrSLType); | 119 SkASSERT(uni.fType == kVec3f_GrSLType); |
115 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 120 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
| 121 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
116 void* buffer = this->getBufferPtrAndMarkDirty(uni); | 122 void* buffer = this->getBufferPtrAndMarkDirty(uni); |
117 SkASSERT(sizeof(float) == 4); | 123 SkASSERT(sizeof(float) == 4); |
118 float v[3] = { v0, v1, v2 }; | 124 float v[3] = { v0, v1, v2 }; |
119 memcpy(buffer, v, 3 * sizeof(float)); | 125 memcpy(buffer, v, 3 * sizeof(float)); |
120 } | 126 } |
121 | 127 |
122 void GrVkPipelineStateDataManager::set3fv(UniformHandle u, | 128 void GrVkPipelineStateDataManager::set3fv(UniformHandle u, |
123 int arrayCount, | 129 int arrayCount, |
124 const float v[]) const { | 130 const float v[]) const { |
125 const Uniform& uni = fUniforms[u.toIndex()]; | 131 const Uniform& uni = fUniforms[u.toIndex()]; |
126 SkASSERT(uni.fType == kVec3f_GrSLType); | 132 SkASSERT(uni.fType == kVec3f_GrSLType); |
127 SkASSERT(arrayCount > 0); | 133 SkASSERT(arrayCount > 0); |
128 SkASSERT(arrayCount <= uni.fArrayCount || | 134 SkASSERT(arrayCount <= uni.fArrayCount || |
129 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; | 135 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; |
| 136 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
130 | 137 |
131 void* buffer = this->getBufferPtrAndMarkDirty(uni); | 138 void* buffer = this->getBufferPtrAndMarkDirty(uni); |
132 SkASSERT(sizeof(float) == 4); | 139 SkASSERT(sizeof(float) == 4); |
133 for (int i = 0; i < arrayCount; ++i) { | 140 for (int i = 0; i < arrayCount; ++i) { |
134 const float* curVec = &v[3 * i]; | 141 const float* curVec = &v[3 * i]; |
135 memcpy(buffer, curVec, 3 * sizeof(float)); | 142 memcpy(buffer, curVec, 3 * sizeof(float)); |
136 buffer = static_cast<char*>(buffer) + 4*sizeof(float); | 143 buffer = static_cast<char*>(buffer) + 4*sizeof(float); |
137 } | 144 } |
138 } | 145 } |
139 | 146 |
140 void GrVkPipelineStateDataManager::set4f(UniformHandle u, | 147 void GrVkPipelineStateDataManager::set4f(UniformHandle u, |
141 float v0, | 148 float v0, |
142 float v1, | 149 float v1, |
143 float v2, | 150 float v2, |
144 float v3) const { | 151 float v3) const { |
145 const Uniform& uni = fUniforms[u.toIndex()]; | 152 const Uniform& uni = fUniforms[u.toIndex()]; |
146 SkASSERT(uni.fType == kVec4f_GrSLType); | 153 SkASSERT(uni.fType == kVec4f_GrSLType); |
147 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); | 154 SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); |
| 155 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
148 void* buffer = this->getBufferPtrAndMarkDirty(uni); | 156 void* buffer = this->getBufferPtrAndMarkDirty(uni); |
149 SkASSERT(sizeof(float) == 4); | 157 SkASSERT(sizeof(float) == 4); |
150 float v[4] = { v0, v1, v2, v3 }; | 158 float v[4] = { v0, v1, v2, v3 }; |
151 memcpy(buffer, v, 4 * sizeof(float)); | 159 memcpy(buffer, v, 4 * sizeof(float)); |
152 } | 160 } |
153 | 161 |
154 void GrVkPipelineStateDataManager::set4fv(UniformHandle u, | 162 void GrVkPipelineStateDataManager::set4fv(UniformHandle u, |
155 int arrayCount, | 163 int arrayCount, |
156 const float v[]) const { | 164 const float v[]) const { |
157 const Uniform& uni = fUniforms[u.toIndex()]; | 165 const Uniform& uni = fUniforms[u.toIndex()]; |
158 SkASSERT(uni.fType == kVec4f_GrSLType); | 166 SkASSERT(uni.fType == kVec4f_GrSLType); |
159 SkASSERT(arrayCount > 0); | 167 SkASSERT(arrayCount > 0); |
160 SkASSERT(arrayCount <= uni.fArrayCount || | 168 SkASSERT(arrayCount <= uni.fArrayCount || |
161 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; | 169 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; |
| 170 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
162 | 171 |
163 void* buffer = this->getBufferPtrAndMarkDirty(uni); | 172 void* buffer = this->getBufferPtrAndMarkDirty(uni); |
164 SkASSERT(sizeof(float) == 4); | 173 SkASSERT(sizeof(float) == 4); |
165 memcpy(buffer, v, arrayCount * 4 * sizeof(float)); | 174 memcpy(buffer, v, arrayCount * 4 * sizeof(float)); |
166 } | 175 } |
167 | 176 |
168 void GrVkPipelineStateDataManager::setMatrix2f(UniformHandle u, const float matr
ix[]) const { | 177 void GrVkPipelineStateDataManager::setMatrix2f(UniformHandle u, const float matr
ix[]) const { |
169 this->setMatrices<2>(u, 1, matrix); | 178 this->setMatrices<2>(u, 1, matrix); |
170 } | 179 } |
171 | 180 |
(...skipping 26 matching lines...) Expand all Loading... |
198 template<int N> struct set_uniform_matrix; | 207 template<int N> struct set_uniform_matrix; |
199 | 208 |
200 template<int N> inline void GrVkPipelineStateDataManager::setMatrices(UniformHan
dle u, | 209 template<int N> inline void GrVkPipelineStateDataManager::setMatrices(UniformHan
dle u, |
201 int arrayC
ount, | 210 int arrayC
ount, |
202 const float
matrices[]) const { | 211 const float
matrices[]) const { |
203 const Uniform& uni = fUniforms[u.toIndex()]; | 212 const Uniform& uni = fUniforms[u.toIndex()]; |
204 SkASSERT(uni.fType == kMat22f_GrSLType + (N - 2)); | 213 SkASSERT(uni.fType == kMat22f_GrSLType + (N - 2)); |
205 SkASSERT(arrayCount > 0); | 214 SkASSERT(arrayCount > 0); |
206 SkASSERT(arrayCount <= uni.fArrayCount || | 215 SkASSERT(arrayCount <= uni.fArrayCount || |
207 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; | 216 (1 == arrayCount && GrGLSLShaderVar::kNonArray == uni.fArrayCount))
; |
| 217 SkASSERT(GrVkUniformHandler::kUniformBufferDescSet == uni.fSetNumber); |
208 | 218 |
209 void* buffer; | 219 void* buffer; |
210 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { | 220 if (GrVkUniformHandler::kVertexBinding == uni.fBinding) { |
211 buffer = fVertexUniformData.get(); | 221 buffer = fVertexUniformData.get(); |
212 fVertexUniformsDirty = true; | 222 fVertexUniformsDirty = true; |
213 } else { | 223 } else { |
214 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); | 224 SkASSERT(GrVkUniformHandler::kFragBinding == uni.fBinding); |
215 buffer = fFragmentUniformData.get(); | 225 buffer = fFragmentUniformData.get(); |
216 fFragmentUniformsDirty = true; | 226 fFragmentUniformsDirty = true; |
217 } | 227 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 VK_ACCESS_HOST_WRITE_BIT, | 275 VK_ACCESS_HOST_WRITE_BIT, |
266 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, | 276 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, |
267 VK_PIPELINE_STAGE_HOST_BIT, | 277 VK_PIPELINE_STAGE_HOST_BIT, |
268 false); | 278 false); |
269 SkAssertResult(fragmentBuffer->updateData(gpu, fFragmentUniformData.get(
), | 279 SkAssertResult(fragmentBuffer->updateData(gpu, fFragmentUniformData.get(
), |
270 fFragmentUniformSize, &updated
Buffer)); | 280 fFragmentUniformSize, &updated
Buffer)); |
271 fFragmentUniformsDirty = false; | 281 fFragmentUniformsDirty = false; |
272 } | 282 } |
273 return updatedBuffer; | 283 return updatedBuffer; |
274 } | 284 } |
OLD | NEW |