For now, the cache key is all of FETCH_COMPILE_STATE.
Use new/delete for swr_vertex_element_state, since we have to call the
constructors/destructors of the struct elements.
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
//////////////////////////////////////////////////////////////////////////
struct FETCH_COMPILE_STATE
{
- uint32_t numAttribs;
+ uint32_t numAttribs {0};
INPUT_ELEMENT_DESC layout[KNOB_NUM_ATTRIBUTES];
SWR_FORMAT indexType;
uint32_t cutIndex{ 0xffffffff };
}
struct swr_vertex_element_state *velems = ctx->velems;
- if (!velems->fsFunc
- || (velems->fsState.cutIndex != info->restart_index)
- || (velems->fsState.bEnableCutIndex != info->primitive_restart)) {
-
- velems->fsState.cutIndex = info->restart_index;
- velems->fsState.bEnableCutIndex = info->primitive_restart;
-
- /* Create Fetch Shader */
+ velems->fsState.cutIndex = info->restart_index;
+ velems->fsState.bEnableCutIndex = info->primitive_restart;
+
+ swr_jit_fetch_key key;
+ swr_generate_fetch_key(key, velems);
+ auto search = velems->map.find(key);
+ if (search != velems->map.end()) {
+ velems->fsFunc = search->second;
+ } else {
HANDLE hJitMgr = swr_screen(ctx->pipe.screen)->hJitMgr;
velems->fsFunc = JitCompileFetch(hJitMgr, velems->fsState);
debug_printf("fetch shader %p\n", velems->fsFunc);
assert(velems->fsFunc && "Error: FetchShader = NULL");
+
+ velems->map.insert(std::make_pair(key, velems->fsFunc));
}
SwrSetFetchFunc(ctx->swrContext, velems->fsFunc);
return !memcmp(&lhs, &rhs, sizeof(lhs));
}
+bool operator==(const swr_jit_fetch_key &lhs, const swr_jit_fetch_key &rhs)
+{
+ return !memcmp(&lhs, &rhs, sizeof(lhs));
+}
+
static void
swr_generate_sampler_key(const struct lp_tgsi_info &info,
struct swr_context *ctx,
swr_generate_sampler_key(swr_vs->info, ctx, PIPE_SHADER_VERTEX, key);
}
+void
+swr_generate_fetch_key(struct swr_jit_fetch_key &key,
+ struct swr_vertex_element_state *velems)
+{
+ memset(&key, 0, sizeof(key));
+
+ key.fsState = velems->fsState;
+}
+
struct BuilderSWR : public Builder {
BuilderSWR(JitManager *pJitMgr, const char *pName)
: Builder(pJitMgr)
struct swr_context *ctx,
swr_vertex_shader *swr_vs);
+void swr_generate_fetch_key(struct swr_jit_fetch_key &key,
+ struct swr_vertex_element_state *velems);
+
struct swr_jit_sampler_key {
unsigned nr_samplers;
unsigned nr_sampler_views;
unsigned clip_plane_mask; // from rasterizer state & vs_info
};
+struct swr_jit_fetch_key {
+ FETCH_COMPILE_STATE fsState;
+};
+
namespace std
{
template <> struct hash<swr_jit_fs_key> {
return util_hash_crc32(&k, sizeof(k));
}
};
+
+template <> struct hash<swr_jit_fetch_key> {
+ std::size_t operator()(const swr_jit_fetch_key &k) const
+ {
+ return util_hash_crc32(&k, sizeof(k));
+ }
+};
};
bool operator==(const swr_jit_fs_key &lhs, const swr_jit_fs_key &rhs);
bool operator==(const swr_jit_vs_key &lhs, const swr_jit_vs_key &rhs);
+bool operator==(const swr_jit_fetch_key &lhs, const swr_jit_fetch_key &rhs);
{
struct swr_vertex_element_state *velems;
assert(num_elements <= PIPE_MAX_ATTRIBS);
- velems = CALLOC_STRUCT(swr_vertex_element_state);
+ velems = new swr_vertex_element_state;
if (velems) {
velems->fsState.bVertexIDOffsetEnable = true;
velems->fsState.numAttribs = num_elements;
static void
swr_delete_vertex_elements_state(struct pipe_context *pipe, void *velems)
{
+ struct swr_vertex_element_state *swr_velems =
+ (struct swr_vertex_element_state *) velems;
/* XXX Need to destroy fetch shader? */
- FREE(velems);
+ delete swr_velems;
}
/* Vertex element state */
struct swr_vertex_element_state {
FETCH_COMPILE_STATE fsState;
- PFN_FETCH_FUNC fsFunc;
- uint32_t stream_pitch[PIPE_MAX_ATTRIBS];
- uint32_t min_instance_div[PIPE_MAX_ATTRIBS];
- uint32_t instanced_bufs;
+ PFN_FETCH_FUNC fsFunc {NULL};
+ uint32_t stream_pitch[PIPE_MAX_ATTRIBS] {0};
+ uint32_t min_instance_div[PIPE_MAX_ATTRIBS] {0};
+ uint32_t instanced_bufs {0};
+ std::unordered_map<swr_jit_fetch_key, PFN_FETCH_FUNC> map;
};
struct swr_blend_state {