chromium/third_party/vulkan-validation-layers/src/layers/state_tracker/shader_module.cpp

/* Copyright (c) 2021-2024 The Khronos Group Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "state_tracker/shader_module.h"

#include <sstream>
#include <string>
#include <queue>

#include "utils/hash_util.h"
#include "generated/spirv_grammar_helper.h"
#include "spirv/1.2/GLSL.std.450.h"

namespace spirv {

void DecorationBase::Add(uint32_t decoration, uint32_t value) {}

// Some decorations are only avaiable for variables, so can't be in OpMemberDecorate
void DecorationSet::Add(uint32_t decoration, uint32_t value) {}

bool DecorationSet::HasAnyBuiltIn() const {}

bool DecorationSet::HasInMember(FlagBit flag_bit) const {}

bool DecorationSet::AllMemberHave(FlagBit flag_bit) const {}

void ExecutionModeSet::Add(const Instruction& insn) {}

static uint32_t ExecutionModelToShaderStageFlagBits(uint32_t mode) {}

// TODO: The set of interesting opcodes here was determined by eyeballing the SPIRV spec. It might be worth
// converting parts of this to be generated from the machine-readable spec instead.
static void FindPointersAndObjects(const Instruction& insn, vvl::unordered_set<uint32_t>& result) {}

// Built-in can be both on the OpVariable or a inside a OpTypeStruct for Block built-in.
bool EntryPoint::IsBuiltInWritten(spv::BuiltIn built_in, const Module& module_state, const StageInterfaceVariable& variable,
                                  const AccessChainVariableMap& access_chain_map) {}

vvl::unordered_set<uint32_t> EntryPoint::GetAccessibleIds(const Module& module_state, EntryPoint& entrypoint) {}

std::vector<StageInterfaceVariable> EntryPoint::GetStageInterfaceVariables(const Module& module_state, const EntryPoint& entrypoint,
                                                                           const VariableAccessMap& variable_access_map,
                                                                           const DebugNameMap& debug_name_map) {}

std::vector<ResourceInterfaceVariable> EntryPoint::GetResourceInterfaceVariables(const Module& module_state, EntryPoint& entrypoint,
                                                                                 const ImageAccessMap& image_access_map,
                                                                                 const AccessChainVariableMap& access_chain_map,
                                                                                 const VariableAccessMap& variable_access_map,
                                                                                 const DebugNameMap& debug_name_map) {}

static inline bool IsImageOperandsBiasOffset(uint32_t type) {}

ImageAccess::ImageAccess(const Module& module_state, const Instruction& image_insn, const FuncParameterMap& func_parameter_map)
    :{}

EntryPoint::EntryPoint(const Module& module_state, const Instruction& entrypoint_insn, const ImageAccessMap& image_access_map,
                       const AccessChainVariableMap& access_chain_map, const VariableAccessMap& variable_access_map,
                       const DebugNameMap& debug_name_map)
    :{}

std::optional<VkPrimitiveTopology> Module::GetTopology(const EntryPoint& entrypoint) const {}

Module::StaticData::StaticData(const Module& module_state, StatelessData* stateless_data) {}

std::string Module::GetDecorations(uint32_t id) const {}

std::string Module::GetName(uint32_t id) const {}

std::string Module::GetMemberName(uint32_t id, uint32_t member_index) const {}

// Used to pretty-print the OpType* for an error message
void Module::DescribeTypeInner(std::ostringstream& ss, uint32_t type, uint32_t indent) const {}

std::string Module::DescribeType(uint32_t type) const {}

std::string Module::DescribeVariable(uint32_t id) const {}

std::shared_ptr<const EntryPoint> Module::FindEntrypoint(char const* name, VkShaderStageFlagBits stageBits) const {}

// Because the following is legal, need the entry point
//    OpEntryPoint GLCompute %main "name_a"
//    OpEntryPoint GLCompute %main "name_b"
// Assumes shader module contains no spec constants used to set the local size values
bool Module::FindLocalSize(const EntryPoint& entrypoint, uint32_t& local_size_x, uint32_t& local_size_y,
                           uint32_t& local_size_z) const {}

uint32_t Module::CalculateWorkgroupSharedMemory() const {}

// If the instruction at |id| is a OpConstant or copy of a constant, returns the instruction
// Cases such as runtime arrays, will not find a constant and return NULL
const Instruction* Module::GetConstantDef(uint32_t id) const {}

// Returns the constant value described by the instruction at |id|
// Caller ensures there can't be a runtime array or specialization constants
uint32_t Module::GetConstantValueById(uint32_t id) const {}

// Returns the number of Location slots used for a given ID reference to a OpType*
uint32_t Module::GetLocationsConsumedByType(uint32_t type) const {}

// Returns the number of Components slots used for a given ID reference to a OpType*
uint32_t Module::GetComponentsConsumedByType(uint32_t type) const {}

// characterizes a SPIR-V type appearing in an interface to a FF stage, for comparison to a VkFormat's characterization above.
// also used for input attachments, as we statically know their format.
NumericType Module::GetNumericType(uint32_t type) const {}

bool Module::HasRuntimeArray(uint32_t type_id) const {}

std::string InterfaceSlot::Describe() const {}

uint32_t GetFormatType(VkFormat format) {}

char const* string_NumericType(uint32_t type) {}

const char* VariableBase::FindDebugName(const VariableBase& variable, const DebugNameMap& debug_name_map) {}

VariableBase::VariableBase(const Module& module_state, const Instruction& insn, VkShaderStageFlagBits stage,
                           const VariableAccessMap& variable_access_map, const DebugNameMap& debug_name_map)
    :{}

std::string VariableBase::DescribeDescriptor() const {}

bool StageInterfaceVariable::IsPerTaskNV(const StageInterfaceVariable& variable) {}

// Some cases there is an array that is there to be "per-vertex" (or related)
// We want to remove this as it is not part of the Location caluclation or true type of variable
bool StageInterfaceVariable::IsArrayInterface(const StageInterfaceVariable& variable) {}

const Instruction& StageInterfaceVariable::FindBaseType(StageInterfaceVariable& variable, const Module& module_state) {}

bool StageInterfaceVariable::IsBuiltin(const StageInterfaceVariable& variable, const Module& module_state) {}

// This logic is based off assumption that the Location are implicit and not member decorations
// when we have structs-of-structs, only the top struct can have explicit locations given
static uint32_t GetStructInterfaceSlots(const Module& module_state, std::shared_ptr<const TypeStructInfo> type_struct_info,
                                        std::vector<InterfaceSlot>& slots, uint32_t starting_location) {}

std::vector<InterfaceSlot> StageInterfaceVariable::GetInterfaceSlots(StageInterfaceVariable& variable, const Module& module_state) {}

std::vector<uint32_t> StageInterfaceVariable::GetBuiltinBlock(const StageInterfaceVariable& variable, const Module& module_state) {}

uint32_t StageInterfaceVariable::GetBuiltinComponents(const StageInterfaceVariable& variable, const Module& module_state) {}

StageInterfaceVariable::StageInterfaceVariable(const Module& module_state, const Instruction& insn, VkShaderStageFlagBits stage,
                                               const VariableAccessMap& variable_access_map, const DebugNameMap& debug_name_map)
    :{}

const Instruction& ResourceInterfaceVariable::FindBaseType(ResourceInterfaceVariable& variable, const Module& module_state) {}

// Determines if the Resource variable itself is dynamic
bool ResourceInterfaceVariable::IsDynamicAccessed(ResourceInterfaceVariable& variable, const Module& module_state,
                                                  const AccessChainVariableMap& access_chain_map) {}

uint32_t ResourceInterfaceVariable::FindImageSampledTypeWidth(const Module& module_state, const Instruction& base_type) {}

NumericType ResourceInterfaceVariable::FindImageFormatType(const Module& module_state, const Instruction& base_type) {}

bool ResourceInterfaceVariable::IsStorageBuffer(const ResourceInterfaceVariable& variable) {}

ResourceInterfaceVariable::ResourceInterfaceVariable(const Module& module_state, const EntryPoint& entrypoint,
                                                     const Instruction& insn, const ImageAccessMap& image_access_map,
                                                     const AccessChainVariableMap& access_chain_map,
                                                     const VariableAccessMap& variable_access_map,
                                                     const DebugNameMap& debug_name_map)
    :{}

PushConstantVariable::PushConstantVariable(const Module& module_state, const Instruction& insn, VkShaderStageFlagBits stage,
                                           const VariableAccessMap& variable_access_map, const DebugNameMap& debug_name_map)
    :{}

TypeStructInfo::TypeStructInfo(const Module& module_state, const Instruction& struct_insn)
    :{}

TypeStructSize TypeStructInfo::GetSize(const Module& module_state) const {}

uint32_t Module::GetNumComponentsInBaseType(const Instruction* insn) const {}

// Returns the total size in 'bits' of any OpType*
uint32_t Module::GetTypeBitsSize(const Instruction* insn) const {}

// Returns the total size in 'bytes' of any OpType*
uint32_t Module::GetTypeBytesSize(const Instruction* insn) const {}

// Returns the base type (float, int or unsigned int) or struct (can have multiple different base types inside)
// Will return 0 if it can not be determined
uint32_t Module::GetBaseType(const Instruction* insn) const {}

const Instruction* Module::GetBaseTypeInstruction(uint32_t type) const {}

// Returns type_id if id has type or zero otherwise
uint32_t Module::GetTypeId(uint32_t id) const {}

// Return zero if nothing is found
uint32_t Module::GetTexelComponentCount(const Instruction& insn) const {}

// Takes an array like [3][2][4] and returns 24
// If not an array, returns 1
uint32_t Module::GetFlattenArraySize(const Instruction& insn) const {}

AtomicInstructionInfo Module::GetAtomicInfo(const Instruction& insn) const {}

}  // namespace spirv