| 1 | /* |
| 2 | * Copyright (C) 2019 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "WHLSLBuiltInSemantic.h" |
| 28 | |
| 29 | #if ENABLE(WEBGPU) |
| 30 | |
| 31 | #include "WHLSLFunctionDefinition.h" |
| 32 | #include "WHLSLInferTypes.h" |
| 33 | #include "WHLSLIntrinsics.h" |
| 34 | #include "WHLSLTypeReference.h" |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | namespace WHLSL { |
| 39 | |
| 40 | namespace AST { |
| 41 | |
| 42 | bool BuiltInSemantic::isAcceptableType(const UnnamedType& unnamedType, const Intrinsics& intrinsics) const |
| 43 | { |
| 44 | switch (m_variable) { |
| 45 | case Variable::SVInstanceID: |
| 46 | return matches(unnamedType, intrinsics.uintType()); |
| 47 | case Variable::SVVertexID: |
| 48 | return matches(unnamedType, intrinsics.uintType()); |
| 49 | case Variable::PSize: |
| 50 | return matches(unnamedType, intrinsics.floatType()); |
| 51 | case Variable::SVPosition: |
| 52 | return matches(unnamedType, intrinsics.float4Type()); |
| 53 | case Variable::SVIsFrontFace: |
| 54 | return matches(unnamedType, intrinsics.boolType()); |
| 55 | case Variable::SVSampleIndex: |
| 56 | return matches(unnamedType, intrinsics.uintType()); |
| 57 | case Variable::SVInnerCoverage: |
| 58 | return matches(unnamedType, intrinsics.uintType()); |
| 59 | case Variable::SVTarget: |
| 60 | return matches(unnamedType, intrinsics.float4Type()); |
| 61 | case Variable::SVDepth: |
| 62 | return matches(unnamedType, intrinsics.floatType()); |
| 63 | case Variable::SVCoverage: |
| 64 | return matches(unnamedType, intrinsics.uintType()); |
| 65 | case Variable::SVDispatchThreadID: |
| 66 | return matches(unnamedType, intrinsics.float3Type()); |
| 67 | case Variable::SVGroupID: |
| 68 | return matches(unnamedType, intrinsics.float3Type()); |
| 69 | case Variable::SVGroupIndex: |
| 70 | return matches(unnamedType, intrinsics.uintType()); |
| 71 | case Variable::SVGroupThreadID: |
| 72 | return matches(unnamedType, intrinsics.float3Type()); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | bool BuiltInSemantic::isAcceptableForShaderItemDirection(ShaderItemDirection direction, const Optional<EntryPointType>& entryPointType) const |
| 77 | { |
| 78 | switch (*entryPointType) { |
| 79 | case EntryPointType::Vertex: |
| 80 | switch (direction) { |
| 81 | case ShaderItemDirection::Input: |
| 82 | switch (m_variable) { |
| 83 | case Variable::SVInstanceID: |
| 84 | case Variable::SVVertexID: |
| 85 | return true; |
| 86 | default: |
| 87 | return false; |
| 88 | } |
| 89 | case ShaderItemDirection::Output: |
| 90 | switch (m_variable) { |
| 91 | case Variable::PSize: |
| 92 | case Variable::SVPosition: |
| 93 | return true; |
| 94 | default: |
| 95 | return false; |
| 96 | } |
| 97 | } |
| 98 | case EntryPointType::Fragment: |
| 99 | switch (direction) { |
| 100 | case ShaderItemDirection::Input: |
| 101 | switch (m_variable) { |
| 102 | case Variable::SVIsFrontFace: |
| 103 | case Variable::SVPosition: |
| 104 | case Variable::SVSampleIndex: |
| 105 | case Variable::SVInnerCoverage: |
| 106 | return true; |
| 107 | default: |
| 108 | return false; |
| 109 | } |
| 110 | case ShaderItemDirection::Output: |
| 111 | switch (m_variable) { |
| 112 | case Variable::SVTarget: |
| 113 | case Variable::SVDepth: |
| 114 | case Variable::SVCoverage: |
| 115 | return true; |
| 116 | default: |
| 117 | return false; |
| 118 | } |
| 119 | } |
| 120 | case EntryPointType::Compute: |
| 121 | switch (direction) { |
| 122 | case ShaderItemDirection::Input: |
| 123 | switch (m_variable) { |
| 124 | case Variable::SVDispatchThreadID: |
| 125 | case Variable::SVGroupID: |
| 126 | case Variable::SVGroupIndex: |
| 127 | case Variable::SVGroupThreadID: |
| 128 | return true; |
| 129 | default: |
| 130 | return false; |
| 131 | } |
| 132 | case ShaderItemDirection::Output: |
| 133 | return false; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | } // namespace AST |
| 139 | |
| 140 | } |
| 141 | |
| 142 | } |
| 143 | |
| 144 | #endif |
| 145 | |