angle/util/shader_utils.h

167 строки
4.8 KiB
C
Исходник Обычный вид История

//
// Copyright 2014 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.
//
#ifndef SAMPLE_UTIL_SHADER_UTILS_H
#define SAMPLE_UTIL_SHADER_UTILS_H
#include <functional>
#include <string>
#include <vector>
#include "util/util_export.h"
#include "util/util_gl.h"
ANGLE_UTIL_EXPORT GLuint CheckLinkStatusAndReturnProgram(GLuint program, bool outputErrorMessages);
ANGLE_UTIL_EXPORT GLuint CompileShader(GLenum type, const char *source);
ANGLE_UTIL_EXPORT GLuint CompileShaderFromFile(GLenum type, const std::string &sourcePath);
ANGLE_UTIL_EXPORT GLuint
CompileProgramWithTransformFeedback(const char *vsSource,
const char *fsSource,
const std::vector<std::string> &transformFeedbackVaryings,
GLenum bufferMode);
ANGLE_UTIL_EXPORT GLuint CompileProgram(const char *vsSource, const char *fsSource);
ANGLE_UTIL_EXPORT GLuint CompileProgram(const char *vsSource,
const char *fsSource,
const std::function<void(GLuint)> &preLinkCallback);
ANGLE_UTIL_EXPORT GLuint CompileProgramWithGS(const char *vsSource,
const char *gsSource,
const char *fsSource);
ANGLE_UTIL_EXPORT GLuint CompileProgramFromFiles(const std::string &vsPath,
const std::string &fsPath);
ANGLE_UTIL_EXPORT GLuint CompileComputeProgram(const char *csSource,
bool outputErrorMessages = true);
ANGLE_UTIL_EXPORT bool LinkAttachedProgram(GLuint program);
ANGLE_UTIL_EXPORT GLuint LoadBinaryProgramOES(const std::vector<uint8_t> &binary,
GLenum binaryFormat);
ANGLE_UTIL_EXPORT GLuint LoadBinaryProgramES3(const std::vector<uint8_t> &binary,
GLenum binaryFormat);
namespace angle
{
namespace essl1_shaders
{
ANGLE_UTIL_EXPORT const char *PositionAttrib();
ANGLE_UTIL_EXPORT const char *ColorUniform();
Vulkan: Implement a texture descriptor cache. We noticed a significant hotspot in vkAllocateDesctiptorSets. The app was repeatedly cycling through a few combinations of active textures. For each state change in ANGLE we were allocating a new desctiptor set. This in turn would trigger internal driver memory allocation and cause jank. Using a cache avoids allocations entirely since the application is rotating through a stable set of textures. The descriptor cache is stored in each program. It is indexed by a set of 32-bit serials. Each texture generates a unique serial for every combination of VkImage and VkSampler that the texture owns. The texture descriptor is refreshed every time a texture changes or is rebound. The descriptor cache is accessed via an unoredered map with the texture serial sets as the hash key. We also store the maximum active texture index in the cache key so we don't need to hash and memcmp on all 64 active textures. This will currently fail if more than MAX_UINT serials are generated. But that number is high enough that it shouldn't be possible to hit in practice in a practical amount of time. Requires shifting the texture sync to ContextVk so we can get the new serial after the textures are updated. And to make sure to update the image layouts even if the descriptors are not dirty. Improves performance of the T-Rex demo. Also improves the score of the texture state change microbenchmark by about 40%. Bug: angleproject:3117 Change-Id: Ieb9bec1e8c1a7619814afab767a1980b959a8241 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1642226 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
2019-06-13 21:17:48 +03:00
ANGLE_UTIL_EXPORT const char *Texture2DUniform();
namespace vs
{
// A shader that sets gl_Position to zero.
ANGLE_UTIL_EXPORT const char *Zero();
// A shader that sets gl_Position to attribute a_position.
ANGLE_UTIL_EXPORT const char *Simple();
// A shader that passes through attribute a_position, setting it to gl_Position and varying
// v_position.
ANGLE_UTIL_EXPORT const char *Passthrough();
Vulkan: Implement a texture descriptor cache. We noticed a significant hotspot in vkAllocateDesctiptorSets. The app was repeatedly cycling through a few combinations of active textures. For each state change in ANGLE we were allocating a new desctiptor set. This in turn would trigger internal driver memory allocation and cause jank. Using a cache avoids allocations entirely since the application is rotating through a stable set of textures. The descriptor cache is stored in each program. It is indexed by a set of 32-bit serials. Each texture generates a unique serial for every combination of VkImage and VkSampler that the texture owns. The texture descriptor is refreshed every time a texture changes or is rebound. The descriptor cache is accessed via an unoredered map with the texture serial sets as the hash key. We also store the maximum active texture index in the cache key so we don't need to hash and memcmp on all 64 active textures. This will currently fail if more than MAX_UINT serials are generated. But that number is high enough that it shouldn't be possible to hit in practice in a practical amount of time. Requires shifting the texture sync to ContextVk so we can get the new serial after the textures are updated. And to make sure to update the image layouts even if the descriptors are not dirty. Improves performance of the T-Rex demo. Also improves the score of the texture state change microbenchmark by about 40%. Bug: angleproject:3117 Change-Id: Ieb9bec1e8c1a7619814afab767a1980b959a8241 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1642226 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
2019-06-13 21:17:48 +03:00
// A shader that simply passes through attribute a_position, setting it to gl_Position and varying
// texcoord.
ANGLE_UTIL_EXPORT const char *Texture2D();
} // namespace vs
namespace fs
{
// A shader that renders a simple checker pattern of red and green. X axis and y axis separate the
// different colors. Needs varying v_position.
ANGLE_UTIL_EXPORT const char *Checkered();
// A shader that fills with color taken from uniform named "color".
ANGLE_UTIL_EXPORT const char *UniformColor();
// A shader that fills with 100% opaque red.
ANGLE_UTIL_EXPORT const char *Red();
// A shader that fills with 100% opaque green.
ANGLE_UTIL_EXPORT const char *Green();
// A shader that fills with 100% opaque blue.
ANGLE_UTIL_EXPORT const char *Blue();
// A shader that samples the texture
Vulkan: Implement a texture descriptor cache. We noticed a significant hotspot in vkAllocateDesctiptorSets. The app was repeatedly cycling through a few combinations of active textures. For each state change in ANGLE we were allocating a new desctiptor set. This in turn would trigger internal driver memory allocation and cause jank. Using a cache avoids allocations entirely since the application is rotating through a stable set of textures. The descriptor cache is stored in each program. It is indexed by a set of 32-bit serials. Each texture generates a unique serial for every combination of VkImage and VkSampler that the texture owns. The texture descriptor is refreshed every time a texture changes or is rebound. The descriptor cache is accessed via an unoredered map with the texture serial sets as the hash key. We also store the maximum active texture index in the cache key so we don't need to hash and memcmp on all 64 active textures. This will currently fail if more than MAX_UINT serials are generated. But that number is high enough that it shouldn't be possible to hit in practice in a practical amount of time. Requires shifting the texture sync to ContextVk so we can get the new serial after the textures are updated. And to make sure to update the image layouts even if the descriptors are not dirty. Improves performance of the T-Rex demo. Also improves the score of the texture state change microbenchmark by about 40%. Bug: angleproject:3117 Change-Id: Ieb9bec1e8c1a7619814afab767a1980b959a8241 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1642226 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
2019-06-13 21:17:48 +03:00
ANGLE_UTIL_EXPORT const char *Texture2D();
} // namespace fs
} // namespace essl1_shaders
namespace essl3_shaders
{
ANGLE_UTIL_EXPORT const char *PositionAttrib();
namespace vs
{
// A shader that sets gl_Position to zero.
ANGLE_UTIL_EXPORT const char *Zero();
// A shader that sets gl_Position to attribute a_position.
ANGLE_UTIL_EXPORT const char *Simple();
// A shader that simply passes through attribute a_position, setting it to gl_Position and varying
// v_position.
ANGLE_UTIL_EXPORT const char *Passthrough();
} // namespace vs
namespace fs
{
// A shader that fills with 100% opaque red.
ANGLE_UTIL_EXPORT const char *Red();
// A shader that fills with 100% opaque green.
ANGLE_UTIL_EXPORT const char *Green();
// A shader that fills with 100% opaque blue.
ANGLE_UTIL_EXPORT const char *Blue();
} // namespace fs
} // namespace essl3_shaders
namespace essl31_shaders
{
ANGLE_UTIL_EXPORT const char *PositionAttrib();
namespace vs
{
// A shader that sets gl_Position to zero.
ANGLE_UTIL_EXPORT const char *Zero();
// A shader that sets gl_Position to attribute a_position.
ANGLE_UTIL_EXPORT const char *Simple();
// A shader that simply passes through attribute a_position, setting it to gl_Position and varying
// v_position.
ANGLE_UTIL_EXPORT const char *Passthrough();
} // namespace vs
namespace fs
{
// A shader that fills with 100% opaque red.
ANGLE_UTIL_EXPORT const char *Red();
} // namespace fs
} // namespace essl31_shaders
} // namespace angle
#endif // SAMPLE_UTIL_SHADER_UTILS_H