Hash :
6655e94f
Author :
Date :
2024-09-09T15:41:09
Remove Feature Level 9_3, part 2 Remove all of the remaining feature level 9_3 code. Bug: angleproject:355462523 Change-Id: Ifd15d8f5486d3e7f8f2e134f23872abf4a8ea51c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5847452 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
//
// Copyright 2023 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ProgramExecutableD3D.h: Implementation of ProgramExecutableImpl.
#ifndef LIBANGLE_RENDERER_D3D_PROGRAMEXECUTABLED3D_H_
#define LIBANGLE_RENDERER_D3D_PROGRAMEXECUTABLED3D_H_
#include "compiler/translator/hlsl/blocklayoutHLSL.h"
#include "libANGLE/ProgramExecutable.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/ProgramExecutableImpl.h"
#include "libANGLE/renderer/d3d/DynamicHLSL.h"
namespace rx
{
class RendererD3D;
class UniformStorageD3D;
class ShaderExecutableD3D;
#if !defined(ANGLE_COMPILE_OPTIMIZATION_LEVEL)
// WARNING: D3DCOMPILE_OPTIMIZATION_LEVEL3 may lead to a DX9 shader compiler hang.
// It should only be used selectively to work around specific bugs.
# define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL1
#endif
enum class HLSLRegisterType : uint8_t
{
None = 0,
Texture = 1,
UnorderedAccessView = 2
};
// Helper struct representing a single shader uniform
// TODO(jmadill): Make uniform blocks shared between all programs, so we don't need separate
// register indices.
struct D3DUniform : private angle::NonCopyable
{
D3DUniform(GLenum type,
HLSLRegisterType reg,
const std::string &nameIn,
const std::vector<unsigned int> &arraySizesIn,
bool defaultBlock);
~D3DUniform();
bool isSampler() const;
bool isImage() const;
bool isImage2D() const;
bool isArray() const { return !arraySizes.empty(); }
unsigned int getArraySizeProduct() const;
bool isReferencedByShader(gl::ShaderType shaderType) const;
const uint8_t *firstNonNullData() const;
const uint8_t *getDataPtrToElement(size_t elementIndex) const;
// Duplicated from the GL layer
const gl::UniformTypeInfo &typeInfo;
std::string name; // Names of arrays don't include [0], unlike at the GL layer.
std::vector<unsigned int> arraySizes;
// Pointer to a system copies of the data. Separate pointers for each uniform storage type.
gl::ShaderMap<uint8_t *> mShaderData;
// Register information.
HLSLRegisterType regType;
gl::ShaderMap<unsigned int> mShaderRegisterIndexes;
unsigned int registerCount;
// Register "elements" are used for uniform structs in ES3, to appropriately identify single
// uniforms
// inside aggregate types, which are packed according C-like structure rules.
unsigned int registerElement;
// Special buffer for sampler values.
std::vector<GLint> mSamplerData;
};
struct D3DInterfaceBlock
{
D3DInterfaceBlock();
D3DInterfaceBlock(const D3DInterfaceBlock &other);
bool activeInShader(gl::ShaderType shaderType) const
{
return mShaderRegisterIndexes[shaderType] != GL_INVALID_INDEX;
}
gl::ShaderMap<unsigned int> mShaderRegisterIndexes;
};
struct D3DUniformBlock : D3DInterfaceBlock
{
D3DUniformBlock();
D3DUniformBlock(const D3DUniformBlock &other);
gl::ShaderMap<bool> mUseStructuredBuffers;
gl::ShaderMap<unsigned int> mByteWidths;
gl::ShaderMap<unsigned int> mStructureByteStrides;
};
struct ShaderStorageBlock
{
std::string name;
unsigned int arraySize = 0;
unsigned int registerIndex = 0;
};
struct D3DUBOCache
{
unsigned int registerIndex;
int binding;
};
struct D3DUBOCacheUseSB : D3DUBOCache
{
unsigned int byteWidth;
unsigned int structureByteStride;
};
struct D3DVarying final
{
D3DVarying();
D3DVarying(const std::string &semanticNameIn,
unsigned int semanticIndexIn,
unsigned int componentCountIn,
unsigned int outputSlotIn);
D3DVarying(const D3DVarying &) = default;
D3DVarying &operator=(const D3DVarying &) = default;
std::string semanticName;
unsigned int semanticIndex;
unsigned int componentCount;
unsigned int outputSlot;
};
using D3DUniformMap = std::map<std::string, D3DUniform *>;
class D3DVertexExecutable
{
public:
enum HLSLAttribType
{
FLOAT,
UNSIGNED_INT,
SIGNED_INT,
};
typedef std::vector<HLSLAttribType> Signature;
D3DVertexExecutable(const gl::InputLayout &inputLayout,
const Signature &signature,
ShaderExecutableD3D *shaderExecutable);
~D3DVertexExecutable();
bool matchesSignature(const Signature &signature) const;
static void getSignature(RendererD3D *renderer,
const gl::InputLayout &inputLayout,
Signature *signatureOut);
const gl::InputLayout &inputs() const { return mInputs; }
const Signature &signature() const { return mSignature; }
ShaderExecutableD3D *shaderExecutable() const { return mShaderExecutable; }
private:
static HLSLAttribType GetAttribType(GLenum type);
gl::InputLayout mInputs;
Signature mSignature;
ShaderExecutableD3D *mShaderExecutable;
};
class D3DPixelExecutable
{
public:
D3DPixelExecutable(const std::vector<GLenum> &outputSignature,
const gl::ImageUnitTextureTypeMap &image2DSignature,
ShaderExecutableD3D *shaderExecutable);
~D3DPixelExecutable();
bool matchesSignature(const std::vector<GLenum> &outputSignature,
const gl::ImageUnitTextureTypeMap &image2DSignature) const
{
return mOutputSignature == outputSignature && mImage2DSignature == image2DSignature;
}
const std::vector<GLenum> &outputSignature() const { return mOutputSignature; }
const gl::ImageUnitTextureTypeMap &image2DSignature() const { return mImage2DSignature; }
ShaderExecutableD3D *shaderExecutable() const { return mShaderExecutable; }
private:
const std::vector<GLenum> mOutputSignature;
const gl::ImageUnitTextureTypeMap mImage2DSignature;
ShaderExecutableD3D *mShaderExecutable;
};
class D3DComputeExecutable
{
public:
D3DComputeExecutable(const gl::ImageUnitTextureTypeMap &signature,
std::unique_ptr<ShaderExecutableD3D> shaderExecutable);
~D3DComputeExecutable();
bool matchesSignature(const gl::ImageUnitTextureTypeMap &signature) const
{
return mSignature == signature;
}
const gl::ImageUnitTextureTypeMap &signature() const { return mSignature; }
ShaderExecutableD3D *shaderExecutable() const { return mShaderExecutable.get(); }
private:
gl::ImageUnitTextureTypeMap mSignature;
std::unique_ptr<ShaderExecutableD3D> mShaderExecutable;
};
struct D3DSampler
{
D3DSampler();
bool active;
GLint logicalTextureUnit;
gl::TextureType textureType;
};
struct D3DImage
{
D3DImage();
bool active;
GLint logicalImageUnit;
};
class ProgramExecutableD3D : public ProgramExecutableImpl
{
public:
ProgramExecutableD3D(const gl::ProgramExecutable *executable);
~ProgramExecutableD3D() override;
void destroy(const gl::Context *context) override;
void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override;
void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override;
void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override;
void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override;
void setUniform1iv(GLint location, GLsizei count, const GLint *v) override;
void setUniform2iv(GLint location, GLsizei count, const GLint *v) override;
void setUniform3iv(GLint location, GLsizei count, const GLint *v) override;
void setUniform4iv(GLint location, GLsizei count, const GLint *v) override;
void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override;
void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override;
void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override;
void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override;
void setUniformMatrix2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void setUniformMatrix3fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void setUniformMatrix4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void setUniformMatrix2x3fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void setUniformMatrix3x2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void setUniformMatrix2x4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void setUniformMatrix4x2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void setUniformMatrix3x4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void setUniformMatrix4x3fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value) override;
void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override;
void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override;
void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override;
void updateCachedInputLayoutFromShader(RendererD3D *renderer,
const gl::SharedCompiledShaderState &vertexShader);
void updateCachedOutputLayoutFromShader();
void updateCachedImage2DBindLayoutFromShader(gl::ShaderType shaderType);
void updateCachedInputLayout(RendererD3D *renderer,
UniqueSerial associatedSerial,
const gl::State &state);
void updateCachedOutputLayout(const gl::Context *context, const gl::Framebuffer *framebuffer);
void updateCachedImage2DBindLayout(const gl::Context *context, const gl::ShaderType shaderType);
void updateUniformBufferCache(const gl::Caps &caps);
// Checks if we need to recompile certain shaders.
bool hasVertexExecutableForCachedInputLayout();
bool hasGeometryExecutableForPrimitiveType(RendererD3D *renderer,
const gl::State &state,
gl::PrimitiveMode drawMode);
bool hasPixelExecutableForCachedOutputLayout();
bool hasComputeExecutableForCachedImage2DBindLayout();
bool anyShaderUniformsDirty() const { return mShaderUniformsDirty.any(); }
bool areShaderUniformsDirty(gl::ShaderType shaderType) const
{
return mShaderUniformsDirty[shaderType];
}
void dirtyAllUniforms();
void markUniformsClean();
const std::vector<PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
void assignImage2DRegisters(gl::ShaderType shaderType,
unsigned int startImageIndex,
int startLogicalImageUnit,
bool readonly);
const std::vector<D3DUniform *> &getD3DUniforms() const { return mD3DUniforms; }
UniformStorageD3D *getShaderUniformStorage(gl::ShaderType shaderType) const
{
return mShaderUniformStorages[shaderType].get();
}
const AttribIndexArray &getAttribLocationToD3DSemantics() const
{
return mAttribLocationToD3DSemantic;
}
unsigned int getAtomicCounterBufferRegisterIndex(GLuint binding,
gl::ShaderType shaderType) const;
unsigned int getShaderStorageBufferRegisterIndex(GLuint blockIndex,
gl::ShaderType shaderType) const;
const std::vector<D3DUBOCache> &getShaderUniformBufferCache(gl::ShaderType shaderType) const;
const std::vector<D3DUBOCacheUseSB> &getShaderUniformBufferCacheUseSB(
gl::ShaderType shaderType) const;
GLint getSamplerMapping(gl::ShaderType type,
unsigned int samplerIndex,
const gl::Caps &caps) const;
gl::TextureType getSamplerTextureType(gl::ShaderType type, unsigned int samplerIndex) const;
gl::RangeUI getUsedSamplerRange(gl::ShaderType type) const;
bool isSamplerMappingDirty() const { return mDirtySamplerMapping; }
void updateSamplerMapping();
GLint getImageMapping(gl::ShaderType type,
unsigned int imageIndex,
bool readonly,
const gl::Caps &caps) const;
gl::RangeUI getUsedImageRange(gl::ShaderType type, bool readonly) const;
bool usesPointSize() const { return mUsesPointSize; }
bool usesPointSpriteEmulation(RendererD3D *renderer) const;
bool usesGeometryShader(RendererD3D *renderer,
const gl::ProvokingVertexConvention provokingVertex,
gl::PrimitiveMode drawMode) const;
bool usesGeometryShaderForPointSpriteEmulation(RendererD3D *renderer) const;
angle::Result getVertexExecutableForCachedInputLayout(d3d::Context *context,
RendererD3D *renderer,
ShaderExecutableD3D **outExectuable,
gl::InfoLog *infoLog);
angle::Result getGeometryExecutableForPrimitiveType(
d3d::Context *errContext,
RendererD3D *renderer,
const gl::Caps &caps,
gl::ProvokingVertexConvention provokingVertex,
gl::PrimitiveMode drawMode,
ShaderExecutableD3D **outExecutable,
gl::InfoLog *infoLog);
angle::Result getPixelExecutableForCachedOutputLayout(d3d::Context *context,
RendererD3D *renderer,
ShaderExecutableD3D **outExectuable,
gl::InfoLog *infoLog);
angle::Result getComputeExecutableForImage2DBindLayout(d3d::Context *context,
RendererD3D *renderer,
ShaderExecutableD3D **outExecutable,
gl::InfoLog *infoLog);
bool hasShaderStage(gl::ShaderType shaderType) const
{
return mExecutable->getLinkedShaderStages()[shaderType];
}
bool hasNamedUniform(const std::string &name);
bool usesVertexID() const { return mUsesVertexID; }
angle::Result loadBinaryShaderExecutables(d3d::Context *contextD3D,
RendererD3D *renderer,
gl::BinaryInputStream *stream);
unsigned int getSerial() const { return mSerial; }
private:
friend class ProgramD3D;
bool load(const gl::Context *context, RendererD3D *renderer, gl::BinaryInputStream *stream);
void save(const gl::Context *context, RendererD3D *renderer, gl::BinaryOutputStream *stream);
template <typename DestT>
void getUniformInternal(GLint location, DestT *dataOut) const;
template <typename T>
void setUniformImpl(D3DUniform *targetUniform,
const gl::VariableLocation &locationInfo,
GLsizei count,
const T *v,
uint8_t *targetData,
GLenum uniformType);
template <typename T>
void setUniformInternal(GLint location, GLsizei count, const T *v, GLenum uniformType);
template <int cols, int rows>
void setUniformMatrixfvInternal(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void initAttribLocationsToD3DSemantic(const gl::SharedCompiledShaderState &vertexShader);
void reset();
void initializeUniformBlocks();
void initializeShaderStorageBlocks(const gl::ShaderMap<gl::SharedCompiledShaderState> &shaders);
void initializeUniformStorage(RendererD3D *renderer,
const gl::ShaderBitSet &availableShaderStages);
void updateCachedVertexExecutableIndex();
void updateCachedPixelExecutableIndex();
void updateCachedComputeExecutableIndex();
void defineUniformsAndAssignRegisters(
RendererD3D *renderer,
const gl::ShaderMap<gl::SharedCompiledShaderState> &shaders);
void defineUniformBase(gl::ShaderType shaderType,
const sh::ShaderVariable &uniform,
D3DUniformMap *uniformMap);
void assignAllSamplerRegisters(const gl::ShaderMap<gl::SharedCompiledShaderState> &shaders);
void assignSamplerRegisters(const gl::ShaderMap<gl::SharedCompiledShaderState> &shaders,
size_t uniformIndex);
static void AssignSamplers(unsigned int startSamplerIndex,
const gl::UniformTypeInfo &typeInfo,
unsigned int samplerCount,
std::vector<D3DSampler> &outSamplers,
gl::RangeUI *outUsedRange);
void assignAllImageRegisters();
void assignAllAtomicCounterRegisters();
void assignImageRegisters(size_t uniformIndex);
static void AssignImages(unsigned int startImageIndex,
int startLogicalImageUnit,
unsigned int imageCount,
std::vector<D3DImage> &outImages,
gl::RangeUI *outUsedRange);
void gatherTransformFeedbackVaryings(
RendererD3D *renderer,
const gl::VaryingPacking &varyings,
const std::vector<std::string> &transformFeedbackVaryingNames,
const BuiltinInfo &builtins);
D3DUniform *getD3DUniformFromLocation(const gl::VariableLocation &locationInfo);
const D3DUniform *getD3DUniformFromLocation(const gl::VariableLocation &locationInfo) const;
gl::ShaderMap<SharedCompiledShaderStateD3D> mAttachedShaders;
std::vector<std::unique_ptr<D3DVertexExecutable>> mVertexExecutables;
std::vector<std::unique_ptr<D3DPixelExecutable>> mPixelExecutables;
angle::PackedEnumMap<gl::PrimitiveMode, std::unique_ptr<ShaderExecutableD3D>>
mGeometryExecutables;
std::vector<std::unique_ptr<D3DComputeExecutable>> mComputeExecutables;
gl::ShaderMap<std::string> mShaderHLSL;
gl::ShaderMap<CompilerWorkaroundsD3D> mShaderWorkarounds;
FragDepthUsage mFragDepthUsage;
bool mUsesSampleMask;
bool mHasMultiviewEnabled;
bool mUsesVertexID;
bool mUsesViewID;
std::vector<PixelShaderOutputVariable> mPixelShaderKey;
// Common code for all dynamic geometry shaders. Consists mainly of the GS input and output
// structures, built from the linked varying info. We store the string itself instead of the
// packed varyings for simplicity.
std::string mGeometryShaderPreamble;
bool mUsesPointSize;
bool mUsesFlatInterpolation;
gl::ShaderMap<std::unique_ptr<UniformStorageD3D>> mShaderUniformStorages;
gl::ShaderMap<std::vector<D3DSampler>> mShaderSamplers;
gl::ShaderMap<gl::RangeUI> mUsedShaderSamplerRanges;
bool mDirtySamplerMapping;
gl::ShaderMap<std::vector<D3DImage>> mImages;
gl::ShaderMap<std::vector<D3DImage>> mReadonlyImages;
gl::ShaderMap<gl::RangeUI> mUsedImageRange;
gl::ShaderMap<gl::RangeUI> mUsedReadonlyImageRange;
gl::ShaderMap<gl::RangeUI> mUsedAtomicCounterRange;
// Cache for pixel shader output layout to save reallocations.
std::vector<GLenum> mPixelShaderOutputLayoutCache;
Optional<size_t> mCachedPixelExecutableIndex;
AttribIndexArray mAttribLocationToD3DSemantic;
gl::ShaderMap<std::vector<D3DUBOCache>> mShaderUBOCaches;
gl::ShaderMap<std::vector<D3DUBOCacheUseSB>> mShaderUBOCachesUseSB;
D3DVertexExecutable::Signature mCachedVertexSignature;
gl::InputLayout mCachedInputLayout;
Optional<size_t> mCachedVertexExecutableIndex;
std::vector<D3DVarying> mStreamOutVaryings;
std::vector<D3DUniform *> mD3DUniforms;
std::map<std::string, int> mImageBindingMap;
std::map<std::string, int> mAtomicBindingMap;
std::vector<D3DUniformBlock> mD3DUniformBlocks;
std::vector<D3DInterfaceBlock> mD3DShaderStorageBlocks;
gl::ShaderMap<std::vector<ShaderStorageBlock>> mShaderStorageBlocks;
std::array<unsigned int, gl::IMPLEMENTATION_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS>
mComputeAtomicCounterBufferRegisterIndices;
gl::ShaderMap<std::vector<sh::ShaderVariable>> mImage2DUniforms;
gl::ShaderMap<gl::ImageUnitTextureTypeMap> mImage2DBindLayoutCache;
Optional<size_t> mCachedComputeExecutableIndex;
gl::ShaderBitSet mShaderUniformsDirty;
UniqueSerial mCurrentVertexArrayStateSerial;
unsigned int mSerial;
static unsigned int issueSerial();
static unsigned int mCurrentSerial;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_PROGRAMEXECUTABLED3D_H_