Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow A8B8G8R8 formats. #861

Merged
merged 23 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cd95e84
Allow A8B8G8R8 formats.
MarkCallow Feb 14, 2024
6cd3496
Support A8B8G8R8_*_PACK32 formats in create.
MarkCallow Feb 17, 2024
5cd8683
Use generated switches for VkFormat to GL format conversions.
MarkCallow Feb 19, 2024
f8ca2bc
Add custom target to run generate_format_switches.rb.
MarkCallow Feb 19, 2024
0ed29f3
Fix name of macos runner.
MarkCallow Feb 19, 2024
b14bd19
Use correct separator between OSes in matrix.
MarkCallow Feb 20, 2024
efa5800
Fix variable setting on cmake command line.
MarkCallow Feb 20, 2024
a00d26e
Fix cmake build command.
MarkCallow Feb 20, 2024
91cddb5
Add new formats to Java and Python declarations.
MarkCallow Feb 20, 2024
6c24c88
Fix incorrect variable name.
MarkCallow Feb 20, 2024
9eaae0c
Test for changes in generated files.
MarkCallow Feb 20, 2024
8880692
Access env. vars via context for portability.
MarkCallow Feb 20, 2024
f1de7f1
Change awk argument handling on shebang line.
MarkCallow Feb 20, 2024
d1eae56
Remove errant paren.
MarkCallow Feb 20, 2024
702e3f9
Use correct comment character for Python.
MarkCallow Feb 20, 2024
ef6e46d
Revert formatting change and remove dead code & unnecessary comments.
MarkCallow Feb 20, 2024
b2d7922
Clean first to ensure the test has to regenerate the files.
MarkCallow Feb 21, 2024
2463d62
Point at new tests for this issue.
MarkCallow Feb 21, 2024
0e704ac
Allow A8B8G8R8 in extract; update test reference.
MarkCallow Feb 21, 2024
5eccb29
Don't attempt glFormat, etc. look up for _BLOCK textures.
MarkCallow Feb 22, 2024
8680550
Update reference to include raw tests.
MarkCallow Feb 22, 2024
1cf6c88
Fix documentation.
MarkCallow Feb 22, 2024
0e9d2ed
Update CTS reference.
MarkCallow Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/check-mkvk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2015-2020 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0
name: KTX-Software Check mkvk CI

# Seems no way to avoid duplicating this on logic in each .yml file.
# See https://github.com/actions/starter-workflows/issues/245.
on:
# Trigger the workflow on a pull request,
pull_request:

push:
# And on pushes to main, which will occur when a PR is merged.
branches:
- main
# Also trigger on push of release tags to any branch. Useful
# for testing release builds before merging to main.
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
paths-ignore:
- .appveyor.yml
- .travis.yml

# Allow manual trigger
workflow_dispatch:

jobs:
check-mkvk:
strategy:
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]

runs-on: ${{ matrix.os }}
env:
BUILD_DIR: "build"
WERROR: ON

steps:
- uses: actions/checkout@v4

- name: Clone KTX-Specification repo
run: |
pushd ..; git clone https://github.com/KhronosGroup/KTX-Specification.git; popd
- name: Configure CMake build
run: cmake -B ${{ env.BUILD_DIR }} -DKTX_GENERATE_VK_FILES=ON -DKTX_FEATURE_TESTS=OFF -DKTX_FEATURE_TOOLS=OFF -DKTX_WERROR=${{ env.WERROR }}
- name: Test file generation
run: |
cmake --build ${{ env.BUILD_DIR }} --target mkvk --clean-first
git diff --quiet HEAD

5 changes: 0 additions & 5 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ jobs:
sse: ON, opencl: ON}
]
include:
- os: windows-latest
generator: 'Visual Studio 17 2022'
toolset: CLangCL
arch: x64
check_mkvk: ONLY
- os: windows-2019
generator: 'Visual Studio 16 2019'
toolset: v142
Expand Down
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ env:
# FEATURE_PY is off for arm64 macOS because we'd need a cross-compiled version
# of Python for it to correctly build the Python extensions (the CI
# runs on x86_64)
- CHECK_MKVK=ONLY

- CONFIGURATION=Debug,Release PLATFORM=macOS ARCHS=x86_64
FEATURE_DOC=ON FEATURE_JNI=ON FEATURE_PY=ON FEATURE_LOADTESTS=OpenGL+Vulkan FEATURE_TOOLS=ON
FEATURE_TOOLS_CTS=ON LOADTESTS_USE_LOCAL_DEPENDENCIES=ON SUPPORT_SSE=ON SUPPORT_OPENCL=OFF DEPLOY_DOCS=YES PACKAGE=YES
Expand Down Expand Up @@ -89,10 +87,6 @@ jobs:
dist: jammy
env:
- CHECK_REUSE: ONLY
- os: linux
dist: jammy
env:
- CHECK_MKVK: ONLY
- os: linux
dist: jammy
addons:
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,11 @@ set(KTX_MAIN_SRC
lib/texture2.c
lib/texture2.h
lib/uthash.h
lib/vk2gl.h
lib/vk_format.h
lib/vkFormat2glFormat.inl
lib/vkFormat2glInternalFormat.inl
lib/vkFormat2glType.inl
lib/vkformat_check.c
lib/vkformat_enum.h
lib/vkformat_str.c
Expand Down
132 changes: 103 additions & 29 deletions lib/mkvkformatfiles → ci_scripts/mkvkformatfiles
Original file line number Diff line number Diff line change
@@ -1,25 +1,74 @@
#! /usr/bin/awk -f
#! /usr/bin/env -S awk -f
# Copyright 2019-2024 Mark Callow
# SPDX-License-Identifier: Apache-2.0

# Usage: mkvkformatfiles [output-dir path/to/vulkan_core]
#
# output_dir defaults to the current directory.
# path/to/vulkan_core defaults to ENVIRON["Vulkan_INCLUDE_DIR"]. If not
# set, default is lib/dfdutils/vulkan/vulkan_core.h.
#
# When specifying path/to/vulkan_core, output-dir must also be
# specified.

# This script creates 5 files from vulkan/vulkan_core.h:
#
# - vkformat_enum.h, the VkFormat enum declaration for those who don't
# want to include vulkan_core.h.
# - vkformat_list.inl, a list of VkFormat enum names for use in
# initializing tables, etc.
# - vkformat_str.c, a switch statement for converting VkFormat enums to
# - lib/vkformat_enum.h: the VkFormat enum declaration for those who don't
# want to include vulkan_core.h. extension token names for
# extensions that have been moved to core are omitted.
#
# - lib/vkformat_str.c: a switch statement for converting VkFormat enums to
# to strings corresponding to the format names.
# - vkformat_typesize.c, function to return the type-size for each
# - lib/vkformat_typesize.c, function to return the type-size for each
# format.
# - vkformat_check.c, 2 functions: 1 to checking if a format is prohibited in
# KTX2 and the other to see if a format is valid.
# KTX2.
#
# - lib/vkformat_check.c: 2 functions: 1 to check if a format is prohibited in
# KTX2 and the other to see if a format is a valid Vulkan format.
#
# - interface/python_binding/pyktx/vk_format.py, VkFormat enumerators for
# Python.
#
# - interface/java_binding/src/main/java/org/khronos/ktx/VkFormat.java,
# VkFormat enumerators for Java.
#
# - tests/unittests/vkformat_list.inl, a list of VkFormat enum names for use in
# initializing tables, etc.
#
# KTX v2 prohibited formats are excluded from the last three files.

BEGIN {
if (index(tolower(ENVIRON["OS"]), "windows") > 0) {
ORS = "\r\n";
}
# ARGV[0] is "awk".
if (ARGC > 1) {
output_dir = ARGV[1] "/";
delete ARGV[1];
} else {
output_dir = "./";
}
# awk reads files whose names are found in the positional parameters,
# hence setting ARGV[1] here and deleting a possible ARGV[1] above.
if (ARGC == 1) {
if (ENVIRON["Vulkan_INCLUDE_DIR"]) {
ARGV[1] = ENVIRON["Vulkan_INCLUDE_DIR"] "/vulkan/vulkan_core.h"; ARGC = 2
} else {
# Use local vulkan_core.h until ASTC 3D texture extension is released.
# ARGV[1] = "/usr/include";
ARGV[1] = "lib/dfdutils/vulkan/vulkan_core.h"; ARGC = 2
}
}

# Hard-coded paths are somewhat unfortunate but major changes in
# the source code organization are unlikely.
format_hdr = output_dir "lib/vkformat_enum.h"
format_typesize = output_dir "lib/vkformat_typesize.c"
format_inl = output_dir "tests/unittests/vkformat_list.inl"
format_strings = output_dir "lib/vkformat_str.c"
format_check = output_dir "lib/vkformat_check.c"
format_java = output_dir "interface/java_binding/src/main/java/org/khronos/ktx/VkFormat.java"
format_python = output_dir "interface/python_binding/pyktx/vk_format.py"

vulkan_core = "vulkan_core.h"
processing_core_formats = 0
processing_extension_formats = 0
Expand All @@ -33,33 +82,21 @@ BEGIN {
extension_formats = ""
end_range = ""
max_std_format_enum = 0
java = "package org.khronos.ktx;" ORS "public class VkFormat {" ORS
prohibited = "#include <stdint.h>" ORS "#include <stdbool.h>" ORS ORS
prohibited = prohibited "#include \"vkformat_enum.h\"" ORS ORS
prohibited = prohibited "bool" ORS "isProhibitedFormat(VkFormat format)" ORS "{" ORS
prohibited = prohibited " switch (format) {" ORS;
python = "from enum import IntEnum" ORS ORS "class VkFormat(IntEnum):" ORS
python = python " \"\"\"Vulkan texture format constants.\"\"\"" ORS ORS
valid = "bool" ORS "isValidFormat(VkFormat format)" ORS "{" ORS
valid = valid " // On MSVC VkFormat can be a signed integer" ORS
valid = valid " if ((uint32_t) format <= VK_FORMAT_MAX_STANDARD_ENUM)" ORS
valid = valid " return true;" ORS " else switch(format) {" ORS
if (ARGC == 2) {
output_dir = ARGV[1] "/";
}
format_hdr = output_dir "vkformat_enum.h"
format_typesize = output_dir "vkformat_typesize.c"
format_inl = output_dir "vkformat_list.inl"
format_strings = output_dir "vkformat_str.c"
format_check = output_dir "vkformat_check.c"
if (ENVIRON["Vulkan_INCLUDE_DIR"]) {
ARGV[1] = ENVIRON["Vulkan_INCLUDE_DIR"] "/vulkan/vulkan_core.h"; ARGC = 2
} else {
# Use local vulkan_core.h until ASTC 3D texture extension is released.
# ARGV[1] = "/usr/include";
ARGV[1] = "lib/dfdutils/vulkan/vulkan_core.h"; ARGC = 2
}
}

# A range pattern to extract the copyright message.
/\*\* Copyright*/,/\*\// { copyright = copyright $0 ORS }
/\*\* Copyright*/,/\*\// { copyright = copyright $0 ORS; }

$2 == "VK_HEADER_VERSION" {
banner = ORS
Expand Down Expand Up @@ -89,8 +126,12 @@ $2 == "VK_HEADER_VERSION" {
if (enum_val+0 > max_std_format_enum) {
max_std_format_enum = enum_val+0;
}
if ($1 !~ /UNDEFINED/) {
format_name_list = format_name_list $1 "," ORS
if ($1 !~ /SCALED/) {
if ($1 !~ /UNDEFINED/) {
format_name_list = format_name_list $1 "," ORS
}
java = java " public static final int " $1 " = " enum_val ";" ORS
python = python " " $1 " = " enum_val ORS
}
}
}
Expand All @@ -99,7 +140,7 @@ $2 == "VK_HEADER_VERSION" {
}
}

/.*SCALED|A8B8G8R8_.*_PACK32/ { prohibited = prohibited " case " $1 ":" ORS; }
/.*SCALED/ { prohibited = prohibited " case " $1 ":" ORS; }
#/A8B8G8R8_.*_PACK32/ { prohibited = prohibited " case " $1 ":" ORS; }
# Multiplane formats.
/VK_FORMAT_[^F]/ && (/PLANE/ || /420/) {
Expand All @@ -113,6 +154,10 @@ $2 == "VK_HEADER_VERSION" {
/VK_FORMAT_[^F].* = 1000/ && ! /PLANE/ && !/420/ {
valid = valid " case " $1 ":" ORS;
format_name_list = format_name_list $1 "," ORS
enum_val = $3;
sub(/,$/, "", enum_val);
java = java " public static final int " $1 " = " enum_val ";" ORS
python = python " " $1 " = " enum_val ORS
}

function removePrefix(string, prefix) {
Expand Down Expand Up @@ -177,9 +222,31 @@ function write_source_file(body, filename) {
print body > filename
}

function write_python_source_file(body, filename) {
pybanner = banner;
sub(/\/\*/, "#***", pybanner);
sub(/\*\//, "****", pybanner);
sub(/ Auto/, "# Auto", pybanner);
regexp = ORS " \\*";
sub(regexp, ORS "#", pybanner);

pycopyright = copyright;
regexp = "/\\*" ORS;
sub(regexp, "", pycopyright);
gsub(/\*\*/, "#", pycopyright);
regexp = "\\*/" ORS;
sub(regexp, "", pycopyright);

print pybanner > filename
print pycopyright > filename
print body > filename
}

END {
# vkformat_enum.h
write_header_file("_VKFORMAT_ENUM_H_", "VULKAN_CORE_H_", format_decl ORS end_range, format_hdr);

# vkformat_list.inl
write_source_file(format_name_list ORS, format_inl)

# vkformat_typesize.c
Expand Down Expand Up @@ -255,6 +322,13 @@ END {
end_str2vk = " return VK_FORMAT_UNDEFINED;" ORS;
end_str2vk = end_str2vk "}"
write_source_file(prelude switch_body_vk2str postscript begin_str2vk switch_body_str2vk end_str2vk, format_strings);

# VkFormat.java
end_java = "}" ORS
write_source_file(java end_java, format_java);

# vk_format.py
write_python_source_file(python, format_python);
}

# vim:ai:ts=4:sts=4:sw=2:expandtab:textwidth=70
Expand Down
Loading
Loading